| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/avatar_button_error_controller.h" |
| 6 |
| 7 #include "chrome/browser/profiles/profiles_state.h" |
| 8 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 9 #include "components/browser_sync/browser/profile_sync_service.h" |
| 10 #include "components/signin/core/browser/signin_error_controller.h" |
| 11 #include "components/signin/core/common/profile_management_switches.h" |
| 12 |
| 13 AvatarButtonErrorController::AvatarButtonErrorController(Profile* profile) |
| 14 : avatar_signin_error_controller_(profile, this), |
| 15 avatar_sync_error_controller_(profile, this), |
| 16 has_signin_error_(false), |
| 17 has_sync_error_(false) {} |
| 18 |
| 19 void AvatarButtonErrorController::UpdateSigninError(bool has_signin_error) { |
| 20 has_signin_error_ = has_signin_error; |
| 21 OnAvatarErrorChanged(); |
| 22 } |
| 23 |
| 24 void AvatarButtonErrorController::UpdateSyncError(bool has_sync_error) { |
| 25 has_sync_error_ = has_sync_error; |
| 26 OnAvatarErrorChanged(); |
| 27 } |
| 28 |
| 29 void AvatarButtonErrorController::GetAvatarErrorUpdate() { |
| 30 avatar_signin_error_controller_.OnErrorChanged(); |
| 31 avatar_sync_error_controller_.OnErrorChanged(); |
| 32 } |
| 33 |
| 34 AvatarButtonErrorController::AvatarSigninErrorController:: |
| 35 AvatarSigninErrorController( |
| 36 Profile* profile, |
| 37 AvatarButtonErrorController* avatar_button_error_controller) |
| 38 : profile_(profile), |
| 39 avatar_button_error_controller_(avatar_button_error_controller) { |
| 40 SigninErrorController* signin_error_controller = |
| 41 profiles::GetSigninErrorController(profile_); |
| 42 if (signin_error_controller) |
| 43 signin_error_controller->AddObserver(this); |
| 44 } |
| 45 |
| 46 AvatarButtonErrorController::AvatarSigninErrorController:: |
| 47 ~AvatarSigninErrorController() { |
| 48 SigninErrorController* signin_error_controller = |
| 49 profiles::GetSigninErrorController(profile_); |
| 50 if (signin_error_controller) |
| 51 signin_error_controller->RemoveObserver(this); |
| 52 } |
| 53 |
| 54 void AvatarButtonErrorController::AvatarSigninErrorController:: |
| 55 OnErrorChanged() { |
| 56 const SigninErrorController* signin_error_controller = |
| 57 profiles::GetSigninErrorController(profile_); |
| 58 avatar_button_error_controller_->UpdateSigninError( |
| 59 signin_error_controller && signin_error_controller->HasError()); |
| 60 } |
| 61 |
| 62 AvatarButtonErrorController::AvatarSyncErrorController:: |
| 63 AvatarSyncErrorController( |
| 64 Profile* profile, |
| 65 AvatarButtonErrorController* avatar_button_error_controller) |
| 66 : profile_(profile), |
| 67 avatar_button_error_controller_(avatar_button_error_controller) { |
| 68 SyncErrorController* sync_error_controller = GetSyncErrorControllerIfNeeded(); |
| 69 if (sync_error_controller) |
| 70 sync_error_controller->AddObserver(this); |
| 71 } |
| 72 |
| 73 AvatarButtonErrorController::AvatarSyncErrorController:: |
| 74 ~AvatarSyncErrorController() { |
| 75 SyncErrorController* sync_error_controller = GetSyncErrorControllerIfNeeded(); |
| 76 if (sync_error_controller) |
| 77 sync_error_controller->RemoveObserver(this); |
| 78 } |
| 79 |
| 80 void AvatarButtonErrorController::AvatarSyncErrorController::OnErrorChanged() { |
| 81 ProfileSyncService* sync_service = |
| 82 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 83 if (switches::IsMaterialDesignUserMenu() && sync_service) { |
| 84 SyncErrorController* sync_error_controller = |
| 85 sync_service->sync_error_controller(); |
| 86 ProfileSyncService::Status status; |
| 87 sync_service->QueryDetailedSyncStatus(&status); |
| 88 avatar_button_error_controller_->UpdateSyncError( |
| 89 sync_service->HasUnrecoverableError() || |
| 90 status.sync_protocol_error.action == syncer::UPGRADE_CLIENT || |
| 91 (sync_error_controller && sync_error_controller->HasError())); |
| 92 } else { |
| 93 avatar_button_error_controller_->UpdateSyncError(false); |
| 94 } |
| 95 } |
| 96 |
| 97 SyncErrorController* AvatarButtonErrorController::AvatarSyncErrorController:: |
| 98 GetSyncErrorControllerIfNeeded() { |
| 99 if (!switches::IsMaterialDesignUserMenu()) |
| 100 return nullptr; |
| 101 ProfileSyncService* sync_service = |
| 102 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 103 return sync_service ? sync_service->sync_error_controller() : nullptr; |
| 104 } |
| OLD | NEW |