Add abhijeet.k@samsung.com to AUTHORS list.
[chromium-blink-merge.git] / components / signin / core / browser / signin_error_controller.h
blob368b916a84eae7162bb245b7adff0e97964e2f52
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_
8 #include <set>
9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h"
11 #include "base/observer_list.h"
12 #include "components/keyed_service/core/keyed_service.h"
13 #include "google_apis/gaia/google_service_auth_error.h"
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
17 // AuthStatusProvider to report their current authentication state, and should
18 // invoke AuthStatusChanged() when their authentication state may have changed.
19 class SigninErrorController : public KeyedService {
20 public:
21 class AuthStatusProvider {
22 public:
23 AuthStatusProvider();
24 virtual ~AuthStatusProvider();
26 // Returns the account id with the status specified by GetAuthStatus().
27 virtual std::string GetAccountId() const = 0;
29 // Returns the username with the status specified by GetAuthStatus().
30 virtual std::string GetUsername() const = 0;
32 // API invoked by SigninErrorController to get the current auth status of
33 // the various signed in services.
34 virtual GoogleServiceAuthError GetAuthStatus() const = 0;
37 // The observer class for SigninErrorController lets the controller notify
38 // observers when an error arises or changes.
39 class Observer {
40 public:
41 virtual ~Observer() {}
42 virtual void OnErrorChanged() = 0;
45 SigninErrorController();
46 ~SigninErrorController() override;
48 // Adds a provider which the SigninErrorController object will start querying
49 // for auth status.
50 void AddProvider(const AuthStatusProvider* provider);
52 // Removes a provider previously added by SigninErrorController (generally
53 // only called in preparation for shutdown).
54 void RemoveProvider(const AuthStatusProvider* provider);
56 // Invoked when the auth status of an AuthStatusProvider has changed.
57 void AuthStatusChanged();
59 // True if there exists an error worth elevating to the user.
60 bool HasError() const;
62 void AddObserver(Observer* observer);
63 void RemoveObserver(Observer* observer);
65 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_; }
69 private:
70 std::set<const AuthStatusProvider*> provider_set_;
72 // The account that generated the last auth error.
73 std::string error_account_id_;
74 std::string error_username_;
76 // The auth error detected the last time AuthStatusChanged() was invoked (or
77 // NONE if AuthStatusChanged() has never been invoked).
78 GoogleServiceAuthError auth_error_;
80 ObserverList<Observer, false> observer_list_;
82 DISALLOW_COPY_AND_ASSIGN(SigninErrorController);
85 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_