Home | History | Annotate | Download | only in signin
      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 GlobalError {
     22  public:
     23   class AuthStatusProvider {
     24    public:
     25     AuthStatusProvider();
     26     virtual ~AuthStatusProvider();
     27 
     28     // API invoked by SigninGlobalError to get the current auth status of
     29     // the various signed in services.
     30     virtual GoogleServiceAuthError GetAuthStatus() const = 0;
     31   };
     32 
     33   SigninGlobalError(Profile* profile);
     34   virtual ~SigninGlobalError();
     35 
     36   // Adds a provider which the SigninGlobalError object will start querying for
     37   // auth status.
     38   void AddProvider(const AuthStatusProvider* provider);
     39 
     40   // Removes a provider previously added by SigninGlobalError (generally only
     41   // called in preparation for shutdown).
     42   void RemoveProvider(const AuthStatusProvider* provider);
     43 
     44   // Invoked when the auth status of an AuthStatusProvider has changed.
     45   void AuthStatusChanged();
     46 
     47   GoogleServiceAuthError GetLastAuthError() const { return auth_error_; }
     48 
     49   // GlobalError implementation.
     50   virtual bool HasMenuItem() OVERRIDE;
     51   virtual int MenuItemCommandID() OVERRIDE;
     52   virtual string16 MenuItemLabel() OVERRIDE;
     53   virtual void ExecuteMenuItem(Browser* browser) OVERRIDE;
     54   virtual bool HasBubbleView() OVERRIDE;
     55   virtual string16 GetBubbleViewTitle() OVERRIDE;
     56   virtual std::vector<string16> GetBubbleViewMessages() OVERRIDE;
     57   virtual string16 GetBubbleViewAcceptButtonLabel() OVERRIDE;
     58   virtual string16 GetBubbleViewCancelButtonLabel() OVERRIDE;
     59   virtual void OnBubbleViewDidClose(Browser* browser) OVERRIDE;
     60   virtual void BubbleViewAcceptButtonPressed(Browser* browser) OVERRIDE;
     61   virtual void BubbleViewCancelButtonPressed(Browser* browser) OVERRIDE;
     62 
     63   // Returns the SigninGlobalError instance for the given profile.
     64   static SigninGlobalError* GetForProfile(Profile* profile);
     65 
     66  private:
     67   std::set<const AuthStatusProvider*> provider_set_;
     68 
     69   // The auth error detected the last time AuthStatusChanged() was invoked (or
     70   // NONE if AuthStatusChanged() has never been invoked).
     71   GoogleServiceAuthError auth_error_;
     72 
     73   // The Profile this object belongs to.
     74   Profile* profile_;
     75 };
     76 
     77 #endif  // CHROME_BROWSER_SIGNIN_SIGNIN_GLOBAL_ERROR_H_
     78