Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/ui/webui/welcome_win10_handler.cc

Issue 2513953004: Adding metrics on the usefulness of the Win10 version of the Welcome Page (Closed)
Patch Set: merge Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/welcome_win10_handler.h" 5 #include "chrome/browser/ui/webui/welcome_win10_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram_functions.h"
9 #include "base/metrics/user_metrics.h"
10 #include "base/strings/stringprintf.h"
8 #include "base/values.h" 11 #include "base/values.h"
9 #include "chrome/browser/shell_integration.h" 12 #include "chrome/browser/shell_integration.h"
10 #include "chrome/browser/shell_integration_win.h" 13 #include "chrome/browser/shell_integration_win.h"
11 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
14 #include "url/gurl.h" 17 #include "url/gurl.h"
15 18
16 WelcomeWin10Handler::WelcomeWin10Handler() : weak_ptr_factory_(this) { 19 namespace {
20
21 void RecordDefaultBrowserResult(
22 const std::string& histogram_suffix,
23 shell_integration::DefaultWebClientState default_browser_state) {
24 base::UmaHistogramBoolean(
25 base::StringPrintf("Welcome.Win10.DefaultPromptResult_%s",
26 histogram_suffix.c_str()),
27 default_browser_state == shell_integration::IS_DEFAULT);
28 }
29
30 void RecordPinnedResult(const std::string& histogram_suffix,
31 bool succeeded,
32 bool is_pinned) {
33 if (!succeeded)
34 return;
35
36 base::UmaHistogramBoolean(
37 base::StringPrintf("Welcome.Win10.PinnedPromptResult_%s",
38 histogram_suffix.c_str()),
39 is_pinned);
40 }
41
42 } // namespace
43
44 WelcomeWin10Handler::WelcomeWin10Handler(bool inline_style_variant)
45 : inline_style_variant_(inline_style_variant), weak_ptr_factory_(this) {
17 // The check is started as early as possible because waiting for the page to 46 // The check is started as early as possible because waiting for the page to
18 // be fully loaded is unnecessarily wasting time. 47 // be fully loaded is unnecessarily wasting time.
19 StartIsPinnedToTaskbarCheck(); 48 StartIsPinnedToTaskbarCheck();
20 } 49 }
21 50
22 WelcomeWin10Handler::~WelcomeWin10Handler() = default; 51 WelcomeWin10Handler::~WelcomeWin10Handler() {
52 // The instructions for pinning Chrome to the taskbar were only displayed if
53 // Chrome wasn't pinned to the taskbar at page construction time.
54 bool pin_instructions_shown =
55 pinned_state_result_.has_value() && !pinned_state_result_.value();
56
57 std::string histogram_suffix;
58 histogram_suffix += inline_style_variant_ ? "Inline" : "Sectioned";
59 histogram_suffix += pin_instructions_shown ? "Combined" : "Default";
60
61 // Closing the page. Record whether the instructions were useful.
62 (new shell_integration::DefaultBrowserWorker(
63 base::Bind(&RecordDefaultBrowserResult, histogram_suffix)))
64 ->StartCheckIsDefault();
65
66 if (pin_instructions_shown) {
67 shell_integration::win::GetIsPinnedToTaskbarState(
68 base::Closure(), base::Bind(&RecordPinnedResult, histogram_suffix));
69 }
70 }
23 71
24 void WelcomeWin10Handler::RegisterMessages() { 72 void WelcomeWin10Handler::RegisterMessages() {
25 web_ui()->RegisterMessageCallback( 73 web_ui()->RegisterMessageCallback(
26 "handleSetDefaultBrowser", 74 "handleSetDefaultBrowser",
27 base::Bind(&WelcomeWin10Handler::HandleSetDefaultBrowser, 75 base::Bind(&WelcomeWin10Handler::HandleSetDefaultBrowser,
28 base::Unretained(this))); 76 base::Unretained(this)));
29 web_ui()->RegisterMessageCallback( 77 web_ui()->RegisterMessageCallback(
30 "handleContinue", 78 "handleContinue",
31 base::Bind(&WelcomeWin10Handler::HandleContinue, base::Unretained(this))); 79 base::Bind(&WelcomeWin10Handler::HandleContinue, base::Unretained(this)));
32 web_ui()->RegisterMessageCallback( 80 web_ui()->RegisterMessageCallback(
33 "getPinnedToTaskbarState", 81 "getPinnedToTaskbarState",
34 base::Bind(&WelcomeWin10Handler::HandleGetPinnedToTaskbarState, 82 base::Bind(&WelcomeWin10Handler::HandleGetPinnedToTaskbarState,
35 base::Unretained(this))); 83 base::Unretained(this)));
36 } 84 }
37 85
38 void WelcomeWin10Handler::HandleGetPinnedToTaskbarState( 86 void WelcomeWin10Handler::HandleGetPinnedToTaskbarState(
39 const base::ListValue* args) { 87 const base::ListValue* args) {
40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
41 AllowJavascript(); 89 AllowJavascript();
42 90
43 // Save the callback id so that the result can be sent back when it is 91 // Save the callback id so that the result can be sent back when it is
44 // available. 92 // available.
45 bool callback_id_found = args->GetString(0, &pinned_state_callback_id_); 93 bool callback_id_found = args->GetString(0, &pinned_state_callback_id_);
46 DCHECK(callback_id_found); 94 DCHECK(callback_id_found);
47 95
48 // Send back the result if it is already available. 96 // Send back the result if it is already available.
49 if (pinned_state_result_) { 97 if (pinned_state_result_.has_value()) {
50 SendPinnedToTaskbarStateResult(); 98 SendPinnedToTaskbarStateResult();
51 return; 99 return;
52 } 100 }
53 101
54 // Only wait for a small amount of time for the result. If the timer fires, 102 // Only wait for a small amount of time for the result. If the timer fires,
55 // it will be assumed that Chrome is pinned to the taskbar. This is to make 103 // it will be assumed that Chrome is pinned to the taskbar. This is to make
56 // sure the instructions are never displayed in case it was impossible to 104 // sure the instructions are never displayed in case it was impossible to
57 // determine the pinned state. 105 // determine the pinned state.
58 constexpr base::TimeDelta kPinnedToTaskbarTimeout = 106 constexpr base::TimeDelta kPinnedToTaskbarTimeout =
59 base::TimeDelta::FromMilliseconds(200); 107 base::TimeDelta::FromMilliseconds(200);
60 timer_.Start(FROM_HERE, kPinnedToTaskbarTimeout, 108 timer_.Start(FROM_HERE, kPinnedToTaskbarTimeout,
61 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined, 109 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined,
62 base::Unretained(this), true)); 110 base::Unretained(this), true));
63 } 111 }
64 112
65 void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) { 113 void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) {
114 base::RecordAction(
115 base::UserMetricsAction("Win10WelcomePage_SetAsDefaultBrowser"));
66 // The worker owns itself. 116 // The worker owns itself.
67 (new shell_integration::DefaultBrowserWorker( 117 (new shell_integration::DefaultBrowserWorker(
68 shell_integration::DefaultWebClientWorkerCallback())) 118 shell_integration::DefaultWebClientWorkerCallback()))
69 ->StartSetAsDefault(); 119 ->StartSetAsDefault();
70 } 120 }
71 121
72 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) { 122 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) {
73 web_ui()->GetWebContents()->GetController().LoadURL( 123 web_ui()->GetWebContents()->GetController().LoadURL(
74 GURL(chrome::kChromeUINewTabURL), content::Referrer(), 124 GURL(chrome::kChromeUINewTabURL), content::Referrer(),
75 ui::PageTransition::PAGE_TRANSITION_LINK, std::string()); 125 ui::PageTransition::PAGE_TRANSITION_LINK, std::string());
(...skipping 15 matching lines...) Expand all
91 bool is_pinned_to_taskbar) { 141 bool is_pinned_to_taskbar) {
92 // Assume that Chrome is pinned to the taskbar if an error occured. 142 // Assume that Chrome is pinned to the taskbar if an error occured.
93 OnIsPinnedToTaskbarDetermined(!succeeded || is_pinned_to_taskbar); 143 OnIsPinnedToTaskbarDetermined(!succeeded || is_pinned_to_taskbar);
94 } 144 }
95 145
96 void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined( 146 void WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined(
97 bool is_pinned_to_taskbar) { 147 bool is_pinned_to_taskbar) {
98 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
99 149
100 // Early exit if the pinned_state was already determined. 150 // Early exit if the pinned_state was already determined.
101 if (pinned_state_result_) 151 if (pinned_state_result_.has_value())
102 return; 152 return;
103 153
104 // Stop the timer if it's still running. 154 // Stop the timer if it's still running.
105 timer_.Stop(); 155 timer_.Stop();
106 156
107 pinned_state_result_ = is_pinned_to_taskbar; 157 // Cache the value.
158 pinned_state_result_.emplace(is_pinned_to_taskbar);
108 159
109 // If the page already called getPinnedToTaskbarState(), the result can be 160 // If the page already called getPinnedToTaskbarState(), the result can be
110 // sent back. 161 // sent back.
111 if (!pinned_state_callback_id_.empty()) 162 if (!pinned_state_callback_id_.empty())
112 SendPinnedToTaskbarStateResult(); 163 SendPinnedToTaskbarStateResult();
113 } 164 }
114 165
115 void WelcomeWin10Handler::SendPinnedToTaskbarStateResult() { 166 void WelcomeWin10Handler::SendPinnedToTaskbarStateResult() {
116 ResolveJavascriptCallback( 167 ResolveJavascriptCallback(
117 base::StringValue(pinned_state_callback_id_), 168 base::StringValue(pinned_state_callback_id_),
118 base::FundamentalValue(pinned_state_result_.value())); 169 base::FundamentalValue(pinned_state_result_.value()));
119 } 170 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/welcome_win10_handler.h ('k') | chrome/browser/ui/webui/welcome_win10_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698