OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_auth_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/shelf/shelf_delegate.h" | 9 #include "ash/shelf/shelf_delegate.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 namespace arc { | 50 namespace arc { |
51 | 51 |
52 namespace { | 52 namespace { |
53 | 53 |
54 // Weak pointer. This class is owned by ArcServiceManager. | 54 // Weak pointer. This class is owned by ArcServiceManager. |
55 ArcAuthService* g_arc_auth_service = nullptr; | 55 ArcAuthService* g_arc_auth_service = nullptr; |
56 | 56 |
57 // Skip creating UI in unit tests | 57 // Skip creating UI in unit tests |
58 bool g_disable_ui_for_testing = false; | 58 bool g_disable_ui_for_testing = false; |
59 | 59 |
60 // Skip checking for cryptohome data ephemeral users. | |
61 bool g_allow_cryptohome_data_ephemeral_user_for_testing = false; | |
khmel
2016/07/18 20:23:42
In most browser tests user is logged as Ephemeral
xiyuan
2016/07/18 20:59:12
Sounds like UserManagerBase::IsUserCryptohomeDataE
khmel
2016/07/18 22:15:11
Yes, this helps
| |
62 | |
60 // Use specified ash::ShelfDelegate for unit tests. | 63 // Use specified ash::ShelfDelegate for unit tests. |
61 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; | 64 ash::ShelfDelegate* g_shelf_delegate_for_testing = nullptr; |
62 | 65 |
63 // The Android management check is disabled by default, it's used only for | 66 // The Android management check is disabled by default, it's used only for |
64 // testing. | 67 // testing. |
65 bool g_enable_check_android_management_for_testing = false; | 68 bool g_enable_check_android_management_for_testing = false; |
66 | 69 |
67 const char kStateNotInitialized[] = "NOT_INITIALIZED"; | 70 const char kStateNotInitialized[] = "NOT_INITIALIZED"; |
68 const char kStateStopped[] = "STOPPED"; | 71 const char kStateStopped[] = "STOPPED"; |
69 const char kStateFetchingCode[] = "FETCHING_CODE"; | 72 const char kStateFetchingCode[] = "FETCHING_CODE"; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); | 129 registry->RegisterBooleanPref(prefs::kArcSignedIn, false); |
127 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); | 130 registry->RegisterBooleanPref(prefs::kArcBackupRestoreEnabled, true); |
128 } | 131 } |
129 | 132 |
130 // static | 133 // static |
131 void ArcAuthService::DisableUIForTesting() { | 134 void ArcAuthService::DisableUIForTesting() { |
132 g_disable_ui_for_testing = true; | 135 g_disable_ui_for_testing = true; |
133 } | 136 } |
134 | 137 |
135 // static | 138 // static |
139 void ArcAuthService::AllowCryptohomeDataEphemeralUserForTesting() { | |
140 g_allow_cryptohome_data_ephemeral_user_for_testing = true; | |
141 } | |
142 | |
143 // static | |
136 void ArcAuthService::SetShelfDelegateForTesting( | 144 void ArcAuthService::SetShelfDelegateForTesting( |
137 ash::ShelfDelegate* shelf_delegate) { | 145 ash::ShelfDelegate* shelf_delegate) { |
138 g_shelf_delegate_for_testing = shelf_delegate; | 146 g_shelf_delegate_for_testing = shelf_delegate; |
139 } | 147 } |
140 | 148 |
141 // static | 149 // static |
142 bool ArcAuthService::IsOptInVerificationDisabled() { | 150 bool ArcAuthService::IsOptInVerificationDisabled() { |
143 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 151 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
144 chromeos::switches::kDisableArcOptInVerification); | 152 chromeos::switches::kDisableArcOptInVerification); |
145 } | 153 } |
(...skipping 25 matching lines...) Expand all Loading... | |
171 return false; | 179 return false; |
172 } | 180 } |
173 | 181 |
174 user_manager::User const* const user = | 182 user_manager::User const* const user = |
175 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 183 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
176 if (!user || !user->HasGaiaAccount()) { | 184 if (!user || !user->HasGaiaAccount()) { |
177 VLOG(1) << "Users without GAIA accounts are not supported in ARC."; | 185 VLOG(1) << "Users without GAIA accounts are not supported in ARC."; |
178 return false; | 186 return false; |
179 } | 187 } |
180 | 188 |
181 if (user_manager::UserManager::Get() | 189 if (!g_allow_cryptohome_data_ephemeral_user_for_testing && |
190 user_manager::UserManager::Get() | |
182 ->IsCurrentUserCryptohomeDataEphemeral()) { | 191 ->IsCurrentUserCryptohomeDataEphemeral()) { |
183 VLOG(2) << "Users with ephemeral data are not supported in Arc."; | 192 VLOG(2) << "Users with ephemeral data are not supported in Arc."; |
184 return false; | 193 return false; |
185 } | 194 } |
186 | 195 |
187 return true; | 196 return true; |
188 } | 197 } |
189 | 198 |
190 void ArcAuthService::OnInstanceReady() { | 199 void ArcAuthService::OnInstanceReady() { |
191 arc_bridge_service()->auth()->instance()->Init( | 200 arc_bridge_service()->auth()->instance()->Init( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 344 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
336 return profile_ != nullptr; | 345 return profile_ != nullptr; |
337 } | 346 } |
338 | 347 |
339 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { | 348 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { |
340 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 349 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
341 DCHECK(profile && profile != profile_); | 350 DCHECK(profile && profile != profile_); |
342 | 351 |
343 Shutdown(); | 352 Shutdown(); |
344 | 353 |
345 profile_ = profile; | |
346 SetState(State::STOPPED); | |
347 | |
348 if (!IsAllowedForProfile(profile)) | 354 if (!IsAllowedForProfile(profile)) |
349 return; | 355 return; |
350 | 356 |
351 // TODO(khmel): Move this to IsAllowedForProfile. | 357 // TODO(khmel): Move this to IsAllowedForProfile. |
352 if (IsArcDisabledForEnterprise() && IsAccountManaged(profile)) { | 358 if (IsArcDisabledForEnterprise() && IsAccountManaged(profile)) { |
353 VLOG(2) << "Enterprise users are not supported in ARC."; | 359 VLOG(2) << "Enterprise users are not supported in ARC."; |
354 return; | 360 return; |
355 } | 361 } |
356 | 362 |
363 profile_ = profile; | |
364 SetState(State::STOPPED); | |
365 | |
357 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 366 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
358 prefs::kArcEnabled, this); | 367 prefs::kArcEnabled, this); |
359 | 368 |
360 context_.reset(new ArcAuthContext(this, profile_)); | 369 context_.reset(new ArcAuthContext(this, profile_)); |
361 | 370 |
362 // In case UI is disabled we assume that ARC is opted-in. | 371 // In case UI is disabled we assume that ARC is opted-in. |
363 if (IsOptInVerificationDisabled()) { | 372 if (IsOptInVerificationDisabled()) { |
364 auth_code_.clear(); | 373 auth_code_.clear(); |
365 StartArc(); | 374 StartArc(); |
366 return; | 375 return; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 } | 639 } |
631 | 640 |
632 bool ArcAuthService::IsArcManaged() const { | 641 bool ArcAuthService::IsArcManaged() const { |
633 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 642 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
634 DCHECK(profile_); | 643 DCHECK(profile_); |
635 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); | 644 return profile_->GetPrefs()->IsManagedPreference(prefs::kArcEnabled); |
636 } | 645 } |
637 | 646 |
638 bool ArcAuthService::IsArcEnabled() const { | 647 bool ArcAuthService::IsArcEnabled() const { |
639 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 648 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
649 if (!IsAllowed()) | |
650 return false; | |
651 | |
640 DCHECK(profile_); | 652 DCHECK(profile_); |
641 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 653 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
642 } | 654 } |
643 | 655 |
644 void ArcAuthService::EnableArc() { | 656 void ArcAuthService::EnableArc() { |
645 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 657 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
646 DCHECK(profile_); | 658 DCHECK(profile_); |
647 | 659 |
648 if (IsArcEnabled()) { | 660 if (IsArcEnabled()) { |
649 OnOptInPreferenceChanged(); | 661 OnOptInPreferenceChanged(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 return os << kStateFetchingCode; | 763 return os << kStateFetchingCode; |
752 case ArcAuthService::State::ACTIVE: | 764 case ArcAuthService::State::ACTIVE: |
753 return os << kStateActive; | 765 return os << kStateActive; |
754 default: | 766 default: |
755 NOTREACHED(); | 767 NOTREACHED(); |
756 return os; | 768 return os; |
757 } | 769 } |
758 } | 770 } |
759 | 771 |
760 } // namespace arc | 772 } // namespace arc |
OLD | NEW |