[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 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. |
| 4 | |
Xiaohui Chen | abeb0dc | 2019-01-10 02:18:38 | [diff] [blame] | 5 | #include "chrome/browser/chromeos/first_run/first_run.h" |
| 6 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 7 | #include "base/command_line.h" |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 8 | #include "base/macros.h" |
asvitkine | b5663751 | 2016-09-01 19:41:40 | [diff] [blame] | 9 | #include "base/metrics/histogram_macros.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 10 | #include "chrome/browser/browser_process.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 11 | #include "chrome/browser/chrome_notification_types.h" |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 12 | #include "chrome/browser/chromeos/arc/arc_util.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 13 | #include "chrome/browser/chromeos/first_run/first_run_controller.h" |
updowndota | ec498067 | 2017-06-08 02:11:14 | [diff] [blame] | 14 | #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 15 | #include "chrome/browser/chromeos/login/wizard_controller.h" |
[email protected] | 052e3ac | 2014-06-30 14:22:47 | [diff] [blame] | 16 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_service.h" |
Denis Kuznetsov | d124ec8 | 2017-08-11 23:43:49 | [diff] [blame] | 18 | #include "chrome/browser/policy/profile_policy_connector.h" |
sdefresne | ed27d86b | 2015-09-14 11:02:38 | [diff] [blame] | 19 | #include "chrome/browser/prefs/pref_service_syncable_util.h" |
Hidehiko Abe | bac30e6 | 2017-07-18 03:52:58 | [diff] [blame] | 20 | #include "chrome/browser/profiles/profile.h" |
Antonio Gomes | c60f490f | 2018-11-28 00:44:20 | [diff] [blame] | 21 | #include "chrome/browser/signin/identity_manager_factory.h" |
Huanzhong Huang | afa9809 | 2019-06-24 12:01:24 | [diff] [blame] | 22 | #include "chrome/browser/ui/ash/tablet_mode_client.h" |
cylee | 49e02a9 | 2014-12-01 19:03:39 | [diff] [blame] | 23 | #include "chrome/browser/ui/extensions/app_launch_params.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 24 | #include "chrome/browser/ui/extensions/application_launch.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 25 | #include "chrome/common/chrome_switches.h" |
lfg | 3fba1a6 | 2014-11-04 22:26:25 | [diff] [blame] | 26 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 27 | #include "chrome/common/pref_names.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 28 | #include "chromeos/constants/chromeos_switches.h" |
Hidehiko Abe | 33e9adf | 2017-09-13 06:12:23 | [diff] [blame] | 29 | #include "components/arc/arc_prefs.h" |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 30 | #include "components/arc/arc_service_manager.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 31 | #include "components/pref_registry/pref_registry_syncable.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 32 | #include "components/prefs/pref_service.h" |
Yue Li | 3a60834 | 2017-08-09 06:03:46 | [diff] [blame] | 33 | #include "components/signin/core/browser/account_info.h" |
Henrique Ferreiro | 94eb46f | 2019-07-03 14:38:56 | [diff] [blame] | 34 | #include "components/signin/public/identity_manager/identity_manager.h" |
maxbogue | ea16ff41 | 2016-10-28 16:35:29 | [diff] [blame] | 35 | #include "components/sync_preferences/pref_service_syncable.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 36 | #include "components/user_manager/user_manager.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 37 | #include "content/public/browser/notification_observer.h" |
| 38 | #include "content/public/browser/notification_registrar.h" |
| 39 | #include "content/public/browser/notification_service.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 40 | #include "content/public/common/content_switches.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 41 | #include "extensions/browser/extension_system.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 42 | #include "extensions/common/constants.h" |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 43 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 44 | |
| 45 | namespace chromeos { |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 46 | namespace first_run { |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 47 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 48 | namespace { |
| 49 | |
| 50 | void LaunchDialogForProfile(Profile* profile) { |
Devlin Cronin | 803b13b | 2018-06-01 15:56:58 | [diff] [blame] | 51 | extensions::ExtensionService* service = |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 52 | 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 Willigers | 618e130 | 2019-06-23 23:03:47 | [diff] [blame] | 61 | OpenApplication( |
| 62 | AppLaunchParams(profile, extension->id(), |
| 63 | extensions::LaunchContainer::kLaunchContainerWindow, |
| 64 | WindowOpenDisposition::NEW_WINDOW, |
| 65 | extensions::AppLaunchSource::kSourceChromeInternal)); |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 66 | profile->GetPrefs()->SetBoolean(prefs::kFirstRunTutorialShown, true); |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 67 | } |
| 68 | |
muyuanli | c20d3c0 | 2017-05-19 00:39:32 | [diff] [blame] | 69 | void TryLaunchFirstRunDialog(Profile* profile) { |
| 70 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 71 | |
Darren Shen | 6f2fb11 | 2019-02-08 03:08:08 | [diff] [blame] | 72 | if (chromeos::switches::ShouldSkipOobePostLogin()) |
muyuanli | c20d3c0 | 2017-05-19 00:39:32 | [diff] [blame] | 73 | return; |
| 74 | |
| 75 | if (command_line->HasSwitch(switches::kForceFirstRunUI)) { |
| 76 | LaunchDialogForProfile(profile); |
| 77 | return; |
| 78 | } |
| 79 | |
Huanzhong Huang | afa9809 | 2019-06-24 12:01:24 | [diff] [blame] | 80 | // TabletModeClient does not exist in some tests. |
| 81 | if (TabletModeClient::Get() && TabletModeClient::Get()->tablet_mode_enabled()) |
Alexander Alekseev | 41183d8 | 2018-10-18 00:15:07 | [diff] [blame] | 82 | return; |
| 83 | |
Xi Han | fe39afc6 | 2019-04-29 14:50:14 | [diff] [blame] | 84 | if (profile->GetProfilePolicyConnector()->IsManaged()) |
Denis Kuznetsov | d124ec8 | 2017-08-11 23:43:49 | [diff] [blame] | 85 | return; |
| 86 | |
muyuanli | c20d3c0 | 2017-05-19 00:39:32 | [diff] [blame] | 87 | 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] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 106 | // 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. |
| 109 | class 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 | |
dcheng | c97a028 | 2015-01-15 23:04:24 | [diff] [blame] | 119 | ~DialogLauncher() override {} |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 120 | |
dcheng | c97a028 | 2015-01-15 23:04:24 | [diff] [blame] | 121 | void Observe(int type, |
| 122 | const content::NotificationSource& source, |
| 123 | const content::NotificationDetails& details) override { |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 124 | DCHECK(type == chrome::NOTIFICATION_SESSION_STARTED); |
[email protected] | 2fda997 | 2014-07-23 14:51:59 | [diff] [blame] | 125 | DCHECK(content::Details<const user_manager::User>(details).ptr() == |
[email protected] | 052e3ac | 2014-06-30 14:22:47 | [diff] [blame] | 126 | ProfileHelper::Get()->GetUserByProfile(profile_)); |
updowndota | ec498067 | 2017-06-08 02:11:14 | [diff] [blame] | 127 | |
Xiaohui Chen | f796f14c | 2019-02-21 02:43:28 | [diff] [blame] | 128 | TryLaunchFirstRunDialog(profile_); |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 129 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 130 | 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 | |
| 142 | void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
Sarah Hu | 00eaa5a | 2017-08-14 17:16:13 | [diff] [blame] | 143 | // 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] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void MaybeLaunchDialogAfterSessionStart() { |
[email protected] | 6426834 | 2014-08-12 17:18:22 | [diff] [blame] | 150 | new DialogLauncher(ProfileHelper::Get()->GetProfileByUserUnsafe( |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 151 | user_manager::UserManager::Get()->GetActiveUser())); |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 152 | } |
| 153 | |
muyuanli | c20d3c0 | 2017-05-19 00:39:32 | [diff] [blame] | 154 | void MaybeLaunchDialogImmediately() { |
| 155 | TryLaunchFirstRunDialog(ProfileHelper::Get()->GetProfileByUser( |
| 156 | user_manager::UserManager::Get()->GetActiveUser())); |
| 157 | } |
| 158 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 159 | void LaunchTutorial() { |
[email protected] | 1876f39 | 2014-01-16 16:13:57 | [diff] [blame] | 160 | UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true); |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 161 | FirstRunController::Start(); |
| 162 | } |
| 163 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 164 | } // namespace first_run |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 165 | } // namespace chromeos |