Chromium Code Reviews| 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/startup/default_browser_prompt.h" | 5 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/win/windows_version.h" | 8 #include "base/win/windows_version.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/shell_integration.h" | 11 #include "chrome/browser/shell_integration.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | |
| 13 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h" | 13 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h" |
| 14 #include "components/prefs/pref_service.h" | |
| 15 #include "components/startup_metric_utils/browser/startup_metric_utils.h" | 14 #include "components/startup_metric_utils/browser/startup_metric_utils.h" |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" | |
| 19 | |
| 20 using content::BrowserThread; | |
| 21 | 16 |
| 22 namespace { | 17 namespace { |
| 23 | 18 |
| 24 // Show the page prompting the user to make Chrome the default browser on | 19 // Show the page prompting the user to make Chrome the default browser on |
| 25 // Windows 8 (which means becoming "the browser" in Metro mode). The page | 20 // Windows 8 (which means becoming "the browser" in Metro mode). The page |
| 26 // will be shown at the first appropriate opportunity. It can be placed in | 21 // will be shown at the first appropriate opportunity. It can be placed in |
| 27 // a tab or in a dialog, depending on other settings. | 22 // a tab or in a dialog, depending on other settings. |
| 28 class SetMetroBrowserFlowLauncher : public content::NotificationObserver { | 23 class SetMetroBrowserFlowLauncher : public content::NotificationObserver { |
| 29 public: | 24 public: |
| 30 static void LaunchSoon(Profile* profile) { | 25 static void LaunchSoon(Profile* profile) { |
| 31 // The instance will manage its own lifetime. | 26 // The instance will manage its own lifetime. |
| 32 new SetMetroBrowserFlowLauncher(profile); | 27 new SetMetroBrowserFlowLauncher(profile); |
| 33 } | 28 } |
| 34 | 29 |
| 35 private: | 30 private: |
| 36 explicit SetMetroBrowserFlowLauncher(Profile* profile) | 31 explicit SetMetroBrowserFlowLauncher(Profile* profile) |
| 37 : profile_(profile) { | 32 : profile_(profile) { |
| 38 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 33 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
|
sky
2016/07/06 19:21:18
Use a BrowserListObserver instead of notification
zmin
2016/07/06 20:04:30
Ok, I thought only the notification type with "dep
| |
| 39 content::NotificationService::AllSources()); | 34 content::NotificationService::AllSources()); |
| 40 } | 35 } |
| 41 | 36 |
| 42 // content::NotificationObserver override: | 37 // content::NotificationObserver override: |
| 43 void Observe(int type, | 38 void Observe(int type, |
| 44 const content::NotificationSource& source, | 39 const content::NotificationSource& source, |
| 45 const content::NotificationDetails& details) override; | 40 const content::NotificationDetails& details) override; |
| 46 | 41 |
| 47 content::NotificationRegistrar registrar_; | 42 content::NotificationRegistrar registrar_; |
| 48 Profile* profile_; | 43 Profile* profile_; |
| 49 | 44 |
| 50 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher); | 45 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher); |
| 51 }; | 46 }; |
| 52 | 47 |
| 53 void SetMetroBrowserFlowLauncher::Observe( | 48 void SetMetroBrowserFlowLauncher::Observe( |
| 54 int type, | 49 int type, |
| 55 const content::NotificationSource& source, | 50 const content::NotificationSource& source, |
| 56 const content::NotificationDetails& details) { | 51 const content::NotificationDetails& details) { |
| 57 DCHECK_EQ(content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, type); | 52 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_WINDOW_READY, type); |
| 58 | 53 |
| 59 Browser* browser = chrome::FindBrowserWithWebContents( | 54 Browser* browser = content::Source<Browser>(source).ptr(); |
| 60 content::Source<content::WebContents>(source).ptr()); | |
| 61 if (!browser || !browser->is_type_tabbed()) | 55 if (!browser || !browser->is_type_tabbed()) |
| 62 return; | 56 return; |
| 63 | 57 |
| 64 // Unregister and delete. | 58 // Unregister and delete. |
| 65 registrar_.RemoveAll(); | 59 registrar_.RemoveAll(); |
| 66 SetAsDefaultBrowserUI::Show(profile_, browser); | 60 SetAsDefaultBrowserUI::Show(profile_, browser); |
| 67 delete this; | 61 delete this; |
| 68 } | 62 } |
| 69 | 63 |
| 70 } // namespace | 64 } // namespace |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 87 | 81 |
| 88 if (show_status) { | 82 if (show_status) { |
| 89 startup_metric_utils::SetNonBrowserUIDisplayed(); | 83 startup_metric_utils::SetNonBrowserUIDisplayed(); |
| 90 SetMetroBrowserFlowLauncher::LaunchSoon(profile); | 84 SetMetroBrowserFlowLauncher::LaunchSoon(profile); |
| 91 } | 85 } |
| 92 | 86 |
| 93 return show_status; | 87 return show_status; |
| 94 } | 88 } |
| 95 | 89 |
| 96 } // namespace chrome | 90 } // namespace chrome |
| OLD | NEW |