[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / signin / chrome_signin_client.h
blob2ce7c355802b838a6625e9ad2658fe96892eec03
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 CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_
6 #define CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_
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/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/render_process_host_observer.h"
16 class CookieSettings;
17 class Profile;
19 class ChromeSigninClient : public SigninClient,
20 public KeyedService,
21 public content::NotificationObserver,
22 public content::RenderProcessHostObserver {
23 public:
24 explicit ChromeSigninClient(Profile* profile);
25 virtual ~ChromeSigninClient();
27 // Utility methods.
28 static bool ProfileAllowsSigninCookies(Profile* profile);
29 static bool SettingsAllowSigninCookies(CookieSettings* cookie_settings);
31 // Tracks the privileged signin process identified by |host_id| so that we
32 // can later ask (via IsSigninProcess) if it is safe to sign the user in from
33 // the current context (see OneClickSigninHelper). All of this tracking
34 // state is reset once the renderer process terminates.
36 // N.B. This is the id returned by RenderProcessHost::GetID().
37 // TODO(guohui): Eliminate these APIs once the web-based signin flow is
38 // replaced by a native flow. crbug.com/347247
39 void SetSigninProcess(int host_id);
40 void ClearSigninProcess();
41 bool IsSigninProcess(int host_id) const;
42 bool HasSigninProcess() const;
44 // content::RenderProcessHostObserver implementation.
45 virtual void RenderProcessHostDestroyed(content::RenderProcessHost* host)
46 OVERRIDE;
48 // SigninClient implementation.
49 virtual PrefService* GetPrefs() OVERRIDE;
50 virtual scoped_refptr<TokenWebData> GetDatabase() OVERRIDE;
51 virtual bool CanRevokeCredentials() OVERRIDE;
52 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE;
53 virtual bool ShouldMergeSigninCredentialsIntoCookieJar() OVERRIDE;
55 // Returns a string describing the chrome version environment. Version format:
56 // <Build Info> <OS> <Version number> (<Last change>)<channel or "-devel">
57 // If version information is unavailable, returns "invalid."
58 virtual std::string GetProductVersion() OVERRIDE;
59 virtual void SetCookieChangedCallback(const CookieChangedCallback& callback)
60 OVERRIDE;
61 virtual void GoogleSigninSucceeded(const std::string& username,
62 const std::string& password) OVERRIDE;
64 // content::NotificationObserver implementation.
65 virtual void Observe(int type,
66 const content::NotificationSource& source,
67 const content::NotificationDetails& details) OVERRIDE;
69 private:
70 void RegisterForCookieChangedNotification();
71 void UnregisterForCookieChangedNotification();
73 Profile* profile_;
74 content::NotificationRegistrar registrar_;
76 // The callback that if non-empty will be called when notifications about
77 // cookie changes are received.
78 CookieChangedCallback callback_;
80 // See SetSigninProcess. Tracks the currently active signin process
81 // by ID, if there is one.
82 int signin_host_id_;
84 // The RenderProcessHosts being observed.
85 std::set<content::RenderProcessHost*> signin_hosts_observed_;
87 DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient);
90 #endif // CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_