| 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_metrics.h" | 7 #include "components/signin/core/browser/signin_metrics.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 it != provider_set_.end(); ++it) { | 57 it != provider_set_.end(); ++it) { |
| 58 GoogleServiceAuthError error = (*it)->GetAuthStatus(); | 58 GoogleServiceAuthError error = (*it)->GetAuthStatus(); |
| 59 | 59 |
| 60 // Ignore the states we don't want to elevate to the user. | 60 // Ignore the states we don't want to elevate to the user. |
| 61 if (error.state() == GoogleServiceAuthError::NONE || | 61 if (error.state() == GoogleServiceAuthError::NONE || |
| 62 error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { | 62 error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { |
| 63 continue; | 63 continue; |
| 64 } | 64 } |
| 65 | 65 |
| 66 std::string account_id = (*it)->GetAccountId(); | 66 std::string account_id = (*it)->GetAccountId(); |
| 67 std::string username = (*it)->GetUsername(); | |
| 68 | 67 |
| 69 // Prioritize this error if it matches the previous |auth_error_|. | 68 // Prioritize this error if it matches the previous |auth_error_|. |
| 70 if (error.state() == prev_state && account_id == prev_account_id) { | 69 if (error.state() == prev_state && account_id == prev_account_id) { |
| 71 auth_error_ = error; | 70 auth_error_ = error; |
| 72 error_account_id_ = account_id; | 71 error_account_id_ = account_id; |
| 73 error_username_ = username; | |
| 74 error_changed = true; | 72 error_changed = true; |
| 75 break; | 73 break; |
| 76 } | 74 } |
| 77 | 75 |
| 78 // Use this error if we haven't found one already, but keep looking for the | 76 // Use this error if we haven't found one already, but keep looking for the |
| 79 // previous |auth_error_| in case there's a match elsewhere in the set. | 77 // previous |auth_error_| in case there's a match elsewhere in the set. |
| 80 if (!error_changed) { | 78 if (!error_changed) { |
| 81 auth_error_ = error; | 79 auth_error_ = error; |
| 82 error_account_id_ = account_id; | 80 error_account_id_ = account_id; |
| 83 error_username_ = username; | |
| 84 error_changed = true; | 81 error_changed = true; |
| 85 } | 82 } |
| 86 } | 83 } |
| 87 | 84 |
| 88 if (!error_changed && prev_state != GoogleServiceAuthError::NONE) { | 85 if (!error_changed && prev_state != GoogleServiceAuthError::NONE) { |
| 89 // No provider reported an error, so clear the error we have now. | 86 // No provider reported an error, so clear the error we have now. |
| 90 auth_error_ = GoogleServiceAuthError::AuthErrorNone(); | 87 auth_error_ = GoogleServiceAuthError::AuthErrorNone(); |
| 91 error_account_id_.clear(); | 88 error_account_id_.clear(); |
| 92 error_username_.clear(); | |
| 93 error_changed = true; | 89 error_changed = true; |
| 94 } | 90 } |
| 95 | 91 |
| 96 if (error_changed) { | 92 if (error_changed) { |
| 97 signin_metrics::LogAuthError(auth_error_.state()); | 93 signin_metrics::LogAuthError(auth_error_.state()); |
| 98 FOR_EACH_OBSERVER(Observer, observer_list_, OnErrorChanged()); | 94 FOR_EACH_OBSERVER(Observer, observer_list_, OnErrorChanged()); |
| 99 } | 95 } |
| 100 } | 96 } |
| 101 | 97 |
| 102 bool SigninErrorController::HasError() const { | 98 bool SigninErrorController::HasError() const { |
| 103 return auth_error_.state() != GoogleServiceAuthError::NONE && | 99 return auth_error_.state() != GoogleServiceAuthError::NONE && |
| 104 auth_error_.state() != GoogleServiceAuthError::CONNECTION_FAILED; | 100 auth_error_.state() != GoogleServiceAuthError::CONNECTION_FAILED; |
| 105 } | 101 } |
| 106 | 102 |
| 107 void SigninErrorController::AddObserver(Observer* observer) { | 103 void SigninErrorController::AddObserver(Observer* observer) { |
| 108 observer_list_.AddObserver(observer); | 104 observer_list_.AddObserver(observer); |
| 109 } | 105 } |
| 110 | 106 |
| 111 void SigninErrorController::RemoveObserver(Observer* observer) { | 107 void SigninErrorController::RemoveObserver(Observer* observer) { |
| 112 observer_list_.RemoveObserver(observer); | 108 observer_list_.RemoveObserver(observer); |
| 113 } | 109 } |
| OLD | NEW |