Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / chromeos / first_run / first_run.cc
blobbbd6c48ef370bf6ceb923be6bf930dd697a15b9c
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 "base/prefs/pref_service.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/chromeos/first_run/first_run_controller.h"
11 #include "chrome/browser/chromeos/profiles/profile_helper.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/prefs/pref_service_syncable_util.h"
14 #include "chrome/browser/profiles/profile_manager.h"
15 #include "chrome/browser/ui/extensions/app_launch_params.h"
16 #include "chrome/browser/ui/extensions/application_launch.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/common/pref_names.h"
20 #include "chromeos/chromeos_switches.h"
21 #include "components/pref_registry/pref_registry_syncable.h"
22 #include "components/syncable_prefs/pref_service_syncable.h"
23 #include "components/user_manager/user_manager.h"
24 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h"
26 #include "content/public/browser/notification_service.h"
27 #include "extensions/browser/extension_system.h"
28 #include "extensions/common/constants.h"
30 namespace chromeos {
31 namespace first_run {
33 namespace {
35 void LaunchDialogForProfile(Profile* profile) {
36 ExtensionService* service =
37 extensions::ExtensionSystem::Get(profile)->extension_service();
38 if (!service)
39 return;
41 const extensions::Extension* extension =
42 service->GetExtensionById(extension_misc::kFirstRunDialogId, false);
43 if (!extension)
44 return;
46 OpenApplication(
47 AppLaunchParams(profile, extension, extensions::LAUNCH_CONTAINER_WINDOW,
48 NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL));
49 profile->GetPrefs()->SetBoolean(prefs::kFirstRunTutorialShown, true);
52 // Object of this class waits for session start. Then it launches or not
53 // launches first-run dialog depending on user prefs and flags. Than object
54 // deletes itself.
55 class DialogLauncher : public content::NotificationObserver {
56 public:
57 explicit DialogLauncher(Profile* profile)
58 : profile_(profile) {
59 DCHECK(profile);
60 registrar_.Add(this,
61 chrome::NOTIFICATION_SESSION_STARTED,
62 content::NotificationService::AllSources());
65 ~DialogLauncher() override {}
67 void Observe(int type,
68 const content::NotificationSource& source,
69 const content::NotificationDetails& details) override {
70 DCHECK(type == chrome::NOTIFICATION_SESSION_STARTED);
71 DCHECK(content::Details<const user_manager::User>(details).ptr() ==
72 ProfileHelper::Get()->GetUserByProfile(profile_));
73 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
74 bool launched_in_test = command_line->HasSwitch(::switches::kTestType);
75 bool launched_in_telemetry =
76 command_line->HasSwitch(switches::kOobeSkipPostLogin);
77 bool is_user_new = user_manager::UserManager::Get()->IsCurrentUserNew();
78 bool first_run_forced = command_line->HasSwitch(switches::kForceFirstRunUI);
79 bool first_run_seen =
80 profile_->GetPrefs()->GetBoolean(prefs::kFirstRunTutorialShown);
81 bool is_pref_synced =
82 PrefServiceSyncableFromProfile(profile_)->IsPrioritySyncing();
83 bool is_user_ephemeral = user_manager::UserManager::Get()
84 ->IsCurrentUserNonCryptohomeDataEphemeral();
85 if (!launched_in_telemetry &&
86 ((is_user_new && !first_run_seen &&
87 (is_pref_synced || !is_user_ephemeral) && !launched_in_test) ||
88 first_run_forced)) {
89 LaunchDialogForProfile(profile_);
91 delete this;
94 private:
95 Profile* profile_;
96 content::NotificationRegistrar registrar_;
98 DISALLOW_COPY_AND_ASSIGN(DialogLauncher);
101 } // namespace
103 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
104 registry->RegisterBooleanPref(
105 prefs::kFirstRunTutorialShown,
106 false,
107 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
110 void MaybeLaunchDialogAfterSessionStart() {
111 new DialogLauncher(ProfileHelper::Get()->GetProfileByUserUnsafe(
112 user_manager::UserManager::Get()->GetActiveUser()));
115 void LaunchTutorial() {
116 UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true);
117 FirstRunController::Start();
120 } // namespace first_run
121 } // namespace chromeos