Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / first_run / first_run.cc
blobb6f9aabc6dbd4cbe2ee15235445f8d1ba4334a9f
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"
22 namespace chromeos {
23 namespace first_run {
25 namespace {
27 void LaunchDialogForProfile(Profile* profile) {
28 ExtensionService* service =
29 extensions::ExtensionSystem::Get(profile)->extension_service();
30 if (!service)
31 return;
33 const extensions::Extension* extension =
34 service->GetExtensionById(extension_misc::kFirstRunDialogId, false);
35 if (!extension)
36 return;
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
45 // deletes itself.
46 class DialogLauncher : public content::NotificationObserver {
47 public:
48 explicit DialogLauncher(Profile* profile)
49 : profile_(profile) {
50 DCHECK(profile);
51 registrar_.Add(this,
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);
72 bool first_run_seen =
73 profile_->GetPrefs()->GetBoolean(prefs::kFirstRunTutorialShown);
74 if (!launched_in_telemetry && !first_run_disabled &&
75 ((is_user_new && !first_run_seen && !launched_in_test) ||
76 first_run_forced)) {
77 LaunchDialogForProfile(profile_);
79 delete this;
82 private:
83 Profile* profile_;
84 content::NotificationRegistrar registrar_;
86 DISALLOW_COPY_AND_ASSIGN(DialogLauncher);
89 } // namespace
91 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
92 registry->RegisterBooleanPref(
93 prefs::kFirstRunTutorialShown,
94 false,
95 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
98 void MaybeLaunchDialogAfterSessionStart() {
99 UserManager* user_manager = UserManager::Get();
100 new DialogLauncher(
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