• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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.
4 
5 #include "base/command_line.h"
6 #include "base/metrics/histogram.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/chromeos/first_run/first_run_controller.h"
9 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/ui/extensions/application_launch.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chromeos/chromeos_switches.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/browser/notification_service.h"
18 #include "extensions/common/constants.h"
19 
20 namespace chromeos {
21 namespace first_run {
22 
23 namespace {
24 
LaunchDialogForProfile(Profile * profile)25 void LaunchDialogForProfile(Profile* profile) {
26   ExtensionService* service =
27       extensions::ExtensionSystem::Get(profile)->extension_service();
28   if (!service)
29     return;
30 
31   const extensions::Extension* extension =
32       service->GetExtensionById(extension_misc::kFirstRunDialogId, false);
33   if (!extension)
34     return;
35 
36   OpenApplication(AppLaunchParams(
37       profile, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
38 }
39 
40 // Object of this class waits for session start. Then it launches or not
41 // launches first-run dialog depending on flags. Than object deletes itself.
42 class DialogLauncher : public content::NotificationObserver {
43  public:
DialogLauncher(Profile * profile)44   explicit DialogLauncher(Profile* profile)
45       : profile_(profile) {
46     DCHECK(profile);
47     registrar_.Add(this,
48                    chrome::NOTIFICATION_SESSION_STARTED,
49                    content::NotificationService::AllSources());
50   }
51 
~DialogLauncher()52   virtual ~DialogLauncher() {}
53 
Observe(int type,const content::NotificationSource & source,const content::NotificationDetails & details)54   virtual void Observe(int type,
55                        const content::NotificationSource& source,
56                        const content::NotificationDetails& details) OVERRIDE {
57     DCHECK(type == chrome::NOTIFICATION_SESSION_STARTED);
58     DCHECK(content::Details<const User>(details).ptr() ==
59         UserManager::Get()->GetUserByProfile(profile_));
60     CommandLine* command_line = CommandLine::ForCurrentProcess();
61     bool launched_in_test = command_line->HasSwitch(::switches::kTestType);
62     bool launched_in_telemetry =
63         command_line->HasSwitch(switches::kOobeSkipPostLogin);
64     bool first_run_disabled =
65         command_line->HasSwitch(switches::kDisableFirstRunUI);
66     bool is_user_new = chromeos::UserManager::Get()->IsCurrentUserNew();
67     bool first_run_forced = command_line->HasSwitch(switches::kForceFirstRunUI);
68     if (!launched_in_telemetry && !first_run_disabled &&
69         ((is_user_new && !launched_in_test) || first_run_forced)) {
70       LaunchDialogForProfile(profile_);
71     }
72     delete this;
73   }
74 
75  private:
76   Profile* profile_;
77   content::NotificationRegistrar registrar_;
78 
79   DISALLOW_COPY_AND_ASSIGN(DialogLauncher);
80 };
81 
82 }  // namespace
83 
MaybeLaunchDialogAfterSessionStart()84 void MaybeLaunchDialogAfterSessionStart() {
85   UserManager* user_manager = UserManager::Get();
86   new DialogLauncher(
87       user_manager->GetProfileByUser(user_manager->GetActiveUser()));
88 }
89 
LaunchTutorial()90 void LaunchTutorial() {
91   UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true);
92   FirstRunController::Start();
93 }
94 
95 }  // namespace first_run
96 }  // namespace chromeos
97