| 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 <string> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.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" |
| 15 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 16 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 17 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 218 } |
| 218 | 219 |
| 219 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { | 220 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { |
| 220 DCHECK(profile && profile != profile_); | 221 DCHECK(profile && profile != profile_); |
| 221 DCHECK(thread_checker.Get().CalledOnValidThread()); | 222 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 222 | 223 |
| 223 Shutdown(); | 224 Shutdown(); |
| 224 | 225 |
| 225 user_manager::User const* const user = | 226 user_manager::User const* const user = |
| 226 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | 227 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 227 if (profile->IsLegacySupervised() || !user->HasGaiaAccount()) { | 228 if (profile->IsLegacySupervised()) { |
| 228 VLOG(2) << "Supervised users and users without GAIA accounts are not " | 229 VLOG(1) << "Supervised users are not supported in ARC."; |
| 229 "supported in Arc."; | 230 return; |
| 231 } |
| 232 if (!user->HasGaiaAccount()) { |
| 233 VLOG(1) << "Users without GAIA accounts are not supported in ARC."; |
| 230 return; | 234 return; |
| 231 } | 235 } |
| 232 | 236 |
| 233 profile_ = profile; | 237 profile_ = profile; |
| 234 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 238 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 235 prefs::kArcEnabled, this); | 239 prefs::kArcEnabled, this); |
| 236 | 240 |
| 237 // Reuse storage used in ARC OptIn platform app. | 241 // Reuse storage used in ARC OptIn platform app. |
| 238 const std::string site_url = | 242 const std::string site_url = |
| 239 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, | 243 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 UpdateOptInActionUMA(profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled) | 354 UpdateOptInActionUMA(profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled) |
| 351 ? OptInActionType::OPTED_IN | 355 ? OptInActionType::OPTED_IN |
| 352 : OptInActionType::OPTED_OUT); | 356 : OptInActionType::OPTED_OUT); |
| 353 } | 357 } |
| 354 } | 358 } |
| 355 | 359 |
| 356 void ArcAuthService::OnOptInPreferenceChanged() { | 360 void ArcAuthService::OnOptInPreferenceChanged() { |
| 357 DCHECK(thread_checker.Get().CalledOnValidThread()); | 361 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 358 DCHECK(profile_); | 362 DCHECK(profile_); |
| 359 | 363 |
| 360 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 364 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 361 if (state_ != State::ACTIVE) { | |
| 362 CloseUI(); | |
| 363 auth_code_.clear(); | |
| 364 | |
| 365 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | |
| 366 // Need pre-fetch auth code and show OptIn UI if needed. | |
| 367 initial_opt_in_ = true; | |
| 368 StartUI(); | |
| 369 } else { | |
| 370 // Ready to start Arc. | |
| 371 StartArc(); | |
| 372 } | |
| 373 | |
| 374 UpdateEnabledStateUMA(true); | |
| 375 } | |
| 376 } else { | |
| 377 if (state_ != State::STOPPED) | 365 if (state_ != State::STOPPED) |
| 378 UpdateEnabledStateUMA(false); | 366 UpdateEnabledStateUMA(false); |
| 379 ShutdownBridgeAndCloseUI(); | 367 ShutdownBridgeAndCloseUI(); |
| 368 return; |
| 380 } | 369 } |
| 370 |
| 371 if (state_ == State::ACTIVE) |
| 372 return; |
| 373 CloseUI(); |
| 374 auth_code_.clear(); |
| 375 |
| 376 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 377 // Need pre-fetch auth code and show OptIn UI if needed. |
| 378 initial_opt_in_ = true; |
| 379 StartUI(); |
| 380 } else { |
| 381 // Ready to start Arc. |
| 382 StartArc(); |
| 383 } |
| 384 |
| 385 UpdateEnabledStateUMA(true); |
| 381 } | 386 } |
| 382 | 387 |
| 383 void ArcAuthService::ShutdownBridge() { | 388 void ArcAuthService::ShutdownBridge() { |
| 384 playstore_launcher_.reset(); | 389 playstore_launcher_.reset(); |
| 385 auth_callback_.reset(); | 390 auth_callback_.reset(); |
| 386 ubertoken_fethcher_.reset(); | 391 ubertoken_fethcher_.reset(); |
| 387 merger_fetcher_.reset(); | 392 merger_fetcher_.reset(); |
| 388 arc_bridge_service()->Shutdown(); | 393 arc_bridge_service()->Shutdown(); |
| 389 SetState(State::STOPPED); | 394 SetState(State::STOPPED); |
| 390 } | 395 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 return os << kStateFetchingCode; | 540 return os << kStateFetchingCode; |
| 536 case ArcAuthService::State::ACTIVE: | 541 case ArcAuthService::State::ACTIVE: |
| 537 return os << kStateActive; | 542 return os << kStateActive; |
| 538 default: | 543 default: |
| 539 NOTREACHED(); | 544 NOTREACHED(); |
| 540 return os; | 545 return os; |
| 541 } | 546 } |
| 542 } | 547 } |
| 543 | 548 |
| 544 } // namespace arc | 549 } // namespace arc |
| OLD | NEW |