Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / startup / default_browser_prompt_win.cc
blob4b19c166e538dbc06b53873846f176023f8120e9
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/startup/default_browser_prompt.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/shell_integration.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_finder.h"
12 #include "chrome/browser/ui/webui/set_as_default_browser_ui.h"
13 #include "components/startup_metric_utils/startup_metric_utils.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/notification_types.h"
18 using content::BrowserThread;
20 namespace {
22 // Show the page prompting the user to make Chrome the default browser on
23 // Windows 8 (which means becoming "the browser" in Metro mode). The page
24 // will be shown at the first appropriate opportunity. It can be placed in
25 // a tab or in a dialog, depending on other settings.
26 class SetMetroBrowserFlowLauncher : public content::NotificationObserver {
27 public:
28 static void LaunchSoon(Profile* profile) {
29 // The instance will manage its own lifetime.
30 new SetMetroBrowserFlowLauncher(profile);
33 private:
34 explicit SetMetroBrowserFlowLauncher(Profile* profile)
35 : profile_(profile) {
36 registrar_.Add(this, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
37 content::NotificationService::AllSources());
40 // content::NotificationObserver override:
41 void Observe(int type,
42 const content::NotificationSource& source,
43 const content::NotificationDetails& details) override;
45 content::NotificationRegistrar registrar_;
46 Profile* profile_;
48 DISALLOW_COPY_AND_ASSIGN(SetMetroBrowserFlowLauncher);
51 void SetMetroBrowserFlowLauncher::Observe(
52 int type,
53 const content::NotificationSource& source,
54 const content::NotificationDetails& details) {
55 DCHECK_EQ(type, content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME);
56 Browser* browser = chrome::FindBrowserWithWebContents(
57 content::Source<content::WebContents>(source).ptr());
59 if (!browser || !browser->is_type_tabbed())
60 return;
62 // Unregister and delete.
63 registrar_.RemoveAll();
64 SetAsDefaultBrowserUI::Show(profile_, browser);
65 delete this;
68 } // namespace
70 namespace chrome {
72 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
73 // If the only available mode of setting the default browser requires
74 // user interaction, it means this couldn't have been done yet. Therefore,
75 // we launch the dialog and inform the caller of it.
76 bool show_status =
77 (ShellIntegration::CanSetAsDefaultBrowser() ==
78 ShellIntegration::SET_DEFAULT_INTERACTIVE) &&
79 (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT);
81 if (show_status) {
82 startup_metric_utils::SetNonBrowserUIDisplayed();
83 SetMetroBrowserFlowLauncher::LaunchSoon(profile);
86 return show_status;
89 } // namespace chrome