Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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.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::BooleanHistogram::FactoryGet( | |
| 25 base::StringPrintf("Welcome.Win10.DefaultPromptResult_%s", | |
| 26 histogram_suffix.c_str()), | |
| 27 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 28 ->AddBoolean(default_browser_state == shell_integration::IS_DEFAULT); | |
| 
 
Alexei Svitkine (slow)
2016/11/21 19:17:40
Instead of this, please use the new functions in h
 
Patrick Monette
2016/11/21 21:04:22
TIL. Very useful!
Done.
 
 | |
| 29 } | |
| 30 | |
| 31 void RecordPinnedResult(const std::string& histogram_suffix, | |
| 32 bool succeeded, | |
| 33 bool is_pinned) { | |
| 34 base::BooleanHistogram::FactoryGet( | |
| 35 base::StringPrintf("Welcome.Win10.PinnedPromptResult_%s", | |
| 36 histogram_suffix.c_str()), | |
| 37 base::HistogramBase::kUmaTargetedHistogramFlag) | |
| 38 ->AddBoolean(is_pinned); | |
| 39 } | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 43 WelcomeWin10Handler::WelcomeWin10Handler(bool inline_style_variant) | |
| 44 : 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 | 45 // The check is started as early as possible because waiting for the page to | 
| 18 // be fully loaded is unnecessarily wasting time. | 46 // be fully loaded is unnecessarily wasting time. | 
| 19 StartIsPinnedToTaskbarCheck(); | 47 StartIsPinnedToTaskbarCheck(); | 
| 20 } | 48 } | 
| 21 | 49 | 
| 22 WelcomeWin10Handler::~WelcomeWin10Handler() = default; | 50 WelcomeWin10Handler::~WelcomeWin10Handler() { | 
| 51 std::string histogram_suffix; | |
| 52 histogram_suffix += inline_style_variant_ ? "Inline" : "Sectioned"; | |
| 53 histogram_suffix += pinned_state_result_ ? "Default" : "Combined"; | |
| 54 | |
| 55 // Closing the page. Record whether the instructions were useful. | |
| 56 (new shell_integration::DefaultBrowserWorker( | |
| 
 
Alexei Svitkine (slow)
2016/11/21 19:17:40
Nit: I don't think you need the extra outer parens
 
Patrick Monette
2016/11/21 21:04:22
Looks weird but it's needed.
.\chrome\browser\ui\
 
 | |
| 57 base::Bind(&RecordDefaultBrowserResult, histogram_suffix))) | |
| 58 ->StartCheckIsDefault(); | |
| 59 | |
| 60 // The instructions for pinning Chrome to the taskbar are only displayed if | |
| 61 // |pinned_state_result_| is true. | |
| 62 if (pinned_state_result_) { | |
| 
 
tmartino
2016/11/21 19:40:08
1. Why are we checking against pinned_state_result
 
Patrick Monette
2016/11/21 21:04:22
Good point. I find that base::Optional<bool> is a
 
 | |
| 63 shell_integration::win::GetIsPinnedToTaskbarState( | |
| 64 base::Closure(), base::Bind(&RecordPinnedResult, histogram_suffix)); | |
| 65 } | |
| 66 } | |
| 23 | 67 | 
| 24 void WelcomeWin10Handler::RegisterMessages() { | 68 void WelcomeWin10Handler::RegisterMessages() { | 
| 25 web_ui()->RegisterMessageCallback( | 69 web_ui()->RegisterMessageCallback( | 
| 26 "handleSetDefaultBrowser", | 70 "handleSetDefaultBrowser", | 
| 27 base::Bind(&WelcomeWin10Handler::HandleSetDefaultBrowser, | 71 base::Bind(&WelcomeWin10Handler::HandleSetDefaultBrowser, | 
| 28 base::Unretained(this))); | 72 base::Unretained(this))); | 
| 29 web_ui()->RegisterMessageCallback( | 73 web_ui()->RegisterMessageCallback( | 
| 30 "handleContinue", | 74 "handleContinue", | 
| 31 base::Bind(&WelcomeWin10Handler::HandleContinue, base::Unretained(this))); | 75 base::Bind(&WelcomeWin10Handler::HandleContinue, base::Unretained(this))); | 
| 32 web_ui()->RegisterMessageCallback( | 76 web_ui()->RegisterMessageCallback( | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 54 // Only wait for a small amount of time for the result. If the timer fires, | 98 // 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. | 99 // it will be assumed that Chrome is pinned to the taskbar. | 
| 56 constexpr base::TimeDelta kPinnedToTaskbarTimeout = | 100 constexpr base::TimeDelta kPinnedToTaskbarTimeout = | 
| 57 base::TimeDelta::FromMilliseconds(200); | 101 base::TimeDelta::FromMilliseconds(200); | 
| 58 timer_.Start(FROM_HERE, kPinnedToTaskbarTimeout, | 102 timer_.Start(FROM_HERE, kPinnedToTaskbarTimeout, | 
| 59 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined, | 103 base::Bind(&WelcomeWin10Handler::OnIsPinnedToTaskbarDetermined, | 
| 60 base::Unretained(this), true)); | 104 base::Unretained(this), true)); | 
| 61 } | 105 } | 
| 62 | 106 | 
| 63 void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) { | 107 void WelcomeWin10Handler::HandleSetDefaultBrowser(const base::ListValue* args) { | 
| 108 base::RecordAction( | |
| 109 base::UserMetricsAction("Win10WelcomePage_SetAsDefaultBrowser")); | |
| 64 // The worker owns itself. | 110 // The worker owns itself. | 
| 65 (new shell_integration::DefaultBrowserWorker( | 111 (new shell_integration::DefaultBrowserWorker( | 
| 66 shell_integration::DefaultWebClientWorkerCallback())) | 112 shell_integration::DefaultWebClientWorkerCallback())) | 
| 67 ->StartSetAsDefault(); | 113 ->StartSetAsDefault(); | 
| 68 } | 114 } | 
| 69 | 115 | 
| 70 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) { | 116 void WelcomeWin10Handler::HandleContinue(const base::ListValue* args) { | 
| 71 web_ui()->GetWebContents()->GetController().LoadURL( | 117 web_ui()->GetWebContents()->GetController().LoadURL( | 
| 72 GURL(chrome::kChromeUINewTabURL), content::Referrer(), | 118 GURL(chrome::kChromeUINewTabURL), content::Referrer(), | 
| 73 ui::PageTransition::PAGE_TRANSITION_LINK, std::string()); | 119 ui::PageTransition::PAGE_TRANSITION_LINK, std::string()); | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 // sent back. | 153 // sent back. | 
| 108 if (!pinned_state_callback_id_.empty()) | 154 if (!pinned_state_callback_id_.empty()) | 
| 109 SendPinnedToTaskbarStateResult(); | 155 SendPinnedToTaskbarStateResult(); | 
| 110 } | 156 } | 
| 111 | 157 | 
| 112 void WelcomeWin10Handler::SendPinnedToTaskbarStateResult() { | 158 void WelcomeWin10Handler::SendPinnedToTaskbarStateResult() { | 
| 113 ResolveJavascriptCallback( | 159 ResolveJavascriptCallback( | 
| 114 base::StringValue(pinned_state_callback_id_), | 160 base::StringValue(pinned_state_callback_id_), | 
| 115 base::FundamentalValue(pinned_state_result_.value())); | 161 base::FundamentalValue(pinned_state_result_.value())); | 
| 116 } | 162 } | 
| OLD | NEW |