Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / signin / core / browser / signin_error_controller.h
blobd0e17c06f9f0f0752f914a2a6c0d249a8c97f5b9
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 // API invoked by SigninErrorController to get the current auth status of
30 // the various signed in services.
31 virtual GoogleServiceAuthError GetAuthStatus() const = 0;
34 // The observer class for SigninErrorController lets the controller notify
35 // observers when an error arises or changes.
36 class Observer {
37 public:
38 virtual ~Observer() {}
39 virtual void OnErrorChanged() = 0;
42 SigninErrorController();
43 ~SigninErrorController() override;
45 // Adds a provider which the SigninErrorController object will start querying
46 // for auth status.
47 void AddProvider(const AuthStatusProvider* provider);
49 // Removes a provider previously added by SigninErrorController (generally
50 // only called in preparation for shutdown).
51 void RemoveProvider(const AuthStatusProvider* provider);
53 // Invoked when the auth status of an AuthStatusProvider has changed.
54 void AuthStatusChanged();
56 // True if there exists an error worth elevating to the user.
57 bool HasError() const;
59 void AddObserver(Observer* observer);
60 void RemoveObserver(Observer* observer);
62 const std::string& error_account_id() const { return error_account_id_; }
63 const GoogleServiceAuthError& auth_error() const { return auth_error_; }
65 private:
66 std::set<const AuthStatusProvider*> provider_set_;
68 // The account that generated the last auth error.
69 std::string error_account_id_;
71 // The auth error detected the last time AuthStatusChanged() was invoked (or
72 // NONE if AuthStatusChanged() has never been invoked).
73 GoogleServiceAuthError auth_error_;
75 base::ObserverList<Observer, false> observer_list_;
77 DISALLOW_COPY_AND_ASSIGN(SigninErrorController);
80 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_ERROR_CONTROLLER_H_