Chromium Code Reviews| 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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 33 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 34 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 34 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 35 #include "chrome/browser/ui/browser_commands.h" | 35 #include "chrome/browser/ui/browser_commands.h" |
| 36 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 37 #include "chrome/grit/generated_resources.h" | 37 #include "chrome/grit/generated_resources.h" |
| 38 #include "chromeos/chromeos_switches.h" | 38 #include "chromeos/chromeos_switches.h" |
| 39 #include "chromeos/cryptohome/cryptohome_parameters.h" | 39 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 40 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
| 41 #include "chromeos/dbus/session_manager_client.h" | 41 #include "chromeos/dbus/session_manager_client.h" |
| 42 #include "components/arc/arc_bridge_service.h" | 42 #include "components/arc/arc_bridge_service.h" |
| 43 #include "components/arc/arc_session_runner.h" | |
| 43 #include "components/pref_registry/pref_registry_syncable.h" | 44 #include "components/pref_registry/pref_registry_syncable.h" |
| 44 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 45 #include "components/sync_preferences/pref_service_syncable.h" | 46 #include "components/sync_preferences/pref_service_syncable.h" |
| 46 #include "components/user_manager/user.h" | 47 #include "components/user_manager/user.h" |
| 47 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 48 #include "extensions/browser/extension_prefs.h" | 49 #include "extensions/browser/extension_prefs.h" |
| 49 | 50 |
| 50 namespace arc { | 51 namespace arc { |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 74 return g_shelf_delegate_for_testing; | 75 return g_shelf_delegate_for_testing; |
| 75 if (ash::WmShell::HasInstance()) { | 76 if (ash::WmShell::HasInstance()) { |
| 76 DCHECK(ash::WmShell::Get()->shelf_delegate()); | 77 DCHECK(ash::WmShell::Get()->shelf_delegate()); |
| 77 return ash::WmShell::Get()->shelf_delegate(); | 78 return ash::WmShell::Get()->shelf_delegate(); |
| 78 } | 79 } |
| 79 return nullptr; | 80 return nullptr; |
| 80 } | 81 } |
| 81 | 82 |
| 82 } // namespace | 83 } // namespace |
| 83 | 84 |
| 84 ArcSessionManager::ArcSessionManager(ArcBridgeService* bridge_service) | 85 ArcSessionManager::ArcSessionManager( |
| 85 : ArcService(bridge_service), | 86 std::unique_ptr<ArcSessionRunner> arc_session_runner) |
| 87 : arc_session_runner_(std::move(arc_session_runner)), | |
| 86 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), | 88 attempt_user_exit_callback_(base::Bind(chrome::AttemptUserExit)), |
| 87 weak_ptr_factory_(this) { | 89 weak_ptr_factory_(this) { |
| 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 90 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 89 DCHECK(!g_arc_session_manager); | 91 DCHECK(!g_arc_session_manager); |
| 90 g_arc_session_manager = this; | 92 g_arc_session_manager = this; |
| 91 | 93 arc_session_runner_->AddObserver(this); |
| 92 arc_bridge_service()->AddObserver(this); | |
| 93 } | 94 } |
| 94 | 95 |
| 95 ArcSessionManager::~ArcSessionManager() { | 96 ArcSessionManager::~ArcSessionManager() { |
| 96 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 97 | 98 |
| 98 Shutdown(); | 99 Shutdown(); |
| 99 arc_bridge_service()->RemoveObserver(this); | 100 arc_session_runner_->RemoveObserver(this); |
| 100 | 101 |
| 101 DCHECK_EQ(this, g_arc_session_manager); | 102 DCHECK_EQ(this, g_arc_session_manager); |
| 102 g_arc_session_manager = nullptr; | 103 g_arc_session_manager = nullptr; |
| 103 } | 104 } |
| 104 | 105 |
| 105 // static | 106 // static |
| 106 ArcSessionManager* ArcSessionManager::Get() { | 107 ArcSessionManager* ArcSessionManager::Get() { |
| 107 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 108 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 108 return g_arc_session_manager; | 109 return g_arc_session_manager; |
| 109 } | 110 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 } | 187 } |
| 187 | 188 |
| 188 return true; | 189 return true; |
| 189 } | 190 } |
| 190 | 191 |
| 191 // static | 192 // static |
| 192 bool ArcSessionManager::IsArcKioskMode() { | 193 bool ArcSessionManager::IsArcKioskMode() { |
| 193 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); | 194 return user_manager::UserManager::Get()->IsLoggedInAsArcKioskApp(); |
| 194 } | 195 } |
| 195 | 196 |
| 197 void ArcSessionManager::OnSessionReady() { | |
| 198 for (auto& observer : arc_session_observer_list_) | |
| 199 observer.OnSessionReady(); | |
| 200 } | |
| 201 | |
| 196 void ArcSessionManager::OnSessionStopped(StopReason reason) { | 202 void ArcSessionManager::OnSessionStopped(StopReason reason) { |
| 197 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. | 203 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. |
| 198 if (arc_sign_in_timer_.IsRunning()) | 204 if (arc_sign_in_timer_.IsRunning()) |
| 199 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); | 205 OnProvisioningFinished(ProvisioningResult::ARC_STOPPED); |
| 200 | 206 |
| 201 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 207 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 202 // This should be always true, but just in case as this is looked at | 208 // This should be always true, but just in case as this is looked at |
| 203 // inside RemoveArcData() at first. | 209 // inside RemoveArcData() at first. |
| 204 DCHECK(arc_bridge_service()->stopped()); | 210 DCHECK(arc_session_runner_->IsStopped()); |
| 205 RemoveArcData(); | 211 RemoveArcData(); |
| 206 } else { | 212 } else { |
| 207 // To support special "Stop and enable ARC" procedure for enterprise, | 213 // To support special "Stop and enable ARC" procedure for enterprise, |
| 208 // here call MaybeReenableArc() asyncronously. | 214 // here call MaybeReenableArc() asyncronously. |
| 209 // TODO(hidehiko): Restructure the code. crbug.com/665316 | 215 // TODO(hidehiko): Restructure the code. crbug.com/665316 |
| 210 base::ThreadTaskRunnerHandle::Get()->PostTask( | 216 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 211 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, | 217 FROM_HERE, base::Bind(&ArcSessionManager::MaybeReenableArc, |
| 212 weak_ptr_factory_.GetWeakPtr())); | 218 weak_ptr_factory_.GetWeakPtr())); |
| 213 } | 219 } |
| 220 | |
| 221 for (auto& observer : arc_session_observer_list_) | |
| 222 observer.OnSessionStopped(reason); | |
| 214 } | 223 } |
| 215 | 224 |
| 216 void ArcSessionManager::RemoveArcData() { | 225 void ArcSessionManager::RemoveArcData() { |
| 217 // Ignore redundant data removal request. | 226 // Ignore redundant data removal request. |
| 218 if (state() == State::REMOVING_DATA_DIR) | 227 if (state() == State::REMOVING_DATA_DIR) |
| 219 return; | 228 return; |
| 220 | 229 |
| 221 // OnArcDataRemoved resets this flag. | 230 // OnArcDataRemoved resets this flag. |
| 222 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); | 231 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, true); |
| 223 | 232 |
| 224 if (!arc_bridge_service()->stopped()) { | 233 if (!arc_session_runner_->IsStopped()) { |
| 225 // Just set a flag. On bridge stopped, this will be re-called, | 234 // Just set a flag. On session stopped, this will be re-called, |
| 226 // then session manager should remove the data. | 235 // then session manager should remove the data. |
| 227 return; | 236 return; |
| 228 } | 237 } |
| 229 | 238 |
| 230 SetState(State::REMOVING_DATA_DIR); | 239 SetState(State::REMOVING_DATA_DIR); |
| 231 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 240 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
| 232 cryptohome::Identification( | 241 cryptohome::Identification( |
| 233 multi_user_util::GetAccountIdFromProfile(profile_)), | 242 multi_user_util::GetAccountIdFromProfile(profile_)), |
| 234 base::Bind(&ArcSessionManager::OnArcDataRemoved, | 243 base::Bind(&ArcSessionManager::OnArcDataRemoved, |
| 235 weak_ptr_factory_.GetWeakPtr())); | 244 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 249 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); | 258 profile_->GetPrefs()->SetBoolean(prefs::kArcDataRemoveRequested, false); |
| 250 DCHECK_EQ(state(), State::REMOVING_DATA_DIR); | 259 DCHECK_EQ(state(), State::REMOVING_DATA_DIR); |
| 251 SetState(State::STOPPED); | 260 SetState(State::STOPPED); |
| 252 | 261 |
| 253 MaybeReenableArc(); | 262 MaybeReenableArc(); |
| 254 } | 263 } |
| 255 | 264 |
| 256 void ArcSessionManager::MaybeReenableArc() { | 265 void ArcSessionManager::MaybeReenableArc() { |
| 257 // Here check if |reenable_arc_| is marked or not. | 266 // Here check if |reenable_arc_| is marked or not. |
| 258 // The only case this happens should be in the special case for enterprise | 267 // The only case this happens should be in the special case for enterprise |
| 259 // "on managed lost" case. In that case, OnBridgeStopped() should trigger | 268 // "on managed lost" case. In that case, OnSessionStopped() should trigger |
| 260 // the RemoveArcData(), then this. | 269 // the RemoveArcData(), then this. |
| 261 if (!reenable_arc_ || !IsArcEnabled()) | 270 if (!reenable_arc_ || !IsArcEnabled()) |
| 262 return; | 271 return; |
| 263 | 272 |
| 264 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 273 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 265 // the ARC user data wipe is still required or not. | 274 // the ARC user data wipe is still required or not. |
| 266 reenable_arc_ = false; | 275 reenable_arc_ = false; |
| 267 VLOG(1) << "Reenable ARC"; | 276 VLOG(1) << "Reenable ARC"; |
| 268 EnableArc(); | 277 EnableArc(); |
| 269 } | 278 } |
| 270 | 279 |
| 271 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { | 280 void ArcSessionManager::OnProvisioningFinished(ProvisioningResult result) { |
| 272 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 281 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 273 | 282 |
| 274 // Due asynchronous nature of stopping Arc bridge, OnProvisioningFinished may | 283 // Due asynchronous nature of stopping ARC instance, OnProvisioningFinished |
|
Luis Héctor Chávez
2016/12/22 18:29:56
nit: the ARC instance
hidehiko
2016/12/22 19:04:12
Done.
| |
| 275 // arrive after setting the |State::STOPPED| state and |State::Active| is not | 284 // may arrive after setting the |State::STOPPED| state and |State::Active| |
| 276 // guaranty set here. prefs::kArcDataRemoveRequested is also can be active | 285 // is not guaranty set here. prefs::kArcDataRemoveRequested is also can be |
|
Luis Héctor Chávez
2016/12/22 18:29:56
nit: s/guaranty/guaranteed to be/;s/is also can be
hidehiko
2016/12/22 19:04:12
Done.
| |
| 277 // for now. | 286 // active for now. |
| 278 | 287 |
| 279 if (provisioning_reported_) { | 288 if (provisioning_reported_) { |
| 280 // We don't expect ProvisioningResult::SUCCESS is reported twice or reported | 289 // We don't expect ProvisioningResult::SUCCESS is reported twice or reported |
| 281 // after an error. | 290 // after an error. |
| 282 DCHECK_NE(result, ProvisioningResult::SUCCESS); | 291 DCHECK_NE(result, ProvisioningResult::SUCCESS); |
| 283 // TODO (khmel): Consider changing LOG to NOTREACHED once we guaranty that | 292 // TODO (khmel): Consider changing LOG to NOTREACHED once we guaranty that |
| 284 // no double message can happen in production. | 293 // no double message can happen in production. |
| 285 LOG(WARNING) << " Provisioning result was already reported. Ignoring " | 294 LOG(WARNING) << " Provisioning result was already reported. Ignoring " |
| 286 << " additional result " << static_cast<int>(result) << "."; | 295 << " additional result " << static_cast<int>(result) << "."; |
| 287 return; | 296 return; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 break; | 370 break; |
| 362 default: | 371 default: |
| 363 error = ArcSupportHost::Error::SIGN_IN_UNKNOWN_ERROR; | 372 error = ArcSupportHost::Error::SIGN_IN_UNKNOWN_ERROR; |
| 364 break; | 373 break; |
| 365 } | 374 } |
| 366 | 375 |
| 367 if (result == ProvisioningResult::ARC_STOPPED || | 376 if (result == ProvisioningResult::ARC_STOPPED || |
| 368 result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { | 377 result == ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR) { |
| 369 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) | 378 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcSignedIn)) |
| 370 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 379 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 371 ShutdownBridge(); | 380 ShutdownSession(); |
| 372 if (support_host_) | 381 if (support_host_) |
| 373 support_host_->ShowError(error, false); | 382 support_host_->ShowError(error, false); |
| 374 return; | 383 return; |
| 375 } | 384 } |
| 376 | 385 |
| 377 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || | 386 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || |
| 378 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || | 387 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || |
| 379 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || | 388 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || |
| 380 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is | 389 // OVERALL_SIGN_IN_TIMEOUT might be an indication that ARC believes it is |
| 381 // fully setup, but Chrome does not. | 390 // fully setup, but Chrome does not. |
| 382 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || | 391 result == ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT || |
| 383 // Just to be safe, remove data if we don't know the cause. | 392 // Just to be safe, remove data if we don't know the cause. |
| 384 result == ProvisioningResult::UNKNOWN_ERROR) { | 393 result == ProvisioningResult::UNKNOWN_ERROR) { |
| 385 RemoveArcData(); | 394 RemoveArcData(); |
| 386 } | 395 } |
| 387 | 396 |
| 388 // We'll delay shutting down the bridge in this case to allow people to send | 397 // We'll delay shutting down the ARC instance in this case to allow people |
| 389 // feedback. | 398 // to send feedback. |
| 390 if (support_host_) | 399 if (support_host_) |
| 391 support_host_->ShowError(error, true /* = show send feedback button */); | 400 support_host_->ShowError(error, true /* = show send feedback button */); |
| 392 } | 401 } |
| 393 | 402 |
| 394 void ArcSessionManager::SetState(State state) { | 403 void ArcSessionManager::SetState(State state) { |
| 395 state_ = state; | 404 state_ = state; |
| 396 } | 405 } |
| 397 | 406 |
| 398 bool ArcSessionManager::IsAllowed() const { | 407 bool ArcSessionManager::IsAllowed() const { |
| 399 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 408 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 profile_->IsNewProfile() && | 493 profile_->IsNewProfile() && |
| 485 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 494 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
| 486 ArcAuthNotification::Show(profile_); | 495 ArcAuthNotification::Show(profile_); |
| 487 } | 496 } |
| 488 } | 497 } |
| 489 | 498 |
| 490 void ArcSessionManager::Shutdown() { | 499 void ArcSessionManager::Shutdown() { |
| 491 if (!g_disable_ui_for_testing) | 500 if (!g_disable_ui_for_testing) |
| 492 ArcAuthNotification::Hide(); | 501 ArcAuthNotification::Hide(); |
| 493 | 502 |
| 494 ShutdownBridge(); | 503 ShutdownSession(); |
| 495 if (support_host_) { | 504 if (support_host_) { |
| 496 support_host_->Close(); | 505 support_host_->Close(); |
| 497 support_host_->RemoveObserver(this); | 506 support_host_->RemoveObserver(this); |
| 498 support_host_.reset(); | 507 support_host_.reset(); |
| 499 } | 508 } |
| 500 if (profile_) { | 509 if (profile_) { |
| 501 sync_preferences::PrefServiceSyncable* pref_service_syncable = | 510 sync_preferences::PrefServiceSyncable* pref_service_syncable = |
| 502 PrefServiceSyncableFromProfile(profile_); | 511 PrefServiceSyncableFromProfile(profile_); |
| 503 pref_service_syncable->RemoveObserver(this); | 512 pref_service_syncable->RemoveObserver(this); |
| 504 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); | 513 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 526 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | 535 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); |
| 527 } | 536 } |
| 528 } | 537 } |
| 529 } | 538 } |
| 530 | 539 |
| 531 void ArcSessionManager::StopArc() { | 540 void ArcSessionManager::StopArc() { |
| 532 if (state_ != State::STOPPED) { | 541 if (state_ != State::STOPPED) { |
| 533 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 542 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 534 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); | 543 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); |
| 535 } | 544 } |
| 536 ShutdownBridge(); | 545 ShutdownSession(); |
| 537 if (support_host_) | 546 if (support_host_) |
| 538 support_host_->Close(); | 547 support_host_->Close(); |
| 539 } | 548 } |
| 540 | 549 |
| 541 void ArcSessionManager::OnOptInPreferenceChanged() { | 550 void ArcSessionManager::OnOptInPreferenceChanged() { |
| 542 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 551 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 543 DCHECK(profile_); | 552 DCHECK(profile_); |
| 544 | 553 |
| 545 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. | 554 // TODO(dspaid): Move code from OnSyncedPrefChanged into this method. |
| 546 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); | 555 OnSyncedPrefChanged(prefs::kArcEnabled, IsArcManaged()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 634 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 626 support_host_->ShowArcLoading(); | 635 support_host_->ShowArcLoading(); |
| 627 StartArcAndroidManagementCheck(); | 636 StartArcAndroidManagementCheck(); |
| 628 return; | 637 return; |
| 629 } | 638 } |
| 630 | 639 |
| 631 // Need user's explicit Terms Of Service agreement. | 640 // Need user's explicit Terms Of Service agreement. |
| 632 StartTermsOfServiceNegotiation(); | 641 StartTermsOfServiceNegotiation(); |
| 633 } | 642 } |
| 634 | 643 |
| 635 void ArcSessionManager::ShutdownBridge() { | 644 void ArcSessionManager::ShutdownSession() { |
| 636 arc_sign_in_timer_.Stop(); | 645 arc_sign_in_timer_.Stop(); |
| 637 playstore_launcher_.reset(); | 646 playstore_launcher_.reset(); |
| 638 terms_of_service_negotiator_.reset(); | 647 terms_of_service_negotiator_.reset(); |
| 639 android_management_checker_.reset(); | 648 android_management_checker_.reset(); |
| 640 arc_bridge_service()->RequestStop(); | 649 arc_session_runner_->RequestStop(); |
| 650 // TODO(hidehiko): Actual ARC instance stop will be delayed, and until | |
| 651 // it's completed, ARC instance is still running. Do not set the state | |
| 652 // STOPPED immediately here. | |
|
Luis Héctor Chávez
2016/12/22 18:29:56
just curious: is the plan to delete IsSessionStopp
hidehiko
2016/12/22 19:04:12
TBD. Currently, IsSessionStopped()/Running() is ju
| |
| 641 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) | 653 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) |
| 642 SetState(State::STOPPED); | 654 SetState(State::STOPPED); |
| 643 for (auto& observer : observer_list_) | 655 for (auto& observer : observer_list_) |
| 644 observer.OnArcBridgeShutdown(); | 656 observer.OnArcBridgeShutdown(); |
| 645 } | 657 } |
| 646 | 658 |
| 647 void ArcSessionManager::AddObserver(Observer* observer) { | 659 void ArcSessionManager::AddObserver(Observer* observer) { |
| 648 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 660 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 649 observer_list_.AddObserver(observer); | 661 observer_list_.AddObserver(observer); |
| 650 } | 662 } |
| 651 | 663 |
| 652 void ArcSessionManager::RemoveObserver(Observer* observer) { | 664 void ArcSessionManager::RemoveObserver(Observer* observer) { |
| 653 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 665 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 654 observer_list_.RemoveObserver(observer); | 666 observer_list_.RemoveObserver(observer); |
| 655 } | 667 } |
| 656 | 668 |
| 669 void ArcSessionManager::AddSessionObserver(ArcSessionObserver* observer) { | |
| 670 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 671 arc_session_observer_list_.AddObserver(observer); | |
| 672 } | |
| 673 | |
| 674 void ArcSessionManager::RemoveSessionObserver(ArcSessionObserver* observer) { | |
| 675 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 676 arc_session_observer_list_.RemoveObserver(observer); | |
| 677 } | |
| 678 | |
| 679 bool ArcSessionManager::IsSessionRunning() const { | |
| 680 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 681 return arc_session_runner_->IsRunning(); | |
| 682 } | |
| 683 | |
| 684 bool ArcSessionManager::IsSessionStopped() const { | |
| 685 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 686 return arc_session_runner_->IsStopped(); | |
| 687 } | |
| 688 | |
| 657 // This is the special method to support enterprise mojo API. | 689 // This is the special method to support enterprise mojo API. |
| 658 // TODO(hidehiko): Remove this. | 690 // TODO(hidehiko): Remove this. |
| 659 void ArcSessionManager::StopAndEnableArc() { | 691 void ArcSessionManager::StopAndEnableArc() { |
| 660 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 692 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 661 DCHECK(!arc_bridge_service()->stopped()); | 693 DCHECK(!arc_session_runner_->IsStopped()); |
| 662 reenable_arc_ = true; | 694 reenable_arc_ = true; |
| 663 StopArc(); | 695 StopArc(); |
| 664 } | 696 } |
| 665 | 697 |
| 666 void ArcSessionManager::StartArc() { | 698 void ArcSessionManager::StartArc() { |
| 667 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 699 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 668 | 700 |
| 669 // Arc must be started only if no pending data removal request exists. | 701 // Arc must be started only if no pending data removal request exists. |
| 670 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | 702 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); |
| 671 | 703 |
| 672 provisioning_reported_ = false; | 704 provisioning_reported_ = false; |
| 673 | 705 |
| 674 arc_bridge_service()->RequestStart(); | 706 arc_session_runner_->RequestStart(); |
| 675 SetState(State::ACTIVE); | 707 SetState(State::ACTIVE); |
| 676 } | 708 } |
| 677 | 709 |
| 678 void ArcSessionManager::OnArcSignInTimeout() { | 710 void ArcSessionManager::OnArcSignInTimeout() { |
| 679 LOG(ERROR) << "Timed out waiting for first sign in."; | 711 LOG(ERROR) << "Timed out waiting for first sign in."; |
| 680 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); | 712 OnProvisioningFinished(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); |
| 681 } | 713 } |
| 682 | 714 |
| 683 void ArcSessionManager::CancelAuthCode() { | 715 void ArcSessionManager::CancelAuthCode() { |
| 684 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 716 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 751 // Only record Enabled state if ARC is allowed in the first place, so we do | 783 // Only record Enabled state if ARC is allowed in the first place, so we do |
| 752 // not split the ARC population by devices that cannot run ARC. | 784 // not split the ARC population by devices that cannot run ARC. |
| 753 if (IsAllowed()) | 785 if (IsAllowed()) |
| 754 UpdateEnabledStateUMA(IsArcEnabled()); | 786 UpdateEnabledStateUMA(IsArcEnabled()); |
| 755 } | 787 } |
| 756 | 788 |
| 757 void ArcSessionManager::StartTermsOfServiceNegotiation() { | 789 void ArcSessionManager::StartTermsOfServiceNegotiation() { |
| 758 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 790 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 759 DCHECK(!terms_of_service_negotiator_); | 791 DCHECK(!terms_of_service_negotiator_); |
| 760 | 792 |
| 761 if (!arc_bridge_service()->stopped()) { | 793 if (!arc_session_runner_->IsStopped()) { |
| 762 // If the user attempts to re-enable ARC while the bridge is still running | 794 // If the user attempts to re-enable ARC while ARC instance is still |
|
Luis Héctor Chávez
2016/12/22 18:29:56
nit: the ARC instance. same below.
hidehiko
2016/12/22 19:04:12
Done.
| |
| 763 // the user should not be able to continue until the bridge has stopped. | 795 // running the user should not be able to continue until ARC instance has |
| 796 // stopped. | |
| 764 if (support_host_) { | 797 if (support_host_) { |
| 765 support_host_->ShowError( | 798 support_host_->ShowError( |
| 766 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | 799 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
| 767 } | 800 } |
| 768 return; | 801 return; |
| 769 } | 802 } |
| 770 | 803 |
| 771 SetState(State::SHOWING_TERMS_OF_SERVICE); | 804 SetState(State::SHOWING_TERMS_OF_SERVICE); |
| 772 if (support_host_) { | 805 if (support_host_) { |
| 773 terms_of_service_negotiator_ = | 806 terms_of_service_negotiator_ = |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 792 | 825 |
| 793 // Terms were accepted. | 826 // Terms were accepted. |
| 794 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | 827 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); |
| 795 | 828 |
| 796 support_host_->ShowArcLoading(); | 829 support_host_->ShowArcLoading(); |
| 797 StartArcAndroidManagementCheck(); | 830 StartArcAndroidManagementCheck(); |
| 798 } | 831 } |
| 799 | 832 |
| 800 void ArcSessionManager::StartArcAndroidManagementCheck() { | 833 void ArcSessionManager::StartArcAndroidManagementCheck() { |
| 801 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 834 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 802 DCHECK(arc_bridge_service()->stopped()); | 835 DCHECK(arc_session_runner_->IsStopped()); |
| 803 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || | 836 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || |
| 804 state_ == State::CHECKING_ANDROID_MANAGEMENT); | 837 state_ == State::CHECKING_ANDROID_MANAGEMENT); |
| 805 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 838 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 806 | 839 |
| 807 android_management_checker_.reset(new ArcAndroidManagementChecker( | 840 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 808 profile_, context_->token_service(), context_->account_id(), | 841 profile_, context_->token_service(), context_->account_id(), |
| 809 false /* retry_on_error */)); | 842 false /* retry_on_error */)); |
| 810 android_management_checker_->StartCheck( | 843 android_management_checker_->StartCheck( |
| 811 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, | 844 base::Bind(&ArcSessionManager::OnAndroidManagementChecked, |
| 812 weak_ptr_factory_.GetWeakPtr())); | 845 weak_ptr_factory_.GetWeakPtr())); |
| 813 } | 846 } |
| 814 | 847 |
| 815 void ArcSessionManager::OnAndroidManagementChecked( | 848 void ArcSessionManager::OnAndroidManagementChecked( |
| 816 policy::AndroidManagementClient::Result result) { | 849 policy::AndroidManagementClient::Result result) { |
| 817 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 850 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 818 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); | 851 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); |
| 819 | 852 |
| 820 switch (result) { | 853 switch (result) { |
| 821 case policy::AndroidManagementClient::Result::UNMANAGED: | 854 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 822 VLOG(1) << "Starting ARC for first sign in."; | 855 VLOG(1) << "Starting ARC for first sign in."; |
| 823 sign_in_time_ = base::Time::Now(); | 856 sign_in_time_ = base::Time::Now(); |
| 824 arc_sign_in_timer_.Start( | 857 arc_sign_in_timer_.Start( |
| 825 FROM_HERE, kArcSignInTimeout, | 858 FROM_HERE, kArcSignInTimeout, |
| 826 base::Bind(&ArcSessionManager::OnArcSignInTimeout, | 859 base::Bind(&ArcSessionManager::OnArcSignInTimeout, |
| 827 weak_ptr_factory_.GetWeakPtr())); | 860 weak_ptr_factory_.GetWeakPtr())); |
| 828 StartArc(); | 861 StartArc(); |
| 829 break; | 862 break; |
| 830 case policy::AndroidManagementClient::Result::MANAGED: | 863 case policy::AndroidManagementClient::Result::MANAGED: |
| 831 ShutdownBridge(); | 864 ShutdownSession(); |
| 832 if (support_host_) { | 865 if (support_host_) { |
| 833 support_host_->ShowError( | 866 support_host_->ShowError( |
| 834 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); | 867 ArcSupportHost::Error::ANDROID_MANAGEMENT_REQUIRED_ERROR, false); |
| 835 } | 868 } |
| 836 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 869 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 837 break; | 870 break; |
| 838 case policy::AndroidManagementClient::Result::ERROR: | 871 case policy::AndroidManagementClient::Result::ERROR: |
| 839 ShutdownBridge(); | 872 ShutdownSession(); |
| 840 if (support_host_) { | 873 if (support_host_) { |
| 841 support_host_->ShowError( | 874 support_host_->ShowError( |
| 842 ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, false); | 875 ArcSupportHost::Error::SERVER_COMMUNICATION_ERROR, false); |
| 843 } | 876 } |
| 844 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 877 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 845 break; | 878 break; |
| 846 } | 879 } |
| 847 } | 880 } |
| 848 | 881 |
| 849 void ArcSessionManager::OnBackgroundAndroidManagementChecked( | 882 void ArcSessionManager::OnBackgroundAndroidManagementChecked( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 886 | 919 |
| 887 UpdateOptInActionUMA(OptInActionType::RETRY); | 920 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 888 | 921 |
| 889 // TODO(hidehiko): Simplify the retry logic. | 922 // TODO(hidehiko): Simplify the retry logic. |
| 890 if (terms_of_service_negotiator_) { | 923 if (terms_of_service_negotiator_) { |
| 891 // Currently Terms of service is shown. ArcTermsOfServiceNegotiator should | 924 // Currently Terms of service is shown. ArcTermsOfServiceNegotiator should |
| 892 // handle this. | 925 // handle this. |
| 893 } else if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 926 } else if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 894 StartTermsOfServiceNegotiation(); | 927 StartTermsOfServiceNegotiation(); |
| 895 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR && | 928 } else if (support_host_->ui_page() == ArcSupportHost::UIPage::ERROR && |
| 896 !arc_bridge_service()->stopped()) { | 929 !arc_session_runner_->IsStopped()) { |
| 897 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping | 930 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping |
| 898 // ARC was postponed to contain its internal state into the report. | 931 // ARC was postponed to contain its internal state into the report. |
| 899 // Here, on retry, stop it, then restart. | 932 // Here, on retry, stop it, then restart. |
| 900 DCHECK_EQ(State::ACTIVE, state_); | 933 DCHECK_EQ(State::ACTIVE, state_); |
| 901 support_host_->ShowArcLoading(); | 934 support_host_->ShowArcLoading(); |
| 902 ShutdownBridge(); | 935 ShutdownSession(); |
| 903 reenable_arc_ = true; | 936 reenable_arc_ = true; |
| 904 } else if (state_ == State::ACTIVE) { | 937 } else if (state_ == State::ACTIVE) { |
| 905 // This case is handled in ArcAuthService. | 938 // This case is handled in ArcAuthService. |
| 906 // Do nothing. | 939 // Do nothing. |
| 907 } else { | 940 } else { |
| 908 // Otherwise, we restart ARC. Note: this is the first boot case. | 941 // Otherwise, we restart ARC. Note: this is the first boot case. |
| 909 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE | 942 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE |
| 910 // case must hit. | 943 // case must hit. |
| 911 support_host_->ShowArcLoading(); | 944 support_host_->ShowArcLoading(); |
| 912 StartArcAndroidManagementCheck(); | 945 StartArcAndroidManagementCheck(); |
| 913 } | 946 } |
| 914 } | 947 } |
| 915 | 948 |
| 916 void ArcSessionManager::OnSendFeedbackClicked() { | 949 void ArcSessionManager::OnSendFeedbackClicked() { |
| 917 DCHECK(support_host_); | 950 DCHECK(support_host_); |
| 918 chrome::OpenFeedbackDialog(nullptr); | 951 chrome::OpenFeedbackDialog(nullptr); |
| 919 } | 952 } |
| 920 | 953 |
| 954 void ArcSessionManager::SetArcSessionRunnerForTesting( | |
| 955 std::unique_ptr<ArcSessionRunner> arc_session_runner) { | |
| 956 DCHECK(arc_session_runner); | |
| 957 DCHECK(arc_session_runner_); | |
| 958 DCHECK(arc_session_runner_->IsStopped()); | |
| 959 arc_session_runner_->RemoveObserver(this); | |
| 960 arc_session_runner_ = std::move(arc_session_runner); | |
| 961 arc_session_runner_->AddObserver(this); | |
| 962 } | |
| 963 | |
| 921 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( | 964 void ArcSessionManager::SetAttemptUserExitCallbackForTesting( |
| 922 const base::Closure& callback) { | 965 const base::Closure& callback) { |
| 923 DCHECK(!callback.is_null()); | 966 DCHECK(!callback.is_null()); |
| 924 attempt_user_exit_callback_ = callback; | 967 attempt_user_exit_callback_ = callback; |
| 925 } | 968 } |
| 926 | 969 |
| 927 std::ostream& operator<<(std::ostream& os, | 970 std::ostream& operator<<(std::ostream& os, |
| 928 const ArcSessionManager::State& state) { | 971 const ArcSessionManager::State& state) { |
| 929 switch (state) { | 972 switch (state) { |
| 930 case ArcSessionManager::State::NOT_INITIALIZED: | 973 case ArcSessionManager::State::NOT_INITIALIZED: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 941 return os << "ACTIVE"; | 984 return os << "ACTIVE"; |
| 942 } | 985 } |
| 943 | 986 |
| 944 // Some compiler reports an error even if all values of an enum-class are | 987 // Some compiler reports an error even if all values of an enum-class are |
| 945 // covered indivisually in a switch statement. | 988 // covered indivisually in a switch statement. |
| 946 NOTREACHED(); | 989 NOTREACHED(); |
| 947 return os; | 990 return os; |
| 948 } | 991 } |
| 949 | 992 |
| 950 } // namespace arc | 993 } // namespace arc |
| OLD | NEW |