OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/set_as_default_browser_ui.h" | 5 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/metrics/histogram.h" | |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "chrome/browser/first_run/first_run.h" | 11 #include "chrome/browser/first_run/first_run.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/shell_integration.h" | 14 #include "chrome/browser/shell_integration.h" |
14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | 16 #include "chrome/browser/ui/browser_dialogs.h" |
16 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
17 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
36 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
37 #include "ui/gfx/font.h" | 38 #include "ui/gfx/font.h" |
38 #include "ui/web_dialogs/web_dialog_delegate.h" | 39 #include "ui/web_dialogs/web_dialog_delegate.h" |
39 | 40 |
40 using content::BrowserThread; | 41 using content::BrowserThread; |
41 using content::WebContents; | 42 using content::WebContents; |
42 using content::WebUIMessageHandler; | 43 using content::WebUIMessageHandler; |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
47 const char kSetAsDefaultBrowserHistogram[] = "DefaultBrowser.InteractionResult"; | |
48 | |
49 // The enum permits registering in UMA the three possible outcomes. | |
50 // ACCEPTED: user pressed Next and made Chrome default. | |
51 // DECLINED: user simply closed the dialog without making Chrome default. | |
52 // REGRETED: user pressed Next but then elected a different default browser. | |
arv (Not doing code reviews)
2012/08/16 19:46:20
typo: regre_tt_ed
motek.
2012/08/16 21:44:08
Done.
| |
53 enum MakeChromeDefaultResult { | |
54 MAKE_CHROME_DEFAULT_ACCEPTED, | |
55 MAKE_CHROME_DEFAULT_DECLINED, | |
56 MAKE_CHROME_DEFAULT_REGRETED, | |
57 MAKE_CHROME_DEFAULT_MAX | |
58 }; | |
59 | |
46 ChromeWebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() { | 60 ChromeWebUIDataSource* CreateSetAsDefaultBrowserUIHTMLSource() { |
47 ChromeWebUIDataSource* data_source = new ChromeWebUIDataSource( | 61 ChromeWebUIDataSource* data_source = new ChromeWebUIDataSource( |
48 chrome::kChromeUIMetroFlowHost); | 62 chrome::kChromeUIMetroFlowHost); |
49 data_source->AddLocalizedString("page-title", IDS_METRO_FLOW_TAB_TITLE); | 63 data_source->AddLocalizedString("page-title", IDS_METRO_FLOW_TAB_TITLE); |
50 data_source->AddLocalizedString("flowTitle", IDS_METRO_FLOW_TITLE_SHORT); | 64 data_source->AddLocalizedString("flowTitle", IDS_METRO_FLOW_TITLE_SHORT); |
51 data_source->AddLocalizedString("flowDescription", | 65 data_source->AddLocalizedString("flowDescription", |
52 IDS_METRO_FLOW_DESCRIPTION); | 66 IDS_METRO_FLOW_DESCRIPTION); |
53 data_source->AddLocalizedString("flowNext", | 67 data_source->AddLocalizedString("flowNext", |
54 IDS_METRO_FLOW_SET_DEFAULT); | 68 IDS_METRO_FLOW_SET_DEFAULT); |
55 data_source->AddLocalizedString("chromeLogoString", | 69 data_source->AddLocalizedString("chromeLogoString", |
56 IDS_METRO_FLOW_LOGO_STRING_ALT); | 70 IDS_METRO_FLOW_LOGO_STRING_ALT); |
57 data_source->set_json_path("strings.js"); | 71 data_source->set_json_path("strings.js"); |
58 data_source->add_resource_path("set_as_default_browser.js", | 72 data_source->add_resource_path("set_as_default_browser.js", |
59 IDR_SET_AS_DEFAULT_BROWSER_JS); | 73 IDR_SET_AS_DEFAULT_BROWSER_JS); |
60 data_source->set_default_resource(IDR_SET_AS_DEFAULT_BROWSER_HTML); | 74 data_source->set_default_resource(IDR_SET_AS_DEFAULT_BROWSER_HTML); |
61 return data_source; | 75 return data_source; |
62 } | 76 } |
63 | 77 |
64 // A simple class serving as a delegate for passing down the result of the | 78 // A simple class serving as a delegate for passing down the result of the |
65 // interaction. | 79 // interaction. |
66 class ResponseDelegate { | 80 class ResponseDelegate { |
67 public: | 81 public: |
68 virtual void SetChromeShutdownRequired(bool shutdown_chrome) = 0; | 82 virtual void SetChromeShutdownRequired(bool shutdown_chrome) = 0; |
83 virtual void SetDialogInteractionResult(MakeChromeDefaultResult result) = 0; | |
69 | 84 |
70 protected: | 85 protected: |
71 virtual ~ResponseDelegate() { } | 86 virtual ~ResponseDelegate() { } |
72 }; | 87 }; |
73 | 88 |
74 // Event handler for SetAsDefaultBrowserUI. Capable of setting Chrome as the | 89 // Event handler for SetAsDefaultBrowserUI. Capable of setting Chrome as the |
75 // default browser on button click, closing itself and triggering Chrome | 90 // default browser on button click, closing itself and triggering Chrome |
76 // restart. | 91 // restart. |
77 class SetAsDefaultBrowserHandler | 92 class SetAsDefaultBrowserHandler |
78 : public WebUIMessageHandler, | 93 : public WebUIMessageHandler, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 ShellIntegration::DefaultWebClientUIState state) { | 149 ShellIntegration::DefaultWebClientUIState state) { |
135 // The callback is expected to be invoked once the procedure has completed. | 150 // The callback is expected to be invoked once the procedure has completed. |
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
137 if (!set_default_returned_) | 152 if (!set_default_returned_) |
138 return; | 153 return; |
139 | 154 |
140 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { | 155 if (state == ShellIntegration::STATE_NOT_DEFAULT && set_default_result_) { |
141 // The operation concluded, but Chrome is still not the default. | 156 // The operation concluded, but Chrome is still not the default. |
142 // If the call has succeeded, this suggests user has decided not to make | 157 // If the call has succeeded, this suggests user has decided not to make |
143 // chrome the default. We fold this UI and move on. | 158 // chrome the default. We fold this UI and move on. |
159 if (response_delegate_) { | |
160 response_delegate_->SetDialogInteractionResult( | |
161 MAKE_CHROME_DEFAULT_REGRETED); | |
162 } | |
163 | |
144 ConcludeInteraction(false); | 164 ConcludeInteraction(false); |
145 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { | 165 } else if (state == ShellIntegration::STATE_IS_DEFAULT) { |
166 if (response_delegate_) { | |
167 response_delegate_->SetDialogInteractionResult( | |
168 MAKE_CHROME_DEFAULT_ACCEPTED); | |
169 } | |
170 | |
146 if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( | 171 if (!Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean( |
147 prefs::kSuppressSwitchToMetroModeOnSetDefault)) { | 172 prefs::kSuppressSwitchToMetroModeOnSetDefault)) { |
148 BrowserThread::PostTask( | 173 BrowserThread::PostTask( |
149 BrowserThread::FILE, FROM_HERE, | 174 BrowserThread::FILE, FROM_HERE, |
150 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome, | 175 base::Bind(&SetAsDefaultBrowserHandler::ActivateMetroChrome, |
151 base::Unretained(this))); | 176 base::Unretained(this))); |
152 } else { | 177 } else { |
153 ConcludeInteraction(false); | 178 ConcludeInteraction(false); |
154 } | 179 } |
155 } | 180 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 virtual std::string GetDialogArgs() const OVERRIDE; | 252 virtual std::string GetDialogArgs() const OVERRIDE; |
228 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; | 253 virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE; |
229 virtual void OnCloseContents(WebContents* source, | 254 virtual void OnCloseContents(WebContents* source, |
230 bool* out_close_dialog) OVERRIDE; | 255 bool* out_close_dialog) OVERRIDE; |
231 virtual bool ShouldShowDialogTitle() const OVERRIDE; | 256 virtual bool ShouldShowDialogTitle() const OVERRIDE; |
232 virtual bool HandleContextMenu( | 257 virtual bool HandleContextMenu( |
233 const content::ContextMenuParams& params) OVERRIDE; | 258 const content::ContextMenuParams& params) OVERRIDE; |
234 | 259 |
235 // Overridden from ResponseDelegate: | 260 // Overridden from ResponseDelegate: |
236 virtual void SetChromeShutdownRequired(bool shutdown_chrome); | 261 virtual void SetChromeShutdownRequired(bool shutdown_chrome); |
262 virtual void SetDialogInteractionResult(MakeChromeDefaultResult result); | |
237 | 263 |
238 private: | 264 private: |
239 Profile* profile_; | 265 Profile* profile_; |
240 Browser* browser_; | 266 Browser* browser_; |
241 mutable bool owns_handler_; | 267 mutable bool owns_handler_; |
242 SetAsDefaultBrowserHandler* handler_; | 268 SetAsDefaultBrowserHandler* handler_; |
269 MakeChromeDefaultResult dialog_interation_result_; | |
243 bool response_is_close_chrome_; | 270 bool response_is_close_chrome_; |
244 | 271 |
245 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); | 272 DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserDialogImpl); |
246 }; | 273 }; |
247 | 274 |
248 SetAsDefaultBrowserDialogImpl::SetAsDefaultBrowserDialogImpl(Profile* profile, | 275 SetAsDefaultBrowserDialogImpl::SetAsDefaultBrowserDialogImpl(Profile* profile, |
249 Browser* browser) | 276 Browser* browser) |
250 : profile_(profile), | 277 : profile_(profile), |
251 browser_(browser), | 278 browser_(browser), |
252 owns_handler_(true), | 279 owns_handler_(true), |
253 handler_(new SetAsDefaultBrowserHandler(this)), | 280 handler_(new SetAsDefaultBrowserHandler(this)), |
281 dialog_interation_result_(MAKE_CHROME_DEFAULT_DECLINED), | |
254 response_is_close_chrome_(false) { | 282 response_is_close_chrome_(false) { |
255 } | 283 } |
256 | 284 |
257 SetAsDefaultBrowserDialogImpl::~SetAsDefaultBrowserDialogImpl() { | 285 SetAsDefaultBrowserDialogImpl::~SetAsDefaultBrowserDialogImpl() { |
258 if (owns_handler_) | 286 if (owns_handler_) |
259 delete handler_; | 287 delete handler_; |
260 } | 288 } |
261 | 289 |
262 void SetAsDefaultBrowserDialogImpl::ShowDialog() { | 290 void SetAsDefaultBrowserDialogImpl::ShowDialog() { |
263 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(), | 291 chrome::ShowWebDialog(browser_->window()->GetNativeWindow(), |
(...skipping 29 matching lines...) Expand all Loading... | |
293 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES, | 321 IDS_METRO_FLOW_WIDTH_CHARS, IDS_METRO_FLOW_HEIGHT_LINES, |
294 approximate_web_font); | 322 approximate_web_font); |
295 } | 323 } |
296 | 324 |
297 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const { | 325 std::string SetAsDefaultBrowserDialogImpl::GetDialogArgs() const { |
298 return "[]"; | 326 return "[]"; |
299 } | 327 } |
300 | 328 |
301 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( | 329 void SetAsDefaultBrowserDialogImpl::OnDialogClosed( |
302 const std::string& json_retval) { | 330 const std::string& json_retval) { |
331 // Register the user's response in UMA. | |
332 UMA_HISTOGRAM_ENUMERATION(kSetAsDefaultBrowserHistogram, | |
333 dialog_interation_result_, | |
334 MAKE_CHROME_DEFAULT_MAX); | |
335 | |
303 if (response_is_close_chrome_) { | 336 if (response_is_close_chrome_) { |
304 // If Metro Chrome has been activated, we should close this process. | 337 // If Metro Chrome has been activated, we should close this process. |
305 // We are restarting as metro now. | 338 // We are restarting as metro now. |
306 BrowserList::CloseAllBrowsersWithProfile(profile_); | 339 BrowserList::CloseAllBrowsersWithProfile(profile_); |
307 } else { | 340 } else { |
308 // This will be false if the user closed the dialog without doing anything | 341 // This will be false if the user closed the dialog without doing anything |
309 // or if operation failed for any reason (including invocation under a | 342 // or if operation failed for any reason (including invocation under a |
310 // Windows version earlier than 8). | 343 // Windows version earlier than 8). |
311 // In such case we just carry on with a normal chrome session. However, for | 344 // In such case we just carry on with a normal chrome session. However, for |
312 // the purpose of surfacing this dialog the actual browser window had to | 345 // the purpose of surfacing this dialog the actual browser window had to |
(...skipping 20 matching lines...) Expand all Loading... | |
333 bool SetAsDefaultBrowserDialogImpl::HandleContextMenu( | 366 bool SetAsDefaultBrowserDialogImpl::HandleContextMenu( |
334 const content::ContextMenuParams& params) { | 367 const content::ContextMenuParams& params) { |
335 return true; | 368 return true; |
336 } | 369 } |
337 | 370 |
338 void SetAsDefaultBrowserDialogImpl::SetChromeShutdownRequired( | 371 void SetAsDefaultBrowserDialogImpl::SetChromeShutdownRequired( |
339 bool shutdown_chrome) { | 372 bool shutdown_chrome) { |
340 response_is_close_chrome_ = shutdown_chrome; | 373 response_is_close_chrome_ = shutdown_chrome; |
341 } | 374 } |
342 | 375 |
376 void SetAsDefaultBrowserDialogImpl::SetDialogInteractionResult( | |
377 MakeChromeDefaultResult result) { | |
378 dialog_interation_result_ = result; | |
379 } | |
380 | |
343 } // namespace | 381 } // namespace |
344 | 382 |
345 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) | 383 SetAsDefaultBrowserUI::SetAsDefaultBrowserUI(content::WebUI* web_ui) |
346 : ui::WebDialogUI(web_ui) { | 384 : ui::WebDialogUI(web_ui) { |
347 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui), | 385 ChromeURLDataManager::AddDataSource(Profile::FromWebUI(web_ui), |
348 CreateSetAsDefaultBrowserUIHTMLSource()); | 386 CreateSetAsDefaultBrowserUIHTMLSource()); |
349 } | 387 } |
350 | 388 |
351 // static | 389 // static |
352 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { | 390 void SetAsDefaultBrowserUI::Show(Profile* profile, Browser* browser) { |
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
354 SetAsDefaultBrowserDialogImpl* dialog = | 392 SetAsDefaultBrowserDialogImpl* dialog = |
355 new SetAsDefaultBrowserDialogImpl(profile, browser); | 393 new SetAsDefaultBrowserDialogImpl(profile, browser); |
356 dialog->ShowDialog(); | 394 dialog->ShowDialog(); |
357 } | 395 } |
OLD | NEW |