OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/signin/core/browser/signin_error_controller.h" | 5 #include "components/signin/core/browser/signin_error_controller.h" |
6 | 6 |
| 7 #include "components/signin/core/browser/signin_client.h" |
| 8 #include "components/signin/core/browser/signin_metrics.h" |
| 9 |
7 namespace { | 10 namespace { |
8 | 11 |
9 typedef std::set<const SigninErrorController::AuthStatusProvider*> | 12 typedef std::set<const SigninErrorController::AuthStatusProvider*> |
10 AuthStatusProviderSet; | 13 AuthStatusProviderSet; |
11 | 14 |
12 } // namespace | 15 } // namespace |
13 | 16 |
14 SigninErrorController::AuthStatusProvider::AuthStatusProvider() { | 17 SigninErrorController::AuthStatusProvider::AuthStatusProvider() { |
15 } | 18 } |
16 | 19 |
17 SigninErrorController::AuthStatusProvider::~AuthStatusProvider() { | 20 SigninErrorController::AuthStatusProvider::~AuthStatusProvider() { |
18 } | 21 } |
19 | 22 |
20 SigninErrorController::SigninErrorController() | 23 SigninErrorController::SigninErrorController(SigninClient* signin_client) |
21 : auth_error_(GoogleServiceAuthError::AuthErrorNone()) { | 24 : auth_error_(GoogleServiceAuthError::AuthErrorNone()) { |
| 25 AddObserver(signin_client); |
22 } | 26 } |
23 | 27 |
24 SigninErrorController::~SigninErrorController() { | 28 SigninErrorController::~SigninErrorController() { |
25 DCHECK(provider_set_.empty()) | 29 DCHECK(provider_set_.empty()) |
26 << "All AuthStatusProviders should be unregistered before" | 30 << "All AuthStatusProviders should be unregistered before" |
27 << " SigninErrorController::Shutdown() is called"; | 31 << " SigninErrorController::Shutdown() is called"; |
28 } | 32 } |
29 | 33 |
30 void SigninErrorController::AddProvider(const AuthStatusProvider* provider) { | 34 void SigninErrorController::AddProvider(const AuthStatusProvider* provider) { |
31 DCHECK(provider_set_.find(provider) == provider_set_.end()) | 35 DCHECK(provider_set_.find(provider) == provider_set_.end()) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 89 |
86 if (!error_changed && prev_state != GoogleServiceAuthError::NONE) { | 90 if (!error_changed && prev_state != GoogleServiceAuthError::NONE) { |
87 // No provider reported an error, so clear the error we have now. | 91 // No provider reported an error, so clear the error we have now. |
88 auth_error_ = GoogleServiceAuthError::AuthErrorNone(); | 92 auth_error_ = GoogleServiceAuthError::AuthErrorNone(); |
89 error_account_id_.clear(); | 93 error_account_id_.clear(); |
90 error_username_.clear(); | 94 error_username_.clear(); |
91 error_changed = true; | 95 error_changed = true; |
92 } | 96 } |
93 | 97 |
94 if (error_changed) { | 98 if (error_changed) { |
| 99 signin_metrics::LogAuthError(auth_error_.state()); |
95 FOR_EACH_OBSERVER(Observer, observer_list_, OnErrorChanged()); | 100 FOR_EACH_OBSERVER(Observer, observer_list_, OnErrorChanged()); |
96 } | 101 } |
97 } | 102 } |
98 | 103 |
99 bool SigninErrorController::HasError() const { | 104 bool SigninErrorController::HasError() const { |
100 return auth_error_.state() != GoogleServiceAuthError::NONE && | 105 return auth_error_.state() != GoogleServiceAuthError::NONE && |
101 auth_error_.state() != GoogleServiceAuthError::CONNECTION_FAILED; | 106 auth_error_.state() != GoogleServiceAuthError::CONNECTION_FAILED; |
102 } | 107 } |
103 | 108 |
104 void SigninErrorController::AddObserver(Observer* observer) { | 109 void SigninErrorController::AddObserver(Observer* observer) { |
105 observer_list_.AddObserver(observer); | 110 observer_list_.AddObserver(observer); |
106 } | 111 } |
107 | 112 |
108 void SigninErrorController::RemoveObserver(Observer* observer) { | 113 void SigninErrorController::RemoveObserver(Observer* observer) { |
109 observer_list_.RemoveObserver(observer); | 114 observer_list_.RemoveObserver(observer); |
110 } | 115 } |
OLD | NEW |