Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager.cc

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

Powered by Google App Engine
This is Rietveld 408576698