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