1 // Copyright (c) 2013 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. 4 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_GLOBAL_ERROR_H_ 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_GLOBAL_ERROR_H_ 7 8 #include <set> 9 #include "base/basictypes.h" 10 #include "base/compiler_specific.h" 11 #include "chrome/browser/ui/global_error/global_error.h" 12 #include "google_apis/gaia/google_service_auth_error.h" 13 14 class Profile; 15 16 // Shows auth errors on the wrench menu using a bubble view and a 17 // menu item. Services that wish to expose auth errors to the user should 18 // register an AuthStatusProvider to report their current authentication state, 19 // and should invoke AuthStatusChanged() when their authentication state may 20 // have changed. 21 class SigninGlobalError : public GlobalErrorWithStandardBubble { 22 public: 23 class AuthStatusProvider { 24 public: 25 AuthStatusProvider(); 26 virtual ~AuthStatusProvider(); 27 28 // Returns the account id with the status specified by GetAuthStatus(). 29 virtual std::string GetAccountId() const = 0; 30 31 // API invoked by SigninGlobalError to get the current auth status of 32 // the various signed in services. 33 virtual GoogleServiceAuthError GetAuthStatus() const = 0; 34 }; 35 36 explicit SigninGlobalError(Profile* profile); 37 virtual ~SigninGlobalError(); 38 39 // Adds a provider which the SigninGlobalError object will start querying for 40 // auth status. 41 void AddProvider(const AuthStatusProvider* provider); 42 43 // Removes a provider previously added by SigninGlobalError (generally only 44 // called in preparation for shutdown). 45 void RemoveProvider(const AuthStatusProvider* provider); 46 47 // Invoked when the auth status of an AuthStatusProvider has changed. 48 void AuthStatusChanged(); 49 50 std::string GetAccountIdOfLastAuthError() const { return account_id_; } 51 52 GoogleServiceAuthError GetLastAuthError() const { return auth_error_; } 53 54 // GlobalError implementation. 55 virtual bool HasMenuItem() OVERRIDE; 56 virtual int MenuItemCommandID() OVERRIDE; 57 virtual base::string16 MenuItemLabel() OVERRIDE; 58 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; 59 virtual bool HasBubbleView() OVERRIDE; 60 virtual base::string16 GetBubbleViewTitle() OVERRIDE; 61 virtual std::vector<base::string16> GetBubbleViewMessages() OVERRIDE; 62 virtual base::string16 GetBubbleViewAcceptButtonLabel() OVERRIDE; 63 virtual base::string16 GetBubbleViewCancelButtonLabel() OVERRIDE; 64 virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE; 65 virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE; 66 virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE; 67 68 // Returns the SigninGlobalError instance for the given profile. 69 static SigninGlobalError* GetForProfile(Profile* profile); 70 71 private: 72 std::set<const AuthStatusProvider*> provider_set_; 73 74 // The account that generated the last auth error. 75 std::string account_id_; 76 77 // The auth error detected the last time AuthStatusChanged() was invoked (or 78 // NONE if AuthStatusChanged() has never been invoked). 79 GoogleServiceAuthError auth_error_; 80 81 // The Profile this object belongs to. 82 Profile* profile_; 83 }; 84 85 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_GLOBAL_ERROR_H_ 86