Home | History | Annotate | Download | only in signin
      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.
      4 
      5 #ifndef CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_
      6 #define CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "components/signin/core/browser/signin_client.h"
     11 #include "content/public/browser/notification_observer.h"
     12 #include "content/public/browser/notification_registrar.h"
     13 #include "content/public/browser/render_process_host_observer.h"
     14 
     15 class CookieSettings;
     16 class Profile;
     17 
     18 class ChromeSigninClient : public SigninClient,
     19                            public content::NotificationObserver,
     20                            public content::RenderProcessHostObserver {
     21  public:
     22   explicit ChromeSigninClient(Profile* profile);
     23   virtual ~ChromeSigninClient();
     24 
     25   // Utility methods.
     26   static bool ProfileAllowsSigninCookies(Profile* profile);
     27   static bool SettingsAllowSigninCookies(CookieSettings* cookie_settings);
     28 
     29   // Tracks the privileged signin process identified by |host_id| so that we
     30   // can later ask (via IsSigninProcess) if it is safe to sign the user in from
     31   // the current context (see OneClickSigninHelper).  All of this tracking
     32   // state is reset once the renderer process terminates.
     33   //
     34   // N.B. This is the id returned by RenderProcessHost::GetID().
     35   // TODO(guohui): Eliminate these APIs once the web-based signin flow is
     36   // replaced by a native flow. crbug.com/347247
     37   virtual void SetSigninProcess(int host_id) OVERRIDE;
     38   virtual void ClearSigninProcess() OVERRIDE;
     39   virtual bool IsSigninProcess(int host_id) const OVERRIDE;
     40   virtual bool HasSigninProcess() const OVERRIDE;
     41 
     42   // content::RenderProcessHostObserver implementation.
     43   virtual void RenderProcessHostDestroyed(content::RenderProcessHost* host)
     44       OVERRIDE;
     45 
     46   // SigninClient implementation.
     47   virtual PrefService* GetPrefs() OVERRIDE;
     48   virtual scoped_refptr<TokenWebData> GetDatabase() OVERRIDE;
     49   virtual bool CanRevokeCredentials() OVERRIDE;
     50   virtual std::string GetSigninScopedDeviceId() OVERRIDE;
     51   virtual void ClearSigninScopedDeviceId() OVERRIDE;
     52   virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
     53   virtual bool ShouldMergeSigninCredentialsIntoCookieJar() OVERRIDE;
     54   virtual bool IsFirstRun() const OVERRIDE;
     55   virtual base::Time GetInstallDate() OVERRIDE;
     56 
     57   // Returns a string describing the chrome version environment. Version format:
     58   // <Build Info> <OS> <Version number> (<Last change>)<channel or "-devel">
     59   // If version information is unavailable, returns "invalid."
     60   virtual std::string GetProductVersion() OVERRIDE;
     61   virtual scoped_ptr<CookieChangedCallbackList::Subscription>
     62       AddCookieChangedCallback(const CookieChangedCallback& callback) OVERRIDE;
     63   virtual void GoogleSigninSucceeded(const std::string& account_id,
     64                                      const std::string& username,
     65                                      const std::string& password) OVERRIDE;
     66 
     67   // content::NotificationObserver implementation.
     68   virtual void Observe(int type,
     69                        const content::NotificationSource& source,
     70                        const content::NotificationDetails& details) OVERRIDE;
     71 
     72  private:
     73   void RegisterForCookieChangedNotification();
     74   void UnregisterForCookieChangedNotification();
     75 
     76   Profile* profile_;
     77   content::NotificationRegistrar registrar_;
     78 
     79   // The callbacks that will be called when notifications about cookie changes
     80   // are received.
     81   base::CallbackList<void(const net::CanonicalCookie* cookie)> callbacks_;
     82 
     83   // See SetSigninProcess. Tracks the currently active signin process
     84   // by ID, if there is one.
     85   int signin_host_id_;
     86 
     87   // The RenderProcessHosts being observed.
     88   std::set<content::RenderProcessHost*> signin_hosts_observed_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient);
     91 };
     92 
     93 #endif  // CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_
     94