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

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

Issue 2708923013: Split ArcSessionManager::OnPrimaryUserProfilePrepared(). (Closed)
Patch Set: rebase Created 3 years, 9 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 379
380 void ArcSessionManager::SetState(State state) { 380 void ArcSessionManager::SetState(State state) {
381 state_ = state; 381 state_ = state;
382 } 382 }
383 383
384 bool ArcSessionManager::IsAllowed() const { 384 bool ArcSessionManager::IsAllowed() const {
385 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 385 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
386 return profile_ != nullptr; 386 return profile_ != nullptr;
387 } 387 }
388 388
389 void ArcSessionManager::OnPrimaryUserProfilePrepared(Profile* profile) { 389 void ArcSessionManager::SetProfile(Profile* profile) {
390 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 390 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
391 DCHECK(profile && profile != profile_); 391 DCHECK(IsArcAllowedForProfile(profile));
392 392
393 // TODO(hidehiko): Remove this condition, and following Shutdown().
394 // Do not expect that SetProfile() is called for various Profile instances.
395 // At the moment, it is used for testing purpose.
396 DCHECK(profile != profile_);
393 Shutdown(); 397 Shutdown();
394 398
395 if (!IsArcAllowedForProfile(profile))
396 return;
397
398 // TODO(khmel): Move this to IsArcAllowedForProfile.
399 if (policy_util::IsArcDisabledForEnterprise() &&
400 policy_util::IsAccountManaged(profile)) {
401 VLOG(2) << "Enterprise users are not supported in ARC.";
402 return;
403 }
404
405 profile_ = profile; 399 profile_ = profile;
406 400
407 // Create the support host at initialization. Note that, practically, 401 // Create the support host at initialization. Note that, practically,
408 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). 402 // ARC support Chrome app is rarely used (only opt-in and re-auth flow).
409 // So, it may be better to initialize it lazily. 403 // So, it may be better to initialize it lazily.
410 // TODO(hidehiko): Revisit to think about lazy initialization. 404 // TODO(hidehiko): Revisit to think about lazy initialization.
411 // 405 //
412 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must 406 // Don't show UI for ARC Kiosk because the only one UI in kiosk mode must
413 // be the kiosk app. In case of error the UI will be useless as well, because 407 // be the kiosk app. In case of error the UI will be useless as well, because
414 // in typical use case there will be no one nearby the kiosk device, who can 408 // in typical use case there will be no one nearby the kiosk device, who can
415 // do some action to solve the problem be means of UI. 409 // do some action to solve the problem be means of UI.
416 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() && 410 if (!g_disable_ui_for_testing && !IsArcOptInVerificationDisabled() &&
417 !IsArcKioskMode()) { 411 !IsArcKioskMode()) {
418 DCHECK(!support_host_); 412 DCHECK(!support_host_);
419 support_host_ = base::MakeUnique<ArcSupportHost>(profile_); 413 support_host_ = base::MakeUnique<ArcSupportHost>(profile_);
420 support_host_->SetArcManaged(
421 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_));
422 support_host_->AddObserver(this); 414 support_host_->AddObserver(this);
423 } 415 }
424 416
425 DCHECK_EQ(State::NOT_INITIALIZED, state_); 417 DCHECK_EQ(State::NOT_INITIALIZED, state_);
426 SetState(State::STOPPED); 418 SetState(State::STOPPED);
427 419
428 context_.reset(new ArcAuthContext(profile_)); 420 context_ = base::MakeUnique<ArcAuthContext>(profile_);
429 421
430 if (!g_disable_ui_for_testing || 422 if (!g_disable_ui_for_testing ||
431 g_enable_check_android_management_for_testing) { 423 g_enable_check_android_management_for_testing) {
432 ArcAndroidManagementChecker::StartClient(); 424 ArcAndroidManagementChecker::StartClient();
433 } 425 }
434 426
435 pref_change_registrar_.Init(profile_->GetPrefs());
436 pref_change_registrar_.Add(
437 prefs::kArcEnabled,
438 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged,
439 weak_ptr_factory_.GetWeakPtr()));
440
441 // Chrome may be shut down before completing ARC data removal. 427 // Chrome may be shut down before completing ARC data removal.
442 // In such a case, start removing the data now. 428 // In such a case, start removing the data now.
443 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { 429 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) {
444 VLOG(1) << "ARC data removal requested in previous session."; 430 VLOG(1) << "ARC data removal requested in previous session.";
445 RemoveArcData(); 431 RemoveArcData();
446 } 432 }
447
448 if (IsArcPlayStoreEnabledForProfile(profile_)) {
449 VLOG(1) << "ARC is already enabled.";
450 DCHECK(!enable_requested_);
451 RequestEnable();
452 } else {
453 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)) {
454 // All users that can disable ARC by themselves will have the
455 // |kARcDataRemoveRequested| pref set, so we don't need to eagerly remove
456 // the data for that case.
457 // For managed users, the preference can change when the Profile object is
458 // not alive, so we still need to check it here in case it was disabled to
459 // ensure that the data is deleted in case it was disabled between
460 // launches.
461 VLOG(1) << "ARC is initially disabled for managed profile. "
462 << "Removing data.";
463 RemoveArcData();
464 }
465 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
466 OnIsSyncingChanged();
467 }
468 } 433 }
469 434
470 void ArcSessionManager::OnIsSyncingChanged() { 435 void ArcSessionManager::OnIsSyncingChanged() {
471 sync_preferences::PrefServiceSyncable* const pref_service_syncable = 436 sync_preferences::PrefServiceSyncable* const pref_service_syncable =
472 PrefServiceSyncableFromProfile(profile_); 437 PrefServiceSyncableFromProfile(profile_);
473 if (!pref_service_syncable->IsSyncing()) 438 if (!pref_service_syncable->IsSyncing())
474 return; 439 return;
475 440
476 pref_service_syncable->RemoveObserver(this); 441 pref_service_syncable->RemoveObserver(this);
477 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 442 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
(...skipping 28 matching lines...) Expand all
506 void ArcSessionManager::StopArc() { 471 void ArcSessionManager::StopArc() {
507 if (state_ != State::STOPPED) { 472 if (state_ != State::STOPPED) {
508 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 473 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
509 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); 474 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false);
510 } 475 }
511 ShutdownSession(); 476 ShutdownSession();
512 if (support_host_) 477 if (support_host_)
513 support_host_->Close(); 478 support_host_->Close();
514 } 479 }
515 480
481 void ArcSessionManager::StartPreferenceHandler() {
482 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
483 DCHECK(profile_);
484
485 // Start observing Google Play Store enabled preference.
486 pref_change_registrar_.Init(profile_->GetPrefs());
487 pref_change_registrar_.Add(
488 prefs::kArcEnabled,
489 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged,
490 weak_ptr_factory_.GetWeakPtr()));
491
492 // Set initial managed state to ArcSupportHost to update the message.
493 if (support_host_) {
494 support_host_->SetArcManaged(
495 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_));
496 }
497
498 // Update the state based on the initial Google Play Store enabled value.
499 if (IsArcPlayStoreEnabledForProfile(profile_)) {
500 VLOG(1) << "ARC is already enabled.";
501 DCHECK(!enable_requested_);
502 RequestEnable();
503 } else {
504 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)) {
505 // All users that can disable ARC by themselves will have the
506 // |kARcDataRemoveRequested| pref set, so we don't need to eagerly remove
507 // the data for that case.
508 // For managed users, the preference can change when the Profile object is
509 // not alive, so we still need to check it here in case it was disabled to
510 // ensure that the data is deleted in case it was disabled between
511 // launches.
512 VLOG(1) << "ARC is initially disabled for managed profile. "
513 << "Removing data.";
514 RemoveArcData();
515 }
516 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
517 OnIsSyncingChanged();
518 }
519 }
520
516 void ArcSessionManager::OnOptInPreferenceChanged() { 521 void ArcSessionManager::OnOptInPreferenceChanged() {
517 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 522 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
518 DCHECK(profile_); 523 DCHECK(profile_);
519 524
520 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_); 525 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_);
521 const bool is_play_store_managed = 526 const bool is_play_store_managed =
522 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); 527 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_);
523 if (!is_play_store_managed) { 528 if (!is_play_store_managed) {
524 // Update UMA only for non-Managed cases. 529 // Update UMA only for non-Managed cases.
525 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN 530 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 1000
996 #undef MAP_STATE 1001 #undef MAP_STATE
997 1002
998 // Some compilers report an error even if all values of an enum-class are 1003 // Some compilers report an error even if all values of an enum-class are
999 // covered exhaustively in a switch statement. 1004 // covered exhaustively in a switch statement.
1000 NOTREACHED() << "Invalid value " << static_cast<int>(state); 1005 NOTREACHED() << "Invalid value " << static_cast<int>(state);
1001 return os; 1006 return os;
1002 } 1007 }
1003 1008
1004 } // namespace arc 1009 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_session_manager.h ('k') | chrome/browser/chromeos/arc/arc_session_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698