Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / signin / chrome_signin_client.h
blob209a62c32f70417afbc84a61855d9f3e43b3d1a3
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/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"
15 class CookieSettings;
16 class Profile;
18 class ChromeSigninClient : public SigninClient,
19 public content::NotificationObserver,
20 public content::RenderProcessHostObserver {
21 public:
22 explicit ChromeSigninClient(Profile* profile);
23 virtual ~ChromeSigninClient();
25 // Utility methods.
26 static bool ProfileAllowsSigninCookies(Profile* profile);
27 static bool SettingsAllowSigninCookies(CookieSettings* cookie_settings);
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.
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;
42 // content::RenderProcessHostObserver implementation.
43 virtual void RenderProcessHostDestroyed(content::RenderProcessHost* host)
44 override;
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 OnSignedOut() override;
52 virtual net::URLRequestContextGetter* GetURLRequestContext() override;
53 virtual bool ShouldMergeSigninCredentialsIntoCookieJar() override;
54 virtual bool IsFirstRun() const override;
55 virtual base::Time GetInstallDate() override;
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;
67 // content::NotificationObserver implementation.
68 virtual void Observe(int type,
69 const content::NotificationSource& source,
70 const content::NotificationDetails& details) override;
72 private:
73 void RegisterForCookieChangedNotification();
74 void UnregisterForCookieChangedNotification();
76 Profile* profile_;
77 content::NotificationRegistrar registrar_;
79 // The callbacks that will be called when notifications about cookie changes
80 // are received.
81 base::CallbackList<void(const net::CanonicalCookie* cookie)> callbacks_;
83 // See SetSigninProcess. Tracks the currently active signin process
84 // by ID, if there is one.
85 int signin_host_id_;
87 // The RenderProcessHosts being observed.
88 std::set<content::RenderProcessHost*> signin_hosts_observed_;
90 DISALLOW_COPY_AND_ASSIGN(ChromeSigninClient);
93 #endif // CHROME_BROWSER_SIGNIN_CHROME_SIGNIN_CLIENT_H_