blob: 9b1648f4ca6ae967579c2d67437c58140864cb21 [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
Xiaohui Chenabeb0dc2019-01-10 02:18:385#include "chrome/browser/chromeos/first_run/first_run.h"
6
[email protected]980d5f9e2013-12-17 17:47:087#include "base/command_line.h"
avi8a07d53892015-12-24 22:13:538#include "base/macros.h"
asvitkineb56637512016-09-01 19:41:409#include "base/metrics/histogram_macros.h"
[email protected]4d390782014-08-15 09:22:5810#include "chrome/browser/browser_process.h"
[email protected]980d5f9e2013-12-17 17:47:0811#include "chrome/browser/chrome_notification_types.h"
updowndota07ecbf22017-06-28 05:34:0612#include "chrome/browser/chromeos/arc/arc_util.h"
[email protected]5ee08bf2013-11-30 05:25:3013#include "chrome/browser/chromeos/first_run/first_run_controller.h"
updowndotaec4980672017-06-08 02:11:1414#include "chrome/browser/chromeos/login/ui/login_display_host.h"
15#include "chrome/browser/chromeos/login/wizard_controller.h"
[email protected]052e3ac2014-06-30 14:22:4716#include "chrome/browser/chromeos/profiles/profile_helper.h"
[email protected]5ee08bf2013-11-30 05:25:3017#include "chrome/browser/extensions/extension_service.h"
Denis Kuznetsovd124ec82017-08-11 23:43:4918#include "chrome/browser/policy/profile_policy_connector.h"
sdefresneed27d86b2015-09-14 11:02:3819#include "chrome/browser/prefs/pref_service_syncable_util.h"
Hidehiko Abebac30e62017-07-18 03:52:5820#include "chrome/browser/profiles/profile.h"
Antonio Gomesc60f490f2018-11-28 00:44:2021#include "chrome/browser/signin/identity_manager_factory.h"
Huanzhong Huangafa98092019-06-24 12:01:2422#include "chrome/browser/ui/ash/tablet_mode_client.h"
cylee49e02a92014-12-01 19:03:3923#include "chrome/browser/ui/extensions/app_launch_params.h"
[email protected]5ee08bf2013-11-30 05:25:3024#include "chrome/browser/ui/extensions/application_launch.h"
[email protected]980d5f9e2013-12-17 17:47:0825#include "chrome/common/chrome_switches.h"
lfg3fba1a62014-11-04 22:26:2526#include "chrome/common/extensions/extension_constants.h"
[email protected]980d5f9e2013-12-17 17:47:0827#include "chrome/common/pref_names.h"
Steven Bennetts38e9bde22019-01-03 17:31:1028#include "chromeos/constants/chromeos_switches.h"
Hidehiko Abe33e9adf2017-09-13 06:12:2329#include "components/arc/arc_prefs.h"
updowndota07ecbf22017-06-28 05:34:0630#include "components/arc/arc_service_manager.h"
[email protected]f0c8c4992014-05-15 17:37:2631#include "components/pref_registry/pref_registry_syncable.h"
brettwb1fc1b82016-02-02 00:19:0832#include "components/prefs/pref_service.h"
Yue Li3a608342017-08-09 06:03:4633#include "components/signin/core/browser/account_info.h"
Henrique Ferreiro94eb46f2019-07-03 14:38:5634#include "components/signin/public/identity_manager/identity_manager.h"
maxbogueea16ff412016-10-28 16:35:2935#include "components/sync_preferences/pref_service_syncable.h"
[email protected]4d390782014-08-15 09:22:5836#include "components/user_manager/user_manager.h"
[email protected]980d5f9e2013-12-17 17:47:0837#include "content/public/browser/notification_observer.h"
38#include "content/public/browser/notification_registrar.h"
39#include "content/public/browser/notification_service.h"
brettw90e92602015-10-10 00:12:4040#include "content/public/common/content_switches.h"
[email protected]59b0e602014-01-30 00:41:2441#include "extensions/browser/extension_system.h"
[email protected]5ee08bf2013-11-30 05:25:3042#include "extensions/common/constants.h"
updowndota07ecbf22017-06-28 05:34:0643#include "ui/gfx/geometry/rect.h"
[email protected]5ee08bf2013-11-30 05:25:3044
45namespace chromeos {
[email protected]980d5f9e2013-12-17 17:47:0846namespace first_run {
[email protected]5ee08bf2013-11-30 05:25:3047
[email protected]980d5f9e2013-12-17 17:47:0848namespace {
49
50void LaunchDialogForProfile(Profile* profile) {
Devlin Cronin803b13b2018-06-01 15:56:5851 extensions::ExtensionService* service =
[email protected]5ee08bf2013-11-30 05:25:3052 extensions::ExtensionSystem::Get(profile)->extension_service();
53 if (!service)
54 return;
55
56 const extensions::Extension* extension =
57 service->GetExtensionById(extension_misc::kFirstRunDialogId, false);
58 if (!extension)
59 return;
60
Eric Willigers618e1302019-06-23 23:03:4761 OpenApplication(
62 AppLaunchParams(profile, extension->id(),
63 extensions::LaunchContainer::kLaunchContainerWindow,
64 WindowOpenDisposition::NEW_WINDOW,
65 extensions::AppLaunchSource::kSourceChromeInternal));
[email protected]980d5f9e2013-12-17 17:47:0866 profile->GetPrefs()->SetBoolean(prefs::kFirstRunTutorialShown, true);
[email protected]5ee08bf2013-11-30 05:25:3067}
68
muyuanlic20d3c02017-05-19 00:39:3269void TryLaunchFirstRunDialog(Profile* profile) {
70 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
71
Darren Shen6f2fb112019-02-08 03:08:0872 if (chromeos::switches::ShouldSkipOobePostLogin())
muyuanlic20d3c02017-05-19 00:39:3273 return;
74
75 if (command_line->HasSwitch(switches::kForceFirstRunUI)) {
76 LaunchDialogForProfile(profile);
77 return;
78 }
79
Huanzhong Huangafa98092019-06-24 12:01:2480 // TabletModeClient does not exist in some tests.
81 if (TabletModeClient::Get() && TabletModeClient::Get()->tablet_mode_enabled())
Alexander Alekseev41183d82018-10-18 00:15:0782 return;
83
Xi Hanfe39afc62019-04-29 14:50:1484 if (profile->GetProfilePolicyConnector()->IsManaged())
Denis Kuznetsovd124ec82017-08-11 23:43:4985 return;
86
muyuanlic20d3c02017-05-19 00:39:3287 if (command_line->HasSwitch(::switches::kTestType))
88 return;
89
90 if (!user_manager::UserManager::Get()->IsCurrentUserNew())
91 return;
92
93 if (profile->GetPrefs()->GetBoolean(prefs::kFirstRunTutorialShown))
94 return;
95
96 bool is_pref_synced =
97 PrefServiceSyncableFromProfile(profile)->IsPrioritySyncing();
98 bool is_user_ephemeral = user_manager::UserManager::Get()
99 ->IsCurrentUserNonCryptohomeDataEphemeral();
100 if (!is_pref_synced && is_user_ephemeral)
101 return;
102
103 LaunchDialogForProfile(profile);
104}
105
[email protected]980d5f9e2013-12-17 17:47:08106// Object of this class waits for session start. Then it launches or not
107// launches first-run dialog depending on user prefs and flags. Than object
108// deletes itself.
109class DialogLauncher : public content::NotificationObserver {
110 public:
111 explicit DialogLauncher(Profile* profile)
112 : profile_(profile) {
113 DCHECK(profile);
114 registrar_.Add(this,
115 chrome::NOTIFICATION_SESSION_STARTED,
116 content::NotificationService::AllSources());
117 }
118
dchengc97a0282015-01-15 23:04:24119 ~DialogLauncher() override {}
[email protected]980d5f9e2013-12-17 17:47:08120
dchengc97a0282015-01-15 23:04:24121 void Observe(int type,
122 const content::NotificationSource& source,
123 const content::NotificationDetails& details) override {
[email protected]980d5f9e2013-12-17 17:47:08124 DCHECK(type == chrome::NOTIFICATION_SESSION_STARTED);
[email protected]2fda9972014-07-23 14:51:59125 DCHECK(content::Details<const user_manager::User>(details).ptr() ==
[email protected]052e3ac2014-06-30 14:22:47126 ProfileHelper::Get()->GetUserByProfile(profile_));
updowndotaec4980672017-06-08 02:11:14127
Xiaohui Chenf796f14c2019-02-21 02:43:28128 TryLaunchFirstRunDialog(profile_);
updowndota07ecbf22017-06-28 05:34:06129
[email protected]980d5f9e2013-12-17 17:47:08130 delete this;
131 }
132
133 private:
134 Profile* profile_;
135 content::NotificationRegistrar registrar_;
136
137 DISALLOW_COPY_AND_ASSIGN(DialogLauncher);
138};
139
140} // namespace
141
142void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
Sarah Hu00eaa5a2017-08-14 17:16:13143 // This preference used to be syncable, change it to non-syncable so new
144 // users will always see the welcome app on a new device.
145 // See crbug.com/752361
146 registry->RegisterBooleanPref(prefs::kFirstRunTutorialShown, false);
[email protected]980d5f9e2013-12-17 17:47:08147}
148
149void MaybeLaunchDialogAfterSessionStart() {
[email protected]64268342014-08-12 17:18:22150 new DialogLauncher(ProfileHelper::Get()->GetProfileByUserUnsafe(
[email protected]4d390782014-08-15 09:22:58151 user_manager::UserManager::Get()->GetActiveUser()));
[email protected]980d5f9e2013-12-17 17:47:08152}
153
muyuanlic20d3c02017-05-19 00:39:32154void MaybeLaunchDialogImmediately() {
155 TryLaunchFirstRunDialog(ProfileHelper::Get()->GetProfileByUser(
156 user_manager::UserManager::Get()->GetActiveUser()));
157}
158
[email protected]980d5f9e2013-12-17 17:47:08159void LaunchTutorial() {
[email protected]1876f392014-01-16 16:13:57160 UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true);
[email protected]5ee08bf2013-11-30 05:25:30161 FirstRunController::Start();
162}
163
[email protected]980d5f9e2013-12-17 17:47:08164} // namespace first_run
[email protected]5ee08bf2013-11-30 05:25:30165} // namespace chromeos