[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 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 5 | #include "base/command_line.h" |
avi | 8a07d5389 | 2015-12-24 22:13:53 | [diff] [blame] | 6 | #include "base/macros.h" |
asvitkine | b5663751 | 2016-09-01 19:41:40 | [diff] [blame] | 7 | #include "base/metrics/histogram_macros.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 8 | #include "chrome/browser/browser_process.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 9 | #include "chrome/browser/chrome_notification_types.h" |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 10 | #include "chrome/browser/chromeos/arc/arc_util.h" |
| 11 | #include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_framework_service.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 12 | #include "chrome/browser/chromeos/first_run/first_run_controller.h" |
updowndota | ec498067 | 2017-06-08 02:11:14 | [diff] [blame] | 13 | #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 14 | #include "chrome/browser/chromeos/login/wizard_controller.h" |
[email protected] | 052e3ac | 2014-06-30 14:22:47 | [diff] [blame] | 15 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_service.h" |
Denis Kuznetsov | d124ec8 | 2017-08-11 23:43:49 | [diff] [blame] | 17 | #include "chrome/browser/policy/profile_policy_connector.h" |
| 18 | #include "chrome/browser/policy/profile_policy_connector_factory.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" |
Yue Li | 3a60834 | 2017-08-09 06:03:46 | [diff] [blame] | 21 | #include "chrome/browser/signin/signin_manager_factory.h" |
cylee | 49e02a9 | 2014-12-01 19:03:39 | [diff] [blame] | 22 | #include "chrome/browser/ui/extensions/app_launch_params.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 23 | #include "chrome/browser/ui/extensions/application_launch.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 24 | #include "chrome/common/chrome_switches.h" |
lfg | 3fba1a6 | 2014-11-04 22:26:25 | [diff] [blame] | 25 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 26 | #include "chrome/common/pref_names.h" |
| 27 | #include "chromeos/chromeos_switches.h" |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 28 | #include "components/arc/arc_service_manager.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 29 | #include "components/pref_registry/pref_registry_syncable.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 30 | #include "components/prefs/pref_service.h" |
Yue Li | 3a60834 | 2017-08-09 06:03:46 | [diff] [blame] | 31 | #include "components/signin/core/browser/account_info.h" |
| 32 | #include "components/signin/core/browser/account_tracker_service.h" |
| 33 | #include "components/signin/core/browser/signin_manager.h" |
maxbogue | ea16ff41 | 2016-10-28 16:35:29 | [diff] [blame] | 34 | #include "components/sync_preferences/pref_service_syncable.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 35 | #include "components/user_manager/user_manager.h" |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 36 | #include "content/public/browser/notification_observer.h" |
| 37 | #include "content/public/browser/notification_registrar.h" |
| 38 | #include "content/public/browser/notification_service.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 39 | #include "content/public/common/content_switches.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 40 | #include "extensions/browser/extension_system.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 41 | #include "extensions/common/constants.h" |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 42 | #include "ui/gfx/geometry/rect.h" |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 43 | |
| 44 | namespace chromeos { |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 45 | namespace first_run { |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 46 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 47 | namespace { |
| 48 | |
| 49 | void LaunchDialogForProfile(Profile* profile) { |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 50 | ExtensionService* service = |
| 51 | extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 52 | if (!service) |
| 53 | return; |
| 54 | |
| 55 | const extensions::Extension* extension = |
| 56 | service->GetExtensionById(extension_misc::kFirstRunDialogId, false); |
| 57 | if (!extension) |
| 58 | return; |
| 59 | |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 60 | OpenApplication(AppLaunchParams( |
| 61 | profile, extension, extensions::LAUNCH_CONTAINER_WINDOW, |
| 62 | WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 63 | profile->GetPrefs()->SetBoolean(prefs::kFirstRunTutorialShown, true); |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 64 | } |
| 65 | |
muyuanli | c20d3c0 | 2017-05-19 00:39:32 | [diff] [blame] | 66 | void TryLaunchFirstRunDialog(Profile* profile) { |
| 67 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 68 | |
| 69 | if (command_line->HasSwitch(switches::kOobeSkipPostLogin)) |
| 70 | return; |
| 71 | |
| 72 | if (command_line->HasSwitch(switches::kForceFirstRunUI)) { |
| 73 | LaunchDialogForProfile(profile); |
| 74 | return; |
| 75 | } |
| 76 | |
Denis Kuznetsov | d124ec8 | 2017-08-11 23:43:49 | [diff] [blame] | 77 | if (policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile) |
| 78 | ->IsManaged()) |
| 79 | return; |
| 80 | |
muyuanli | c20d3c0 | 2017-05-19 00:39:32 | [diff] [blame] | 81 | if (command_line->HasSwitch(::switches::kTestType)) |
| 82 | return; |
| 83 | |
| 84 | if (!user_manager::UserManager::Get()->IsCurrentUserNew()) |
| 85 | return; |
| 86 | |
| 87 | if (profile->GetPrefs()->GetBoolean(prefs::kFirstRunTutorialShown)) |
| 88 | return; |
| 89 | |
| 90 | bool is_pref_synced = |
| 91 | PrefServiceSyncableFromProfile(profile)->IsPrioritySyncing(); |
| 92 | bool is_user_ephemeral = user_manager::UserManager::Get() |
| 93 | ->IsCurrentUserNonCryptohomeDataEphemeral(); |
| 94 | if (!is_pref_synced && is_user_ephemeral) |
| 95 | return; |
| 96 | |
| 97 | LaunchDialogForProfile(profile); |
| 98 | } |
| 99 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 100 | // Object of this class waits for session start. Then it launches or not |
| 101 | // launches first-run dialog depending on user prefs and flags. Than object |
| 102 | // deletes itself. |
| 103 | class DialogLauncher : public content::NotificationObserver { |
| 104 | public: |
| 105 | explicit DialogLauncher(Profile* profile) |
| 106 | : profile_(profile) { |
| 107 | DCHECK(profile); |
| 108 | registrar_.Add(this, |
| 109 | chrome::NOTIFICATION_SESSION_STARTED, |
| 110 | content::NotificationService::AllSources()); |
| 111 | } |
| 112 | |
dcheng | c97a028 | 2015-01-15 23:04:24 | [diff] [blame] | 113 | ~DialogLauncher() override {} |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 114 | |
dcheng | c97a028 | 2015-01-15 23:04:24 | [diff] [blame] | 115 | void Observe(int type, |
| 116 | const content::NotificationSource& source, |
| 117 | const content::NotificationDetails& details) override { |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 118 | DCHECK(type == chrome::NOTIFICATION_SESSION_STARTED); |
[email protected] | 2fda997 | 2014-07-23 14:51:59 | [diff] [blame] | 119 | DCHECK(content::Details<const user_manager::User>(details).ptr() == |
[email protected] | 052e3ac | 2014-06-30 14:22:47 | [diff] [blame] | 120 | ProfileHelper::Get()->GetUserByProfile(profile_)); |
updowndota | ec498067 | 2017-06-08 02:11:14 | [diff] [blame] | 121 | |
Yue Li | 3a60834 | 2017-08-09 06:03:46 | [diff] [blame] | 122 | // Whether the account is supported for voice interaction. |
| 123 | bool account_supported = false; |
| 124 | SigninManagerBase* signin_manager = |
| 125 | SigninManagerFactory::GetForProfile(profile_); |
| 126 | if (signin_manager) { |
| 127 | std::string hosted_domain = |
| 128 | signin_manager->GetAuthenticatedAccountInfo().hosted_domain; |
| 129 | if (hosted_domain == AccountTrackerService::kNoHostedDomainFound || |
| 130 | hosted_domain == "google.com") |
| 131 | account_supported = true; |
| 132 | } |
| 133 | |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 134 | // If voice interaction value prop needs to be shown, the tutorial will be |
updowndota | ec498067 | 2017-06-08 02:11:14 | [diff] [blame] | 135 | // shown after the voice interaction OOBE flow. |
Yue Li | 3a60834 | 2017-08-09 06:03:46 | [diff] [blame] | 136 | if (account_supported && arc::IsArcPlayStoreEnabledForProfile(profile_) && |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 137 | !profile_->GetPrefs()->GetBoolean( |
| 138 | prefs::kArcVoiceInteractionValuePropAccepted)) { |
| 139 | auto* service = |
Hidehiko Abe | bac30e6 | 2017-07-18 03:52:58 | [diff] [blame] | 140 | arc::ArcVoiceInteractionFrameworkService::GetForBrowserContext( |
| 141 | profile_); |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 142 | if (service) |
| 143 | service->StartSessionFromUserInteraction(gfx::Rect()); |
| 144 | } else { |
updowndota | ec498067 | 2017-06-08 02:11:14 | [diff] [blame] | 145 | TryLaunchFirstRunDialog(profile_); |
updowndota | 07ecbf2 | 2017-06-28 05:34:06 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 148 | delete this; |
| 149 | } |
| 150 | |
| 151 | private: |
| 152 | Profile* profile_; |
| 153 | content::NotificationRegistrar registrar_; |
| 154 | |
| 155 | DISALLOW_COPY_AND_ASSIGN(DialogLauncher); |
| 156 | }; |
| 157 | |
| 158 | } // namespace |
| 159 | |
| 160 | void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
Sarah Hu | 00eaa5a | 2017-08-14 17:16:13 | [diff] [blame^] | 161 | // This preference used to be syncable, change it to non-syncable so new |
| 162 | // users will always see the welcome app on a new device. |
| 163 | // See crbug.com/752361 |
| 164 | registry->RegisterBooleanPref(prefs::kFirstRunTutorialShown, false); |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void MaybeLaunchDialogAfterSessionStart() { |
[email protected] | 6426834 | 2014-08-12 17:18:22 | [diff] [blame] | 168 | new DialogLauncher(ProfileHelper::Get()->GetProfileByUserUnsafe( |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 169 | user_manager::UserManager::Get()->GetActiveUser())); |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 170 | } |
| 171 | |
muyuanli | c20d3c0 | 2017-05-19 00:39:32 | [diff] [blame] | 172 | void MaybeLaunchDialogImmediately() { |
| 173 | TryLaunchFirstRunDialog(ProfileHelper::Get()->GetProfileByUser( |
| 174 | user_manager::UserManager::Get()->GetActiveUser())); |
| 175 | } |
| 176 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 177 | void LaunchTutorial() { |
[email protected] | 1876f39 | 2014-01-16 16:13:57 | [diff] [blame] | 178 | UMA_HISTOGRAM_BOOLEAN("CrosFirstRun.TutorialLaunched", true); |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 179 | FirstRunController::Start(); |
| 180 | } |
| 181 | |
[email protected] | 980d5f9e | 2013-12-17 17:47:08 | [diff] [blame] | 182 | } // namespace first_run |
[email protected] | 5ee08bf | 2013-11-30 05:25:30 | [diff] [blame] | 183 | } // namespace chromeos |