Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / first_run / first_run.cc
blob27b94fa2482cf8546a3fc33b7256d2607b85692c
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/profiles/profile_manager.h"
14 #include "chrome/browser/ui/extensions/app_launch_params.h"
15 #include "chrome/browser/ui/extensions/application_launch.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/extensions/extension_constants.h"
18 #include "chrome/common/pref_names.h"
19 #include "chromeos/chromeos_switches.h"
20 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "components/user_manager/user_manager.h"
22 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/notification_service.h"
25 #include "extensions/browser/extension_system.h"
26 #include "extensions/common/constants.h"
28 namespace chromeos {
29 namespace first_run {
31 namespace {
33 void LaunchDialogForProfile(Profile* profile) {
34 ExtensionService* service =
35 extensions::ExtensionSystem::Get(profile)->extension_service();
36 if (!service)
37 return;
39 const extensions::Extension* extension =
40 service->GetExtensionById(extension_misc::kFirstRunDialogId, false);
41 if (!extension)
42 return;
44 OpenApplication(
45 AppLaunchParams(profile, extension, extensions::LAUNCH_CONTAINER_WINDOW,
46 NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL));
47 profile->GetPrefs()->SetBoolean(prefs::kFirstRunTutorialShown, true);
50 // Object of this class waits for session start. Then it launches or not
51 // launches first-run dialog depending on user prefs and flags. Than object
52 // deletes itself.
53 class DialogLauncher : public content::NotificationObserver {
54 public:
55 explicit DialogLauncher(Profile* profile)
56 : profile_(profile) {
57 DCHECK(profile);
58 registrar_.Add(this,
59 chrome::NOTIFICATION_SESSION_STARTED,
60 content::NotificationService::AllSources());
63 ~DialogLauncher() override {}
65 void Observe(int type,
66 const content::NotificationSource& source,
67 const content::NotificationDetails& details) override {
68 DCHECK(type == chrome::NOTIFICATION_SESSION_STARTED);
69 DCHECK(content::Details<const user_manager::User>(details).ptr() ==
70 ProfileHelper::Get()->GetUserByProfile(profile_));
71 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
72 bool launched_in_test = command_line->HasSwitch(::switches::kTestType);
73 bool launched_in_telemetry =
74 command_line->HasSwitch(switches::kOobeSkipPostLogin);
75 bool is_user_new = user_manager::UserManager::Get()->IsCurrentUserNew();
76 bool first_run_forced = command_line->HasSwitch(switches::kForceFirstRunUI);
77 bool first_run_seen =
78 profile_->GetPrefs()->GetBoolean(prefs::kFirstRunTutorialShown);
79 if (!launched_in_telemetry &&
80 ((is_user_new && !first_run_seen && !launched_in_test) ||
81 first_run_forced)) {
82 LaunchDialogForProfile(profile_);
84 delete this;
87 private:
88 Profile* profile_;
89 content::NotificationRegistrar registrar_;
91 DISALLOW_COPY_AND_ASSIGN(DialogLauncher);
94 } // namespace
96 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
97 registry->RegisterBooleanPref(
98 prefs::kFirstRunTutorialShown,
99 false,
100 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
103 void MaybeLaunchDialogAfterSessionStart() {
104 new DialogLauncher(ProfileHelper::Get()->GetProfileByUserUnsafe(
105 user_manager::UserManager::Get()->GetActiveUser()));
108 void LaunchTutorial() {
109 UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true);
110 FirstRunController::Start();
113 } // namespace first_run
114 } // namespace chromeos