blob: a0fcc8f5f0d8adfd3df2763accab86eb31275c2d [file] [log] [blame]
[email protected]5ee08bf2013-11-30 05:25:301// 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
[email protected]980d5f9e2013-12-17 17:47:085#include "base/command_line.h"
[email protected]1876f392014-01-16 16:13:576#include "base/metrics/histogram.h"
[email protected]980d5f9e2013-12-17 17:47:087#include "chrome/browser/chrome_notification_types.h"
[email protected]5ee08bf2013-11-30 05:25:308#include "chrome/browser/chromeos/first_run/first_run_controller.h"
[email protected]5ee08bf2013-11-30 05:25:309#include "chrome/browser/chromeos/login/user_manager.h"
10#include "chrome/browser/extensions/extension_service.h"
[email protected]5ee08bf2013-11-30 05:25:3011#include "chrome/browser/ui/extensions/application_launch.h"
[email protected]980d5f9e2013-12-17 17:47:0812#include "chrome/common/chrome_switches.h"
13#include "chrome/common/pref_names.h"
14#include "chromeos/chromeos_switches.h"
[email protected]f0c8c4992014-05-15 17:37:2615#include "components/pref_registry/pref_registry_syncable.h"
[email protected]980d5f9e2013-12-17 17:47:0816#include "content/public/browser/notification_observer.h"
17#include "content/public/browser/notification_registrar.h"
18#include "content/public/browser/notification_service.h"
[email protected]59b0e602014-01-30 00:41:2419#include "extensions/browser/extension_system.h"
[email protected]5ee08bf2013-11-30 05:25:3020#include "extensions/common/constants.h"
21
22namespace chromeos {
[email protected]980d5f9e2013-12-17 17:47:0823namespace first_run {
[email protected]5ee08bf2013-11-30 05:25:3024
[email protected]980d5f9e2013-12-17 17:47:0825namespace {
26
27void LaunchDialogForProfile(Profile* profile) {
[email protected]5ee08bf2013-11-30 05:25:3028 ExtensionService* service =
29 extensions::ExtensionSystem::Get(profile)->extension_service();
30 if (!service)
31 return;
32
33 const extensions::Extension* extension =
34 service->GetExtensionById(extension_misc::kFirstRunDialogId, false);
35 if (!extension)
36 return;
37
38 OpenApplication(AppLaunchParams(
[email protected]ec453fb2013-12-06 14:05:2739 profile, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
[email protected]980d5f9e2013-12-17 17:47:0840 profile->GetPrefs()->SetBoolean(prefs::kFirstRunTutorialShown, true);
[email protected]5ee08bf2013-11-30 05:25:3041}
42
[email protected]980d5f9e2013-12-17 17:47:0843// 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.
46class 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());
54 }
55
56 virtual ~DialogLauncher() {}
57
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_);
78 }
79 delete this;
80 }
81
82 private:
83 Profile* profile_;
84 content::NotificationRegistrar registrar_;
85
86 DISALLOW_COPY_AND_ASSIGN(DialogLauncher);
87};
88
89} // namespace
90
91void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
92 registry->RegisterBooleanPref(
93 prefs::kFirstRunTutorialShown,
94 false,
95 user_prefs::PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF);
96}
97
98void MaybeLaunchDialogAfterSessionStart() {
99 UserManager* user_manager = UserManager::Get();
100 new DialogLauncher(
101 user_manager->GetProfileByUser(user_manager->GetActiveUser()));
102}
103
104void LaunchTutorial() {
[email protected]1876f392014-01-16 16:13:57105 UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true);
[email protected]5ee08bf2013-11-30 05:25:30106 FirstRunController::Start();
107}
108
[email protected]980d5f9e2013-12-17 17:47:08109} // namespace first_run
[email protected]5ee08bf2013-11-30 05:25:30110} // namespace chromeos