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

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

Issue 2209173002: Migrate ArcUserDataService into ArcAuthService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 4 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 "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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 228
229 void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) { 229 void ArcAuthService::OnBridgeStopped(ArcBridgeService::StopReason reason) {
230 // TODO(crbug.com/625923): Use |reason| to report more detailed errors. 230 // TODO(crbug.com/625923): Use |reason| to report more detailed errors.
231 if (waiting_for_reply_) { 231 if (waiting_for_reply_) {
232 // Using SERVICE_UNAVAILABLE instead of UNKNOWN_ERROR, since the latter 232 // Using SERVICE_UNAVAILABLE instead of UNKNOWN_ERROR, since the latter
233 // causes this code to not try to stop ARC, so it would retry without the 233 // causes this code to not try to stop ARC, so it would retry without the
234 // user noticing. 234 // user noticing.
235 OnSignInFailedInternal(ProvisioningResult::ARC_STOPPED); 235 OnSignInFailedInternal(ProvisioningResult::ARC_STOPPED);
236 } 236 }
237 if (!clear_required_) 237
238 if (clear_required_) {
239 // This should be always true, but just in case as this is looked at
240 // inside RemoveArcData() at first.
241 DCHECK(arc_bridge_service()->stopped());
242 RemoveArcData();
243 } else {
244 // To support special "Reenable ARC" procedure for enterprise, here call
245 // OnArcDataRemoved(true) as if the data removal is successfully done.
246 // TODO(hidehiko): Restructure the code.
247 OnArcDataRemoved(true);
248 }
249 }
250
251 void ArcAuthService::RemoveArcData() {
252 if (!arc_bridge_service()->stopped()) {
253 // Just set a flag. On bridge stopped, this will be re-called,
254 // then session manager should remove the data.
255 clear_required_ = true;
238 return; 256 return;
257 }
239 clear_required_ = false; 258 clear_required_ = false;
240 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( 259 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData(
241 cryptohome::Identification( 260 cryptohome::Identification(
242 multi_user_util::GetAccountIdFromProfile(profile_)), 261 multi_user_util::GetAccountIdFromProfile(profile_)),
243 chromeos::SessionManagerClient::ArcCallback()); 262 base::Bind(&ArcAuthService::OnArcDataRemoved,
263 weak_ptr_factory_.GetWeakPtr()));
264 }
265
266 void ArcAuthService::OnArcDataRemoved(bool success) {
267 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed.";
268
269 // Here check if |reenable_arc_| is marked or not.
270 // The only case this happens should be in the special case for enterprise
271 // "on managed lost" case. In that case, OnBridgeStopped() should trigger
272 // the RemoveArcData(), then this.
273 // TODO(hidehiko): Restructure the code.
274 if (!reenable_arc_)
275 return;
276
277 // Restart ARC anyway. Let the enterprise reporting instance decide whether
278 // the ARC user data wipe is still required or not.
279 reenable_arc_ = false;
280 VLOG(1) << "Reenable ARC";
281 EnableArc();
244 } 282 }
245 283
246 std::string ArcAuthService::GetAndResetAuthCode() { 284 std::string ArcAuthService::GetAndResetAuthCode() {
247 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 285 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
248 std::string auth_code; 286 std::string auth_code;
249 auth_code_.swap(auth_code); 287 auth_code_.swap(auth_code);
250 return auth_code; 288 return auth_code;
251 } 289 }
252 290
253 void ArcAuthService::GetAuthCodeDeprecated( 291 void ArcAuthService::GetAuthCodeDeprecated(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 383 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
346 ShutdownBridgeAndShowUI(UIPage::ERROR, 384 ShutdownBridgeAndShowUI(UIPage::ERROR,
347 l10n_util::GetStringUTF16(error_message_id)); 385 l10n_util::GetStringUTF16(error_message_id));
348 return; 386 return;
349 } 387 }
350 388
351 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 389 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
352 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 390 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
353 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 391 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
354 result == ProvisioningResult::UNKNOWN_ERROR) 392 result == ProvisioningResult::UNKNOWN_ERROR)
355 clear_required_ = true; 393 RemoveArcData();
356 394
357 // We'll delay shutting down the bridge in this case to allow people to send 395 // We'll delay shutting down the bridge in this case to allow people to send
358 // feedback. 396 // feedback.
359 ShowUI(UIPage::ERROR_WITH_FEEDBACK, 397 ShowUI(UIPage::ERROR_WITH_FEEDBACK,
360 l10n_util::GetStringUTF16(error_message_id)); 398 l10n_util::GetStringUTF16(error_message_id));
361 } 399 }
362 400
363 void ArcAuthService::GetIsAccountManaged( 401 void ArcAuthService::GetIsAccountManaged(
364 const GetIsAccountManagedCallback& callback) { 402 const GetIsAccountManagedCallback& callback) {
365 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 403 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 555
518 void ArcAuthService::OnOptInPreferenceChanged() { 556 void ArcAuthService::OnOptInPreferenceChanged() {
519 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 557 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
520 DCHECK(profile_); 558 DCHECK(profile_);
521 559
522 const bool arc_enabled = IsArcEnabled(); 560 const bool arc_enabled = IsArcEnabled();
523 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); 561 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled));
524 562
525 if (!arc_enabled) { 563 if (!arc_enabled) {
526 StopArc(); 564 StopArc();
565 RemoveArcData();
527 return; 566 return;
528 } 567 }
529 568
530 if (state_ == State::ACTIVE) 569 if (state_ == State::ACTIVE)
531 return; 570 return;
532 CloseUI(); 571 CloseUI();
533 auth_code_.clear(); 572 auth_code_.clear();
534 573
535 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 574 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
536 // Need pre-fetch auth code and show OptIn UI if needed. 575 // Need pre-fetch auth code and show OptIn UI if needed.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 ArcAuthNotification::Hide(); 626 ArcAuthNotification::Hide();
588 } 627 }
589 628
590 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { 629 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) {
591 ui_page_ = page; 630 ui_page_ = page;
592 ui_page_status_ = status; 631 ui_page_status_ = status;
593 FOR_EACH_OBSERVER(Observer, observer_list_, 632 FOR_EACH_OBSERVER(Observer, observer_list_,
594 OnOptInUIShowPage(ui_page_, ui_page_status_)); 633 OnOptInUIShowPage(ui_page_, ui_page_status_));
595 } 634 }
596 635
636 // This is the special method to support enterprise mojo API.
637 // TODO(hidehiko): Remove this.
638 void ArcAuthService::ReenableArc() {
639 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
640 DCHECK(!arc_bridge_service()->stopped());
641 reenable_arc_ = true;
642 StopArc();
643 }
644
597 void ArcAuthService::StartArc() { 645 void ArcAuthService::StartArc() {
598 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 646 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
599 arc_bridge_service()->HandleStartup(); 647 arc_bridge_service()->HandleStartup();
600 SetState(State::ACTIVE); 648 SetState(State::ACTIVE);
601 } 649 }
602 650
603 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { 651 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) {
604 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 652 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
605 DCHECK(!auth_code.empty()); 653 DCHECK(!auth_code.empty());
606 654
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 return os << kStateFetchingCode; 854 return os << kStateFetchingCode;
807 case ArcAuthService::State::ACTIVE: 855 case ArcAuthService::State::ACTIVE:
808 return os << kStateActive; 856 return os << kStateActive;
809 default: 857 default:
810 NOTREACHED(); 858 NOTREACHED();
811 return os; 859 return os;
812 } 860 }
813 } 861 }
814 862
815 } // namespace arc 863 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698