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.
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/ui/extensions/application_launch.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h"
14 #include "chromeos/chromeos_switches.h"
15 #include "components/user_prefs/pref_registry_syncable.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
18 #include "content/public/browser/notification_service.h"
19 #include "extensions/browser/extension_system.h"
20 #include "extensions/common/constants.h"
27 void LaunchDialogForProfile(Profile
* profile
) {
28 ExtensionService
* service
=
29 extensions::ExtensionSystem::Get(profile
)->extension_service();
33 const extensions::Extension
* extension
=
34 service
->GetExtensionById(extension_misc::kFirstRunDialogId
, false);
38 OpenApplication(AppLaunchParams(
39 profile
, extension
, extensions::LAUNCH_CONTAINER_WINDOW
, NEW_WINDOW
));
40 profile
->GetPrefs()->SetBoolean(prefs::kFirstRunTutorialShown
, true);
43 // Object of this class waits for session start. Then it launches or not
44 // launches first-run dialog depending on user prefs and flags. Than object
46 class DialogLauncher
: public content::NotificationObserver
{
48 explicit DialogLauncher(Profile
* profile
)
52 chrome::NOTIFICATION_SESSION_STARTED
,
53 content::NotificationService::AllSources());
56 virtual ~DialogLauncher() {}
58 virtual void Observe(int type
,
59 const content::NotificationSource
& source
,
60 const content::NotificationDetails
& details
) OVERRIDE
{
61 DCHECK(type
== chrome::NOTIFICATION_SESSION_STARTED
);
62 DCHECK(content::Details
<const User
>(details
).ptr() ==
63 UserManager::Get()->GetUserByProfile(profile_
));
64 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
65 bool launched_in_test
= command_line
->HasSwitch(::switches::kTestType
);
66 bool launched_in_telemetry
=
67 command_line
->HasSwitch(switches::kOobeSkipPostLogin
);
68 bool first_run_disabled
=
69 command_line
->HasSwitch(switches::kDisableFirstRunUI
);
70 bool is_user_new
= chromeos::UserManager::Get()->IsCurrentUserNew();
71 bool first_run_forced
= command_line
->HasSwitch(switches::kForceFirstRunUI
);
73 profile_
->GetPrefs()->GetBoolean(prefs::kFirstRunTutorialShown
);
74 if (!launched_in_telemetry
&& !first_run_disabled
&&
75 ((is_user_new
&& !first_run_seen
&& !launched_in_test
) ||
77 LaunchDialogForProfile(profile_
);
84 content::NotificationRegistrar registrar_
;
86 DISALLOW_COPY_AND_ASSIGN(DialogLauncher
);
91 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
) {
92 registry
->RegisterBooleanPref(
93 prefs::kFirstRunTutorialShown
,
95 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF
);
98 void MaybeLaunchDialogAfterSessionStart() {
99 UserManager
* user_manager
= UserManager::Get();
101 user_manager
->GetProfileByUser(user_manager
->GetActiveUser()));
104 void LaunchTutorial() {
105 UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true);
106 FirstRunController::Start();
109 } // namespace first_run
110 } // namespace chromeos