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

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: Added more 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 clear_required_ = false;
Luis Héctor Chávez 2016/08/09 16:40:02 This is not needed, since it's the first thing Rem
hidehiko 2016/08/10 05:41:18 Done.
240 RemoveArcData();
241 } else {
242 // To support special "Reenable ARC" procedure for enterprise, here call
243 // OnArcDataRemoved(true) as if the data removal is successfully done.
244 // TODO(hidehiko): Restructure the code.
245 OnArcDataRemoved(true);
246 }
247 }
248
249 void ArcAuthService::RemoveArcData() {
250 if (!arc_bridge_service()->stopped()) {
251 // Just set a flag. On bridge stopped, this will be re-called,
252 // then session manager should remove the data.
253 clear_required_ = true;
238 return; 254 return;
255 }
239 clear_required_ = false; 256 clear_required_ = false;
240 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( 257 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData(
241 cryptohome::Identification( 258 cryptohome::Identification(
242 multi_user_util::GetAccountIdFromProfile(profile_)), 259 multi_user_util::GetAccountIdFromProfile(profile_)),
243 chromeos::SessionManagerClient::ArcCallback()); 260 base::Bind(&ArcAuthService::OnArcDataRemoved,
261 weak_ptr_factory_.GetWeakPtr()));
262 }
263
264 void ArcAuthService::OnArcDataRemoved(bool success) {
265 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed.";
266
267 // Here check if |reenable_arc_| is marked or not.
268 // The only case this happens should be in the special case for enterprise
269 // "on managed lost" case. In that case, OnBridgeStopped() should trigger
270 // the RemoveArcData(), then this.
271 // TODO(hidehiko): Restructure the code.
272 if (!reenable_arc_)
273 return;
274
275 // Restart ARC anyway. Let the enterprise reporting instance decide whether
276 // the ARC user data wipe is still required or not.
277 reenable_arc_ = false;
278 VLOG(1) << "Reenable ARC";
279 EnableArc();
244 } 280 }
245 281
246 std::string ArcAuthService::GetAndResetAuthCode() { 282 std::string ArcAuthService::GetAndResetAuthCode() {
247 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 283 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
248 std::string auth_code; 284 std::string auth_code;
249 auth_code_.swap(auth_code); 285 auth_code_.swap(auth_code);
250 return auth_code; 286 return auth_code;
251 } 287 }
252 288
253 void ArcAuthService::GetAuthCodeDeprecated( 289 void ArcAuthService::GetAuthCodeDeprecated(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); 381 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false);
346 ShutdownBridgeAndShowUI(UIPage::ERROR, 382 ShutdownBridgeAndShowUI(UIPage::ERROR,
347 l10n_util::GetStringUTF16(error_message_id)); 383 l10n_util::GetStringUTF16(error_message_id));
348 return; 384 return;
349 } 385 }
350 386
351 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED || 387 if (result == ProvisioningResult::CLOUD_PROVISION_FLOW_FAILED ||
352 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT || 388 result == ProvisioningResult::CLOUD_PROVISION_FLOW_TIMEOUT ||
353 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR || 389 result == ProvisioningResult::CLOUD_PROVISION_FLOW_INTERNAL_ERROR ||
354 result == ProvisioningResult::UNKNOWN_ERROR) 390 result == ProvisioningResult::UNKNOWN_ERROR)
355 clear_required_ = true; 391 RemoveArcData();
356 392
357 // We'll delay shutting down the bridge in this case to allow people to send 393 // We'll delay shutting down the bridge in this case to allow people to send
358 // feedback. 394 // feedback.
359 ShowUI(UIPage::ERROR_WITH_FEEDBACK, 395 ShowUI(UIPage::ERROR_WITH_FEEDBACK,
360 l10n_util::GetStringUTF16(error_message_id)); 396 l10n_util::GetStringUTF16(error_message_id));
361 } 397 }
362 398
363 void ArcAuthService::GetIsAccountManaged( 399 void ArcAuthService::GetIsAccountManaged(
364 const GetIsAccountManagedCallback& callback) { 400 const GetIsAccountManagedCallback& callback) {
365 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 401 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 553
518 void ArcAuthService::OnOptInPreferenceChanged() { 554 void ArcAuthService::OnOptInPreferenceChanged() {
519 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 555 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
520 DCHECK(profile_); 556 DCHECK(profile_);
521 557
522 const bool arc_enabled = IsArcEnabled(); 558 const bool arc_enabled = IsArcEnabled();
523 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); 559 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled));
524 560
525 if (!arc_enabled) { 561 if (!arc_enabled) {
526 StopArc(); 562 StopArc();
563 RemoveArcData();
527 return; 564 return;
528 } 565 }
529 566
530 if (state_ == State::ACTIVE) 567 if (state_ == State::ACTIVE)
531 return; 568 return;
532 CloseUI(); 569 CloseUI();
533 auth_code_.clear(); 570 auth_code_.clear();
534 571
535 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 572 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
536 // Need pre-fetch auth code and show OptIn UI if needed. 573 // 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(); 624 ArcAuthNotification::Hide();
588 } 625 }
589 626
590 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) { 627 void ArcAuthService::SetUIPage(UIPage page, const base::string16& status) {
591 ui_page_ = page; 628 ui_page_ = page;
592 ui_page_status_ = status; 629 ui_page_status_ = status;
593 FOR_EACH_OBSERVER(Observer, observer_list_, 630 FOR_EACH_OBSERVER(Observer, observer_list_,
594 OnOptInUIShowPage(ui_page_, ui_page_status_)); 631 OnOptInUIShowPage(ui_page_, ui_page_status_));
595 } 632 }
596 633
634 // This is the special method to support enterprise mojo API.
635 // TODO(hidehiko): Remove this.
636 void ArcAuthService::ReenableArc() {
637 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
638 DCHECK(!arc_bridge_service()->stopped());
639 reenable_arc_ = true;
640 StopArc();
641 }
642
597 void ArcAuthService::StartArc() { 643 void ArcAuthService::StartArc() {
598 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 644 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
599 arc_bridge_service()->HandleStartup(); 645 arc_bridge_service()->HandleStartup();
600 SetState(State::ACTIVE); 646 SetState(State::ACTIVE);
601 } 647 }
602 648
603 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { 649 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) {
604 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 650 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
605 DCHECK(!auth_code.empty()); 651 DCHECK(!auth_code.empty());
606 652
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 return os << kStateFetchingCode; 852 return os << kStateFetchingCode;
807 case ArcAuthService::State::ACTIVE: 853 case ArcAuthService::State::ACTIVE:
808 return os << kStateActive; 854 return os << kStateActive;
809 default: 855 default:
810 NOTREACHED(); 856 NOTREACHED();
811 return os; 857 return os;
812 } 858 }
813 } 859 }
814 860
815 } // namespace arc 861 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698