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

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

Issue 1892873002: Add CheckAndroidManagement to ARC sign-in flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@check_android_management
Patch Set: Added browser test for ArcAuthService. Created 4 years, 8 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 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 "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/strings/string16.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/browser_process_platform_part.h"
15 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" 18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h"
16 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
17 #include "chrome/browser/chromeos/profiles/profile_helper.h" 21 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/extensions/extension_util.h" 22 #include "chrome/browser/extensions/extension_util.h"
19 #include "chrome/browser/policy/profile_policy_connector.h" 23 #include "chrome/browser/policy/profile_policy_connector.h"
20 #include "chrome/browser/policy/profile_policy_connector_factory.h" 24 #include "chrome/browser/policy/profile_policy_connector_factory.h"
21 #include "chrome/browser/prefs/pref_service_syncable_util.h" 25 #include "chrome/browser/prefs/pref_service_syncable_util.h"
22 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
24 #include "chrome/browser/signin/signin_manager_factory.h" 28 #include "chrome/browser/signin/signin_manager_factory.h"
25 #include "chrome/browser/ui/extensions/app_launch_params.h" 29 #include "chrome/browser/ui/extensions/app_launch_params.h"
26 #include "chrome/browser/ui/extensions/application_launch.h" 30 #include "chrome/browser/ui/extensions/application_launch.h"
27 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
28 #include "chrome/grit/generated_resources.h" 32 #include "chrome/grit/generated_resources.h"
29 #include "chromeos/chromeos_switches.h" 33 #include "chromeos/chromeos_switches.h"
30 #include "components/arc/arc_bridge_service.h" 34 #include "components/arc/arc_bridge_service.h"
35 #include "components/policy/core/browser/browser_policy_connector.h"
36 #include "components/policy/core/common/cloud/device_management_service.h"
31 #include "components/pref_registry/pref_registry_syncable.h" 37 #include "components/pref_registry/pref_registry_syncable.h"
32 #include "components/prefs/pref_service.h" 38 #include "components/prefs/pref_service.h"
33 #include "components/signin/core/browser/profile_oauth2_token_service.h" 39 #include "components/signin/core/browser/profile_oauth2_token_service.h"
34 #include "components/signin/core/browser/signin_manager_base.h" 40 #include "components/signin/core/browser/signin_manager_base.h"
35 #include "components/syncable_prefs/pref_service_syncable.h" 41 #include "components/syncable_prefs/pref_service_syncable.h"
36 #include "components/user_manager/user.h" 42 #include "components/user_manager/user.h"
37 #include "content/public/browser/storage_partition.h" 43 #include "content/public/browser/storage_partition.h"
38 #include "content/public/common/url_constants.h" 44 #include "content/public/common/url_constants.h"
39 #include "extensions/browser/app_window/app_window_registry.h" 45 #include "extensions/browser/app_window/app_window_registry.h"
40 #include "extensions/browser/extension_prefs.h" 46 #include "extensions/browser/extension_prefs.h"
(...skipping 10 matching lines...) Expand all
51 57
52 base::LazyInstance<base::ThreadChecker> thread_checker = 58 base::LazyInstance<base::ThreadChecker> thread_checker =
53 LAZY_INSTANCE_INITIALIZER; 59 LAZY_INSTANCE_INITIALIZER;
54 60
55 const char kArcSupportExtensionId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; 61 const char kArcSupportExtensionId[] = "cnbgggchhmkkdmeppjobngjoejnihlei";
56 const char kArcSupportStorageId[] = "arc_support"; 62 const char kArcSupportStorageId[] = "arc_support";
57 63
58 // Skip creating UI in unit tests 64 // Skip creating UI in unit tests
59 bool disable_ui_for_testing = false; 65 bool disable_ui_for_testing = false;
60 66
67 // Do check Android management requirement in browser tests.
68 bool enable_check_android_management_for_testing = false;
69
61 const char kStateStopped[] = "STOPPED"; 70 const char kStateStopped[] = "STOPPED";
62 const char kStateFetchingCode[] = "FETCHING_CODE"; 71 const char kStateFetchingCode[] = "FETCHING_CODE";
63 const char kStateActive[] = "ACTIVE"; 72 const char kStateActive[] = "ACTIVE";
64 } // namespace 73 } // namespace
65 74
66 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) 75 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service)
67 : ArcService(bridge_service), binding_(this) { 76 : ArcService(bridge_service), binding_(this) {
68 DCHECK(!arc_auth_service); 77 DCHECK(!arc_auth_service);
69 DCHECK(thread_checker.Get().CalledOnValidThread()); 78 DCHECK(thread_checker.Get().CalledOnValidThread());
70 79
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 void ArcAuthService::DisableUIForTesting() { 111 void ArcAuthService::DisableUIForTesting() {
103 disable_ui_for_testing = true; 112 disable_ui_for_testing = true;
104 } 113 }
105 114
106 // static 115 // static
107 bool ArcAuthService::IsOptInVerificationDisabled() { 116 bool ArcAuthService::IsOptInVerificationDisabled() {
108 return base::CommandLine::ForCurrentProcess()->HasSwitch( 117 return base::CommandLine::ForCurrentProcess()->HasSwitch(
109 chromeos::switches::kDisableArcOptInVerification); 118 chromeos::switches::kDisableArcOptInVerification);
110 } 119 }
111 120
121 // static
122 void ArcAuthService::EnableCheckAndroidManagementForTesting() {
123 enable_check_android_management_for_testing = true;
124 }
125
112 void ArcAuthService::OnAuthInstanceReady() { 126 void ArcAuthService::OnAuthInstanceReady() {
113 arc_bridge_service()->auth_instance()->Init( 127 arc_bridge_service()->auth_instance()->Init(
114 binding_.CreateInterfacePtrAndBind()); 128 binding_.CreateInterfacePtrAndBind());
115 } 129 }
116 130
117 std::string ArcAuthService::GetAndResetAuthCode() { 131 std::string ArcAuthService::GetAndResetAuthCode() {
118 DCHECK(thread_checker.Get().CalledOnValidThread()); 132 DCHECK(thread_checker.Get().CalledOnValidThread());
119 std::string auth_code; 133 std::string auth_code;
120 auth_code_.swap(auth_code); 134 auth_code_.swap(auth_code);
121 return auth_code; 135 return auth_code;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const user_manager::User* const primary_user = 208 const user_manager::User* const primary_user =
195 user_manager::UserManager::Get()->GetPrimaryUser(); 209 user_manager::UserManager::Get()->GetPrimaryUser();
196 Profile* const profile = 210 Profile* const profile =
197 chromeos::ProfileHelper::Get()->GetProfileByUser(primary_user); 211 chromeos::ProfileHelper::Get()->GetProfileByUser(primary_user);
198 const policy::ProfilePolicyConnector* const profile_policy_connector = 212 const policy::ProfilePolicyConnector* const profile_policy_connector =
199 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile); 213 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile);
200 callback.Run(profile_policy_connector->IsManaged()); 214 callback.Run(profile_policy_connector->IsManaged());
201 } 215 }
202 216
203 void ArcAuthService::SetState(State state) { 217 void ArcAuthService::SetState(State state) {
204 if (state_ == state) 218 if (state_ == state && !enable_check_android_management_for_testing)
205 return; 219 return;
206 220
207 state_ = state; 221 state_ = state;
208 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_)); 222 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_));
209 } 223 }
210 224
211 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { 225 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
212 DCHECK(profile && profile != profile_); 226 DCHECK(profile && profile != profile_);
213 DCHECK(thread_checker.Get().CalledOnValidThread()); 227 DCHECK(thread_checker.Get().CalledOnValidThread());
214 228
(...skipping 11 matching lines...) Expand all
226 // Reuse storage used in ARC OptIn platform app. 240 // Reuse storage used in ARC OptIn platform app.
227 const std::string site_url = 241 const std::string site_url =
228 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, 242 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme,
229 kArcSupportExtensionId, kArcSupportStorageId); 243 kArcSupportExtensionId, kArcSupportStorageId);
230 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( 244 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite(
231 profile_, GURL(site_url)); 245 profile_, GURL(site_url));
232 CHECK(storage_partition_); 246 CHECK(storage_partition_);
233 247
234 // In case UI is disabled we assume that ARC is opted-in. 248 // In case UI is disabled we assume that ARC is opted-in.
235 if (!IsOptInVerificationDisabled()) { 249 if (!IsOptInVerificationDisabled()) {
250 if (!disable_ui_for_testing || enable_check_android_management_for_testing)
251 StartAndroidManagementClient();
252
236 pref_change_registrar_.Init(profile_->GetPrefs()); 253 pref_change_registrar_.Init(profile_->GetPrefs());
237 pref_change_registrar_.Add( 254 pref_change_registrar_.Add(
238 prefs::kArcEnabled, 255 prefs::kArcEnabled,
239 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, 256 base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
240 base::Unretained(this))); 257 base::Unretained(this)));
241 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 258 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
242 OnOptInPreferenceChanged(); 259 OnOptInPreferenceChanged();
243 } else { 260 } else {
244 UpdateEnabledStateUMA(false); 261 UpdateEnabledStateUMA(false);
245 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); 262 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
(...skipping 25 matching lines...) Expand all
271 void ArcAuthService::Shutdown() { 288 void ArcAuthService::Shutdown() {
272 ShutdownBridgeAndCloseUI(); 289 ShutdownBridgeAndCloseUI();
273 if (profile_) { 290 if (profile_) {
274 syncable_prefs::PrefServiceSyncable* pref_service_syncable = 291 syncable_prefs::PrefServiceSyncable* pref_service_syncable =
275 PrefServiceSyncableFromProfile(profile_); 292 PrefServiceSyncableFromProfile(profile_);
276 pref_service_syncable->RemoveObserver(this); 293 pref_service_syncable->RemoveObserver(this);
277 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); 294 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this);
278 } 295 }
279 pref_change_registrar_.RemoveAll(); 296 pref_change_registrar_.RemoveAll();
280 profile_ = nullptr; 297 profile_ = nullptr;
298 android_management_client_.reset();
khmel1 2016/04/20 19:13:31 Probably ArcAuthService::ShutdownBridge is better
Polina Bondarenko 2016/04/25 19:59:49 If android_management_client_ is destroyed not at
khmel 2016/04/27 16:07:42 Thanks for explanation. Short comment may be welco
Polina Bondarenko 2016/04/27 16:58:50 Added comment.
281 } 299 }
282 300
283 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { 301 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) {
284 if (disable_ui_for_testing || IsOptInVerificationDisabled()) 302 if (disable_ui_for_testing || IsOptInVerificationDisabled())
285 return; 303 return;
286 304
287 SetUIPage(page, status); 305 SetUIPage(page, status);
288 const extensions::AppWindowRegistry* const app_window_registry = 306 const extensions::AppWindowRegistry* const app_window_registry =
289 extensions::AppWindowRegistry::Get(profile_); 307 extensions::AppWindowRegistry::Get(profile_);
290 DCHECK(app_window_registry); 308 DCHECK(app_window_registry);
291 if (app_window_registry->GetCurrentAppWindowForApp(kArcSupportExtensionId)) 309 if (app_window_registry->GetCurrentAppWindowForApp(kArcSupportExtensionId))
292 return; 310 return;
293 311
294 const extensions::Extension* extension = 312 const extensions::Extension* extension =
295 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( 313 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
296 kArcSupportExtensionId); 314 kArcSupportExtensionId);
297 CHECK(extension && 315 CHECK(extension &&
298 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); 316 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_));
299 317
300 OpenApplication(CreateAppLaunchParamsUserContainer( 318 OpenApplication(CreateAppLaunchParamsUserContainer(
301 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); 319 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL));
302 } 320 }
303 321
304 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { 322 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) {
305 DCHECK(thread_checker.Get().CalledOnValidThread()); 323 DCHECK(thread_checker.Get().CalledOnValidThread());
306 324
307 DCHECK(!initial_opt_in_); 325 DCHECK(!initial_opt_in_);
308 context_prepared_ = true;
309 ShowUI(UIPage::LSO_PROGRESS, base::string16()); 326 ShowUI(UIPage::LSO_PROGRESS, base::string16());
327 CheckAndroidManagement();
310 } 328 }
311 329
312 void ArcAuthService::OnMergeSessionFailure( 330 void ArcAuthService::OnMergeSessionFailure(
313 const GoogleServiceAuthError& error) { 331 const GoogleServiceAuthError& error) {
314 DCHECK(thread_checker.Get().CalledOnValidThread()); 332 DCHECK(thread_checker.Get().CalledOnValidThread());
315 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; 333 VLOG(2) << "Failed to merge gaia session " << error.ToString() << ".";
316 OnPrepareContextFailed(); 334 OnPrepareContextFailed();
317 } 335 }
318 336
319 void ArcAuthService::OnUbertokenSuccess(const std::string& token) { 337 void ArcAuthService::OnUbertokenSuccess(const std::string& token) {
320 DCHECK(thread_checker.Get().CalledOnValidThread()); 338 DCHECK(thread_checker.Get().CalledOnValidThread());
321 merger_fetcher_.reset( 339 merger_fetcher_.reset(
322 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, 340 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource,
323 storage_partition_->GetURLRequestContext())); 341 storage_partition_->GetURLRequestContext()));
342 auth_token_ = token;
xiyuan 2016/04/20 18:21:41 |token| is uber token, not sure if it is what you
Polina Bondarenko 2016/04/25 19:59:49 Thanks, fixed to access token.
324 merger_fetcher_->StartMergeSession(token, std::string()); 343 merger_fetcher_->StartMergeSession(token, std::string());
325 } 344 }
326 345
327 void ArcAuthService::OnUbertokenFailure(const GoogleServiceAuthError& error) { 346 void ArcAuthService::OnUbertokenFailure(const GoogleServiceAuthError& error) {
328 DCHECK(thread_checker.Get().CalledOnValidThread()); 347 DCHECK(thread_checker.Get().CalledOnValidThread());
329 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; 348 VLOG(2) << "Failed to get ubertoken " << error.ToString() << ".";
330 OnPrepareContextFailed(); 349 OnPrepareContextFailed();
331 } 350 }
332 351
333 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, 352 void ArcAuthService::OnSyncedPrefChanged(const std::string& path,
(...skipping 15 matching lines...) Expand all
349 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { 368 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) {
350 if (state_ != State::ACTIVE) { 369 if (state_ != State::ACTIVE) {
351 CloseUI(); 370 CloseUI();
352 auth_code_.clear(); 371 auth_code_.clear();
353 372
354 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 373 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
355 // Need pre-fetch auth code and show OptIn UI if needed. 374 // Need pre-fetch auth code and show OptIn UI if needed.
356 initial_opt_in_ = true; 375 initial_opt_in_ = true;
357 StartUI(); 376 StartUI();
358 } else { 377 } else {
359 // Ready to start Arc. 378 // Ready to start Arc, but check android management first.
360 StartArc(); 379 if (!disable_ui_for_testing ||
380 enable_check_android_management_for_testing)
khmel1 2016/04/20 19:13:31 nit: 2+ lines, please use {}
Polina Bondarenko 2016/04/25 19:59:49 Done.
381 CheckAndroidManagement();
382 else
383 StartArc();
361 } 384 }
362 385
363 UpdateEnabledStateUMA(true); 386 UpdateEnabledStateUMA(true);
364 } 387 }
365 } else { 388 } else {
366 if (state_ != State::STOPPED) 389 if (state_ != State::STOPPED)
367 UpdateEnabledStateUMA(false); 390 UpdateEnabledStateUMA(false);
368 ShutdownBridgeAndCloseUI(); 391 ShutdownBridgeAndCloseUI();
369 } 392 }
370 } 393 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (ui_page_ == UIPage::ERROR) 471 if (ui_page_ == UIPage::ERROR)
449 UpdateOptInActionUMA(OptInActionType::RETRY); 472 UpdateOptInActionUMA(OptInActionType::RETRY);
450 473
451 initial_opt_in_ = false; 474 initial_opt_in_ = false;
452 StartUI(); 475 StartUI();
453 } 476 }
454 477
455 void ArcAuthService::CancelAuthCode() { 478 void ArcAuthService::CancelAuthCode() {
456 DCHECK(thread_checker.Get().CalledOnValidThread()); 479 DCHECK(thread_checker.Get().CalledOnValidThread());
457 480
458 if (state_ != State::FETCHING_CODE) 481 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR)
459 return; 482 return;
460 483
461 // Update UMA with user cancel only if error is not currently shown. 484 // Update UMA with user cancel only if error is not currently shown.
462 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) 485 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE)
463 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 486 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
464 487
465 DisableArc(); 488 DisableArc();
466 } 489 }
467 490
468 void ArcAuthService::EnableArc() { 491 void ArcAuthService::EnableArc() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 531
509 void ArcAuthService::OnPrepareContextFailed() { 532 void ArcAuthService::OnPrepareContextFailed() {
510 DCHECK_EQ(state_, State::FETCHING_CODE); 533 DCHECK_EQ(state_, State::FETCHING_CODE);
511 534
512 ShutdownBridgeAndShowUI( 535 ShutdownBridgeAndShowUI(
513 UIPage::ERROR, 536 UIPage::ERROR,
514 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 537 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
515 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 538 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
516 } 539 }
517 540
541 void ArcAuthService::StartAndroidManagementClient() {
542 policy::BrowserPolicyConnectorChromeOS* const connector =
543 g_browser_process->platform_part()->browser_policy_connector_chromeos();
544 policy::DeviceManagementService* const service =
545 connector->device_management_service();
546 service->ScheduleInitialization(0);
547 android_management_client_.reset(new policy::AndroidManagementClient(
548 service, g_browser_process->system_request_context()));
xiyuan 2016/04/20 18:21:41 Should we be using storage_partition_->GetURLReque
Polina Bondarenko 2016/04/25 19:59:49 Done.
549 }
550
551 void ArcAuthService::CheckAndroidManagement() {
552 // Do not send requests for Chrome OS managed users.
553 if (policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_)
554 ->IsManaged()) {
xiyuan 2016/04/20 18:21:41 Would ProfilePolicyConnectorFactory::GetForBrowser
Polina Bondarenko 2016/04/25 19:59:49 No, it seems like it always returns a value.
555 OnAndroidManagementChecked(
556 policy::AndroidManagementClient::Result::RESULT_UNMANAGED);
557 return;
558 }
559
560 // Do not send requests for well-known consumer domains.
561 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser(
562 profile_->GetProfileUserName())) {
563 OnAndroidManagementChecked(
564 policy::AndroidManagementClient::Result::RESULT_UNMANAGED);
565 return;
566 }
567
568 android_management_client_->CheckAndroidManagement(
569 auth_token_, base::Bind(&ArcAuthService::OnAndroidManagementChecked,
570 base::Unretained(this)));
xiyuan 2016/04/20 18:21:41 WeakPtr instead of base::Unretained. Or add a comm
Polina Bondarenko 2016/04/25 19:59:49 Done.
571 }
572
573 void ArcAuthService::OnAndroidManagementChecked(
574 policy::AndroidManagementClient::Result result) {
575 switch (result) {
576 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
577 context_prepared_ = true;
578 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn))
579 ShowUI(UIPage::LSO, base::string16());
khmel1 2016/04/20 19:13:31 Please use UIPage::LSO_PROGRESS... instead UIPage:
Polina Bondarenko 2016/04/25 19:59:49 Done.
580 else
581 StartArc();
582 break;
583 case policy::AndroidManagementClient::Result::RESULT_MANAGED:
584 ShutdownBridgeAndShowUI(
585 UIPage::ERROR,
586 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
587 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
588 break;
589 case policy::AndroidManagementClient::Result::RESULT_ERROR:
590 ShutdownBridgeAndShowUI(
591 UIPage::ERROR,
592 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
593 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
594 break;
595 }
khmel1 2016/04/20 19:13:31 nit: default: NOTREACHED(); ?
Polina Bondarenko 2016/04/25 19:59:49 Done.
596 }
597
518 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { 598 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
519 switch (state) { 599 switch (state) {
520 case ArcAuthService::State::STOPPED: 600 case ArcAuthService::State::STOPPED:
521 return os << kStateStopped; 601 return os << kStateStopped;
522 case ArcAuthService::State::FETCHING_CODE: 602 case ArcAuthService::State::FETCHING_CODE:
523 return os << kStateFetchingCode; 603 return os << kStateFetchingCode;
524 case ArcAuthService::State::ACTIVE: 604 case ArcAuthService::State::ACTIVE:
525 return os << kStateActive; 605 return os << kStateActive;
526 default: 606 default:
527 NOTREACHED(); 607 NOTREACHED();
528 return os; 608 return os;
529 } 609 }
530 } 610 }
531 611
532 } // namespace arc 612 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698