Skip to content

Commit

Permalink
Adding metrics on the usefulness of the Win10 version of the Welcome …
Browse files Browse the repository at this point in the history
…Page

Records an histogram value that indicates if the instructions helped the
user change their default browser and/or pin Chrome to the taskbar.

BUG=648686

Review-Url: https://codereview.chromium.org/2513953004
Cr-Commit-Position: refs/heads/master@{#434550}
  • Loading branch information
plmonette-zz authored and Commit bot committed Nov 25, 2016
1 parent 6d4442b commit 444ce88
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 11 deletions.
61 changes: 56 additions & 5 deletions chrome/browser/ui/webui/welcome_win10_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "chrome/browser/ui/webui/welcome_win10_handler.h"

#include "base/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/shell_integration_win.h"
Expand All @@ -13,13 +16,58 @@
#include "content/public/browser/web_contents.h"
#include "url/gurl.h"

WelcomeWin10Handler::WelcomeWin10Handler() : weak_ptr_factory_(this) {
namespace {

void RecordDefaultBrowserResult(
const std::string& histogram_suffix,
shell_integration::DefaultWebClientState default_browser_state) {
base::UmaHistogramBoolean(
base::StringPrintf("Welcome.Win10.DefaultPromptResult_%s",
histogram_suffix.c_str()),
default_browser_state == shell_integration::IS_DEFAULT);
}

void RecordPinnedResult(const std::string& histogram_suffix,
bool succeeded,
bool is_pinned) {
if (!succeeded)
return;

base::UmaHistogramBoolean(
base::StringPrintf("Welcome.Win10.PinnedPromptResult_%s",
histogram_suffix.c_str()),
is_pinned);
}

} // namespace

WelcomeWin10Handler::WelcomeWin10Handler(bool inline_style_variant)
: inline_style_variant_(inline_style_variant), weak_ptr_factory_(this) {
// The check is started as early as possible because waiting for the page to
// be fully loaded is unnecessarily wasting time.
StartIsPinnedToTaskbarCheck();
}

WelcomeWin10Handler::~WelcomeWin10Handler() = default;
WelcomeWin10Handler::~WelcomeWin10Handler() {
// The instructions for pinning Chrome to the taskbar were only displayed if
// Chrome wasn't pinned to the taskbar at page construction time.
bool pin_instructions_shown =
pinned_state_result_.has_value() && !pinned_state_result_.value();

std::string histogram_suffix;
histogram_suffix += inline_style_variant_ ? "Inline" : "Sectioned";
histogram_suffix += pin_instructions_shown ? "Combined" : "Default";

// Closing the page. Record whether the instructions were useful.
(new shell_integration::DefaultBrowserWorker(
base::Bind(&RecordDefaultBrowserResult, histogram_suffix)))
->StartCheckIsDefault();

if (pin_instructions_shown) {
shell_integration::win::GetIsPinnedToTaskbarState(
base::Closure(), base::Bind(&RecordPinnedResult, histogram_suffix));
}
}

void WelcomeWin10Handler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
Expand All @@ -46,7 +94,7 @@ void WelcomeWin10Handler::HandleGetPinnedToTaskbarState(
DCHECK(callback_id_found);

// Send back the result if it is already available.
if (pinned_state_result_) {
if (pinned_state_result_.has_value()) {
SendPinnedToTaskbarStateResult();
return;
}
Expand All @@ -63,6 +111,8 @@ void WelcomeWin10Handler::HandleGetPinnedToTaskbarState(
}

void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) {
base::RecordAction(
base::UserMetricsAction("Win10WelcomePage_SetAsDefaultBrowser"));
// The worker owns itself.
(new shell_integration::DefaultBrowserWorker(
shell_integration::DefaultWebClientWorkerCallback()))
Expand Down Expand Up @@ -98,13 +148,14 @@ void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined(
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

// Early exit if the pinned_state was already determined.
if (pinned_state_result_)
if (pinned_state_result_.has_value())
return;

// Stop the timer if it's still running.
timer_.Stop();

pinned_state_result_ = is_pinned_to_taskbar;
// Cache the value.
pinned_state_result_.emplace(is_pinned_to_taskbar);

// If the page already called getPinnedToTaskbarState(), the result can be
// sent back.
Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/ui/webui/welcome_win10_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ListValue;
// Handles actions on the Windows 10 specific Welcome page.
class WelcomeWin10Handler : public content::WebUIMessageHandler {
public:
WelcomeWin10Handler();
explicit WelcomeWin10Handler(bool inline_style_variant);
~WelcomeWin10Handler() override;

// content::WebUIMessageHandler:
Expand Down Expand Up @@ -58,6 +58,9 @@ class WelcomeWin10Handler : public content::WebUIMessageHandler {
// when it is received, or wait for the call to happen.
std::string pinned_state_callback_id_;

// Indicates if the inline style variant is displayed.
bool inline_style_variant_;

base::WeakPtrFactory<WelcomeWin10Handler> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(WelcomeWin10Handler);
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/ui/webui/welcome_win10_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ WelcomeWin10UI::WelcomeWin10UI(content::WebUI* web_ui, const GURL& url)
static const char kCssFilePath[] = "welcome.css";
static const char kJsFilePath[] = "welcome.js";

web_ui->AddMessageHandler(new WelcomeWin10Handler());

content::WebUIDataSource* html_source =
content::WebUIDataSource::Create(url.host());

// Determine which variation to show.
bool is_first_run = !UrlContainsKeyValueInQuery(url, "text", "faster");
bool is_inline_style = ShouldShowInlineStyleVariant(url);

web_ui->AddMessageHandler(new WelcomeWin10Handler(is_inline_style));

content::WebUIDataSource* html_source =
content::WebUIDataSource::Create(url.host());

AddLocalizedStrings(html_source, is_first_run);

if (is_inline_style) {
Expand Down
8 changes: 8 additions & 0 deletions tools/metrics/actions/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15734,6 +15734,14 @@ should be able to be added at any place in this file.
</description>
</action>

<action name="Win10WelcomePage_SetAsDefaultBrowser">
<owner>pmonette@chromium.org</owner>
<description>
The user clicked &quot;Open Windows Settings&quot; in the Win10 version of
the Welcome page.
</description>
</action>

<action name="Win7ASHRestart">
<owner>cpu@chromium.org</owner>
<owner>ananta@chromium.org</owner>
Expand Down
34 changes: 34 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73571,6 +73571,22 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Welcome.Win10.DefaultPromptResult" enum="BooleanDefault">
<owner>tmartino@chromium.org</owner>
<summary>
Records whether or not Chrome was the default browser when the user left the
Win10-specific Welcome page.
</summary>
</histogram>

<histogram name="Welcome.Win10.PinnedPromptResult" enum="BooleanPinned">
<owner>tmartino@chromium.org</owner>
<summary>
Records whether or not Chrome was pinned to the taskbar when the user left
the Win10-specific Welcome page.
</summary>
</histogram>

<histogram name="Win8.PageLoad" enum="Win8PageLoadType">
<owner>zturner@chromium.org</owner>
<summary>
Expand Down Expand Up @@ -76435,6 +76451,11 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="1" label="Persisted"/>
</enum>

<enum name="BooleanPinned" type="int">
<int value="0" label="Not Pinned"/>
<int value="1" label="Pinned"/>
</enum>

<enum name="BooleanPopulated" type="int">
<int value="0" label="Not populated"/>
<int value="1" label="Populated"/>
Expand Down Expand Up @@ -113177,6 +113198,19 @@ value.
<affected-histogram name="NewTabPage.DefaultPageType"/>
</histogram_suffixes>

<histogram_suffixes name="WelcomeWin10Variant">
<owner>tmartino@chromium.org</owner>
<suffix name="InlineCombined" label="Inline layout style, combined promo"/>
<suffix name="InlineDefault"
label="Inline layout style, default browser promo only"/>
<suffix name="SectionedCombined"
label="Sectioned layout style, combined promo"/>
<suffix name="SectionedDefault"
label="Sectioned layout style, default browser promo only"/>
<affected-histogram name="Welcome.Win10.DefaultPromptResult"/>
<affected-histogram name="Welcome.Win10.PinnedPromptResult"/>
</histogram_suffixes>

<histogram_suffixes name="WrenchMenuActionTimings" separator=".">
<suffix name="NewTab"/>
<suffix name="NewWindow"/>
Expand Down

0 comments on commit 444ce88

Please sign in to comment.