Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / chrome_signin_client.h
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/keyed_service/core/keyed_service.h"
11 #include "components/signin/core/browser/signin_client.h"
12 #include "content/public/browser/render_process_host_observer.h"
13
14 class CookieSettings;
15 class Profile;
16
17 class ChromeSigninClient : public SigninClient,
18                            public KeyedService,
19                            public content::RenderProcessHostObserver {
20  public:
21   explicit ChromeSigninClient(Profile* profile);
22   virtual ~ChromeSigninClient();
23
24   // Utility methods.
25   static bool ProfileAllowsSigninCookies(Profile* profile);
26   static bool SettingsAllowSigninCookies(CookieSettings* cookie_settings);
27
28   // Tracks the privileged signin process identified by |host_id| so that we
29   // can later ask (via IsSigninProcess) if it is safe to sign the user in from
30   // the current context (see OneClickSigninHelper).  All of this tracking
31   // state is reset once the renderer process terminates.
32   //
33   // N.B. This is the id returned by RenderProcessHost::GetID().
34   // TODO(guohui): Eliminate these APIs once the web-based signin flow is
35   // replaced by a native flow. crbug.com/347247
36   void SetSigninProcess(int host_id);
37   void ClearSigninProcess();
38   bool IsSigninProcess(int host_id) const;
39   bool HasSigninProcess() const;
40
41   // content::RenderProcessHostObserver implementation.
42   virtual void RenderProcessHostDestroyed(content::RenderProcessHost* host)
43       OVERRIDE;
44
45   // SigninClient implementation.
46   virtual PrefService* GetPrefs() OVERRIDE;
47   virtual scoped_refptr<TokenWebData> GetDatabase() OVERRIDE;
48   virtual bool CanRevokeCredentials() OVERRIDE;
49   virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
50   virtual void GoogleSigninSucceeded(const std::string& username,
51                                      const std::string& password) OVERRIDE;
52
53  private:
54   Profile* profile_;
55
56   // See SetSigninProcess. Tracks the currently active signin process
57   // by ID, if there is one.
58   int signin_host_id_;
59
60   // The RenderProcessHosts being observed.
61   std::set<content::RenderProcessHost*> signin_hosts_observed_;
62
63   DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient);
64 };
65
66 #endif  // CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_