| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 5 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_auth_context.h" | 19 #include "chrome/browser/chromeos/arc/arc_auth_context.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 20 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 21 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 22 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 22 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 23 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 23 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_negotiator.h" | 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_negotiator.h" |
| 24 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" | 25 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" |
| 25 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" | 26 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 26 #include "chrome/browser/chromeos/login/user_flow.h" | |
| 27 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | |
| 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 29 #include "chrome/browser/lifetime/application_lifetime.h" | 27 #include "chrome/browser/lifetime/application_lifetime.h" |
| 30 #include "chrome/browser/policy/profile_policy_connector.h" | 28 #include "chrome/browser/policy/profile_policy_connector.h" |
| 31 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 29 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 32 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 30 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 32 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 33 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 36 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 34 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 37 #include "chrome/browser/ui/browser_commands.h" | 35 #include "chrome/browser/ui/browser_commands.h" |
| 38 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/grit/generated_resources.h" | 37 #include "chrome/grit/generated_resources.h" |
| 40 #include "chromeos/chromeos_switches.h" | 38 #include "chromeos/chromeos_switches.h" |
| 41 #include "chromeos/cryptohome/cryptohome_parameters.h" | 39 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 42 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
| 43 #include "chromeos/dbus/session_manager_client.h" | 41 #include "chromeos/dbus/session_manager_client.h" |
| 44 #include "components/arc/arc_bridge_service.h" | 42 #include "components/arc/arc_bridge_service.h" |
| 45 #include "components/arc/arc_session_runner.h" | 43 #include "components/arc/arc_session_runner.h" |
| 44 #include "components/arc/arc_util.h" |
| 46 #include "components/pref_registry/pref_registry_syncable.h" | 45 #include "components/pref_registry/pref_registry_syncable.h" |
| 47 #include "components/prefs/pref_service.h" | 46 #include "components/prefs/pref_service.h" |
| 48 #include "components/sync_preferences/pref_service_syncable.h" | 47 #include "components/sync_preferences/pref_service_syncable.h" |
| 49 #include "components/user_manager/user.h" | |
| 50 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 51 #include "extensions/browser/extension_prefs.h" | 49 #include "extensions/browser/extension_prefs.h" |
| 52 | 50 |
| 53 namespace arc { | 51 namespace arc { |
| 54 | 52 |
| 55 namespace { | 53 namespace { |
| 56 | 54 |
| 57 // Weak pointer. This class is owned by ArcServiceManager. | 55 // Weak pointer. This class is owned by ArcServiceManager. |
| 58 ArcSessionManager* g_arc_session_manager = nullptr; | 56 ArcSessionManager* g_arc_session_manager = nullptr; |
| 59 | 57 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 g_disable_ui_for_testing = true; | 127 g_disable_ui_for_testing = true; |
| 130 } | 128 } |
| 131 | 129 |
| 132 // static | 130 // static |
| 133 void ArcSessionManager::SetShelfDelegateForTesting( | 131 void ArcSessionManager::SetShelfDelegateForTesting( |
| 134 ash::ShelfDelegate* shelf_delegate) { | 132 ash::ShelfDelegate* shelf_delegate) { |
| 135 g_shelf_delegate_for_testing = shelf_delegate; | 133 g_shelf_delegate_for_testing = shelf_delegate; |
| 136 } | 134 } |
| 137 | 135 |
| 138 // static | 136 // static |
| 139 bool ArcSessionManager::IsOptInVerificationDisabled() { | |
| 140 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 141 chromeos::switches::kDisableArcOptInVerification); | |
| 142 } | |
| 143 | |
| 144 // static | |
| 145 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { | 137 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
| 146 g_enable_check_android_management_for_testing = true; | 138 g_enable_check_android_management_for_testing = true; |
| 147 } | 139 } |
| 148 | 140 |
| 149 // static | |
| 150 bool ArcSessionManager::IsAllowedForProfile(const Profile* profile) { | |
| 151 if (!ArcBridgeService::GetEnabled(base::CommandLine::ForCurrentProcess())) { | |
| 152 VLOG(1) << "Arc is not enabled."; | |
| 153 return false; | |
| 154 } | |
| 155 | |
| 156 if (!profile) { | |
| 157 VLOG(1) << "ARC is not supported for systems without profile."; | |
| 158 return false; | |
| 159 } | |
| 160 | |
| 161 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile)) { | |
| 162 VLOG(1) << "Non-primary users are not supported in ARC."; | |
| 163 return false; | |
| 164 } | |
| 165 | |
| 166 // IsPrimaryProfile can return true for an incognito profile corresponding | |
| 167 // to the primary profile, but ARC does not support it. | |
| 168 if (profile->IsOffTheRecord()) { | |
| 169 VLOG(1) << "Incognito profile is not supported in ARC."; | |
| 170 return false; | |
| 171 } | |
| 172 | |
| 173 if (profile->IsLegacySupervised()) { | |
| 174 VLOG(1) << "Supervised users are not supported in ARC."; | |
| 175 return false; | |
| 176 } | |
| 177 | |
| 178 user_manager::User const* const user = | |
| 179 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | |
| 180 if ((!user || !user->HasGaiaAccount()) && !IsArcKioskMode()) { | |
| 181 VLOG(1) << "Users without GAIA accounts are not supported in ARC."; | |
| 182 return false; | |
| 183 } | |
| 184 | |
| 185 chromeos::UserFlow* user_flow = | |
| 186 chromeos::ChromeUserManager::Get()->GetUserFlow(user->GetAccountId()); | |
| 187 if (!user_flow || !user_flow->CanStartArc()) { | |
| 188 VLOG(1) << "ARC is not allowed in the current user flow."; | |
| 189 return false; | |
| 190 } | |
| 191 | |
| 192 if (user_manager::UserManager::Get() | |
| 193 ->IsCurrentUserCryptohomeDataEphemeral()) { | |
| 194 VLOG(2) << "Users with ephemeral data are not supported in Arc."; | |
| 195 return false; | |
| 196 } | |
| 197 | |
| 198 return true; | |
| 199 } | |
| 200 | |
| 201 // static | |
| 202 bool ArcSessionManager::IsArcKioskMode() { | |
| 203 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); | |
| 204 } | |
| 205 | |
| 206 void ArcSessionManager::OnSessionReady() { | 141 void ArcSessionManager::OnSessionReady() { |
| 207 for (auto& observer : arc_session_observer_list_) | 142 for (auto& observer : arc_session_observer_list_) |
| 208 observer.OnSessionReady(); | 143 observer.OnSessionReady(); |
| 209 } | 144 } |
| 210 | 145 |
| 211 void ArcSessionManager::OnSessionStopped(StopReason reason) { | 146 void ArcSessionManager::OnSessionStopped(StopReason reason) { |
| 212 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 147 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 213 if (arc_sign_in_timer_.IsRunning()) | 148 if (arc_sign_in_timer_.IsRunning()) |
| 214 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 149 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
| 215 | 150 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 DCHECK_NE(result, ProvisioningResult::SUCCESS); | 246 DCHECK_NE(result, ProvisioningResult::SUCCESS); |
| 312 // TODO (khmel): Consider changing LOG to NOTREACHED once we guaranty that | 247 // TODO (khmel): Consider changing LOG to NOTREACHED once we guaranty that |
| 313 // no double message can happen in production. | 248 // no double message can happen in production. |
| 314 LOG(WARNING) << "Provisioning result was already reported. Ignoring " | 249 LOG(WARNING) << "Provisioning result was already reported. Ignoring " |
| 315 << "additional result " << static_cast<int>(result) << "."; | 250 << "additional result " << static_cast<int>(result) << "."; |
| 316 return; | 251 return; |
| 317 } | 252 } |
| 318 provisioning_reported_ = true; | 253 provisioning_reported_ = true; |
| 319 | 254 |
| 320 if (result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { | 255 if (result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { |
| 321 if (IsArcKioskMode()) { | 256 if (util::IsArcKioskMode()) { |
| 322 VLOG(1) << "Robot account auth code fetching error"; | 257 VLOG(1) << "Robot account auth code fetching error"; |
| 323 // Log out the user. All the cleanup will be done in Shutdown() method. | 258 // Log out the user. All the cleanup will be done in Shutdown() method. |
| 324 // The callback is not called because auth code is empty. | 259 // The callback is not called because auth code is empty. |
| 325 attempt_user_exit_callback_.Run(); | 260 attempt_user_exit_callback_.Run(); |
| 326 return; | 261 return; |
| 327 } | 262 } |
| 328 | 263 |
| 329 // For backwards compatibility, use NETWORK_ERROR for | 264 // For backwards compatibility, use NETWORK_ERROR for |
| 330 // CHROME_SERVER_COMMUNICATION_ERROR case. | 265 // CHROME_SERVER_COMMUNICATION_ERROR case. |
| 331 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 266 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 344 if (result == ProvisioningResult::SUCCESS) { | 279 if (result == ProvisioningResult::SUCCESS) { |
| 345 if (support_host_) | 280 if (support_host_) |
| 346 support_host_->Close(); | 281 support_host_->Close(); |
| 347 | 282 |
| 348 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) | 283 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) |
| 349 return; | 284 return; |
| 350 | 285 |
| 351 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); | 286 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); |
| 352 // Don't show Play Store app for ARC Kiosk because the only one UI in kiosk | 287 // Don't show Play Store app for ARC Kiosk because the only one UI in kiosk |
| 353 // mode must be the kiosk app and device is not needed for opt-in. | 288 // mode must be the kiosk app and device is not needed for opt-in. |
| 354 if (!IsOptInVerificationDisabled() && !IsArcKioskMode()) { | 289 if (!util::IsOptInVerificationDisabled() && !util::IsArcKioskMode()) { |
| 355 playstore_launcher_.reset( | 290 playstore_launcher_.reset( |
| 356 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); | 291 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); |
| 357 } | 292 } |
| 358 | 293 |
| 359 for (auto& observer : observer_list_) | 294 for (auto& observer : observer_list_) |
| 360 observer.OnArcInitialStart(); | 295 observer.OnArcInitialStart(); |
| 361 return; | 296 return; |
| 362 } | 297 } |
| 363 | 298 |
| 364 ArcSupportHost::Error error; | 299 ArcSupportHost::Error error; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 363 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 429 return profile_ != nullptr; | 364 return profile_ != nullptr; |
| 430 } | 365 } |
| 431 | 366 |
| 432 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { | 367 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { |
| 433 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 368 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 434 DCHECK(profile && profile != profile_); | 369 DCHECK(profile && profile != profile_); |
| 435 | 370 |
| 436 Shutdown(); | 371 Shutdown(); |
| 437 | 372 |
| 438 if (!IsAllowedForProfile(profile)) | 373 if (!util::IsArcAllowedForProfile(profile)) |
| 439 return; | 374 return; |
| 440 | 375 |
| 441 // TODO(khmel): Move this to IsAllowedForProfile. | 376 // TODO(khmel): Move this to IsArcAllowedForProfile. |
| 442 if (policy_util::IsArcDisabledForEnterprise() && | 377 if (policy_util::IsArcDisabledForEnterprise() && |
| 443 policy_util::IsAccountManaged(profile)) { | 378 policy_util::IsAccountManaged(profile)) { |
| 444 VLOG(2) << "Enterprise users are not supported in ARC."; | 379 VLOG(2) << "Enterprise users are not supported in ARC."; |
| 445 return; | 380 return; |
| 446 } | 381 } |
| 447 | 382 |
| 448 profile_ = profile; | 383 profile_ = profile; |
| 449 | 384 |
| 450 // Create the support host at initialization. Note that, practically, | 385 // Create the support host at initialization. Note that, practically, |
| 451 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). | 386 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). |
| 452 // So, it may be better to initialize it lazily. | 387 // So, it may be better to initialize it lazily. |
| 453 // TODO(hidehiko): Revisit to think about lazy initialization. | 388 // TODO(hidehiko): Revisit to think about lazy initialization. |
| 454 // | 389 // |
| 455 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must | 390 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must |
| 456 // be the kiosk app. In case of error the UI will be useless as well, because | 391 // be the kiosk app. In case of error the UI will be useless as well, because |
| 457 // in typical use case there will be no one nearby the kiosk device, who can | 392 // in typical use case there will be no one nearby the kiosk device, who can |
| 458 // do some action to solve the problem be means of UI. | 393 // do some action to solve the problem be means of UI. |
| 459 if (!g_disable_ui_for_testing && !IsOptInVerificationDisabled() && | 394 if (!g_disable_ui_for_testing && !util::IsOptInVerificationDisabled() && |
| 460 !IsArcKioskMode()) { | 395 !util::IsArcKioskMode()) { |
| 461 DCHECK(!support_host_); | 396 DCHECK(!support_host_); |
| 462 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); | 397 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); |
| 463 support_host_->AddObserver(this); | 398 support_host_->AddObserver(this); |
| 464 } | 399 } |
| 465 | 400 |
| 466 DCHECK_EQ(State::NOT_INITIALIZED, state_); | 401 DCHECK_EQ(State::NOT_INITIALIZED, state_); |
| 467 SetState(State::STOPPED); | 402 SetState(State::STOPPED); |
| 468 | 403 |
| 469 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 404 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 470 prefs::kArcEnabled, this); | 405 prefs::kArcEnabled, this); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 reenable_arc_ = true; | 537 reenable_arc_ = true; |
| 603 return; | 538 return; |
| 604 } | 539 } |
| 605 | 540 |
| 606 if (support_host_) | 541 if (support_host_) |
| 607 support_host_->SetArcManaged(IsArcManaged()); | 542 support_host_->SetArcManaged(IsArcManaged()); |
| 608 | 543 |
| 609 // For ARC Kiosk we skip ToS because it is very likely that near the device | 544 // For ARC Kiosk we skip ToS because it is very likely that near the device |
| 610 // there will be no one who is eligible to accept them. | 545 // there will be no one who is eligible to accept them. |
| 611 // TODO(poromov): Move to more Kiosk dedicated set-up phase. | 546 // TODO(poromov): Move to more Kiosk dedicated set-up phase. |
| 612 if (IsArcKioskMode()) | 547 if (util::IsArcKioskMode()) |
| 613 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 548 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
| 614 | 549 |
| 615 // If it is marked that sign in has been successfully done, then directly | 550 // If it is marked that sign in has been successfully done, then directly |
| 616 // start ARC. | 551 // start ARC. |
| 617 // For testing, and for Kisok mode, we also skip ToS negotiation procedure. | 552 // For testing, and for Kisok mode, we also skip ToS negotiation procedure. |
| 618 // For backward compatibility, this check needs to be prior to the | 553 // For backward compatibility, this check needs to be prior to the |
| 619 // kArcTermsAccepted check below. | 554 // kArcTermsAccepted check below. |
| 620 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || | 555 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || |
| 621 IsOptInVerificationDisabled() || IsArcKioskMode()) { | 556 util::IsOptInVerificationDisabled() || util::IsArcKioskMode()) { |
| 622 StartArc(); | 557 StartArc(); |
| 623 | 558 |
| 624 // Skip Android management check for testing. | 559 // Skip Android management check for testing. |
| 625 // We also skip if Android management check for Kiosk mode, | 560 // We also skip if Android management check for Kiosk mode, |
| 626 // because there are no managed human users for Kiosk exist. | 561 // because there are no managed human users for Kiosk exist. |
| 627 if (IsOptInVerificationDisabled() || IsArcKioskMode() || | 562 if (util::IsOptInVerificationDisabled() || util::IsArcKioskMode() || |
| 628 (g_disable_ui_for_testing && | 563 (g_disable_ui_for_testing && |
| 629 !g_enable_check_android_management_for_testing)) { | 564 !g_enable_check_android_management_for_testing)) { |
| 630 return; | 565 return; |
| 631 } | 566 } |
| 632 | 567 |
| 633 // Check Android management in parallel. | 568 // Check Android management in parallel. |
| 634 // Note: Because the callback may be called in synchronous way (i.e. called | 569 // Note: Because the callback may be called in synchronous way (i.e. called |
| 635 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 570 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
| 636 // Otherwise, DisableArc() which may be called in | 571 // Otherwise, DisableArc() which may be called in |
| 637 // OnBackgroundAndroidManagementChecked() could be ignored. | 572 // OnBackgroundAndroidManagementChecked() could be ignored. |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 return os << "ACTIVE"; | 941 return os << "ACTIVE"; |
| 1007 } | 942 } |
| 1008 | 943 |
| 1009 // Some compiler reports an error even if all values of an enum-class are | 944 // Some compiler reports an error even if all values of an enum-class are |
| 1010 // covered indivisually in a switch statement. | 945 // covered indivisually in a switch statement. |
| 1011 NOTREACHED(); | 946 NOTREACHED(); |
| 1012 return os; | 947 return os; |
| 1013 } | 948 } |
| 1014 | 949 |
| 1015 } // namespace arc | 950 } // namespace arc |
| OLD | NEW |