| 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 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_ | 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_ |
| 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_ | 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 13 #include "google_apis/gaia/google_service_auth_error.h" | 13 #include "google_apis/gaia/google_service_auth_error.h" |
| 14 | 14 |
| 15 // Keep track of auth errors and expose them to observers in the UI. Services | 15 // Keep track of auth errors and expose them to observers in the UI. Services |
| 16 // that wish to expose auth errors to the user should register an | 16 // that wish to expose auth errors to the user should register an |
| 17 // AuthStatusProvider to report their current authentication state, and should | 17 // AuthStatusProvider to report their current authentication state, and should |
| 18 // invoke AuthStatusChanged() when their authentication state may have changed. | 18 // invoke AuthStatusChanged() when their authentication state may have changed. |
| 19 class SigninErrorController : public KeyedService { | 19 class SigninErrorController : public KeyedService { |
| 20 public: | 20 public: |
| 21 class AuthStatusProvider { | 21 class AuthStatusProvider { |
| 22 public: | 22 public: |
| 23 AuthStatusProvider(); | 23 AuthStatusProvider(); |
| 24 virtual ~AuthStatusProvider(); | 24 virtual ~AuthStatusProvider(); |
| 25 | 25 |
| 26 // Returns the account id with the status specified by GetAuthStatus(). | 26 // Returns the account id with the status specified by GetAuthStatus(). |
| 27 virtual std::string GetAccountId() const = 0; | 27 virtual std::string GetAccountId() const = 0; |
| 28 | 28 |
| 29 // Returns the username with the status specified by GetAuthStatus(). | |
| 30 virtual std::string GetUsername() const = 0; | |
| 31 | |
| 32 // API invoked by SigninErrorController to get the current auth status of | 29 // API invoked by SigninErrorController to get the current auth status of |
| 33 // the various signed in services. | 30 // the various signed in services. |
| 34 virtual GoogleServiceAuthError GetAuthStatus() const = 0; | 31 virtual GoogleServiceAuthError GetAuthStatus() const = 0; |
| 35 }; | 32 }; |
| 36 | 33 |
| 37 // The observer class for SigninErrorController lets the controller notify | 34 // The observer class for SigninErrorController lets the controller notify |
| 38 // observers when an error arises or changes. | 35 // observers when an error arises or changes. |
| 39 class Observer { | 36 class Observer { |
| 40 public: | 37 public: |
| 41 virtual ~Observer() {} | 38 virtual ~Observer() {} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 // Invoked when the auth status of an AuthStatusProvider has changed. | 53 // Invoked when the auth status of an AuthStatusProvider has changed. |
| 57 void AuthStatusChanged(); | 54 void AuthStatusChanged(); |
| 58 | 55 |
| 59 // True if there exists an error worth elevating to the user. | 56 // True if there exists an error worth elevating to the user. |
| 60 bool HasError() const; | 57 bool HasError() const; |
| 61 | 58 |
| 62 void AddObserver(Observer* observer); | 59 void AddObserver(Observer* observer); |
| 63 void RemoveObserver(Observer* observer); | 60 void RemoveObserver(Observer* observer); |
| 64 | 61 |
| 65 const std::string& error_account_id() const { return error_account_id_; } | 62 const std::string& error_account_id() const { return error_account_id_; } |
| 66 const std::string& error_username() const { return error_username_; } | |
| 67 const GoogleServiceAuthError& auth_error() const { return auth_error_; } | 63 const GoogleServiceAuthError& auth_error() const { return auth_error_; } |
| 68 | 64 |
| 69 private: | 65 private: |
| 70 std::set<const AuthStatusProvider*> provider_set_; | 66 std::set<const AuthStatusProvider*> provider_set_; |
| 71 | 67 |
| 72 // The account that generated the last auth error. | 68 // The account that generated the last auth error. |
| 73 std::string error_account_id_; | 69 std::string error_account_id_; |
| 74 std::string error_username_; | |
| 75 | 70 |
| 76 // The auth error detected the last time AuthStatusChanged() was invoked (or | 71 // The auth error detected the last time AuthStatusChanged() was invoked (or |
| 77 // NONE if AuthStatusChanged() has never been invoked). | 72 // NONE if AuthStatusChanged() has never been invoked). |
| 78 GoogleServiceAuthError auth_error_; | 73 GoogleServiceAuthError auth_error_; |
| 79 | 74 |
| 80 ObserverList<Observer, false> observer_list_; | 75 ObserverList<Observer, false> observer_list_; |
| 81 | 76 |
| 82 DISALLOW_COPY_AND_ASSIGN(SigninErrorController); | 77 DISALLOW_COPY_AND_ASSIGN(SigninErrorController); |
| 83 }; | 78 }; |
| 84 | 79 |
| 85 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_ | 80 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_ |
| OLD | NEW |