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