Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/signin/chrome_signin_client.cc

Issue 695553002: Account reconcilor: Use cookie store cookie changed subscription. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid UI/IO thread ping-pong Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/signin/chrome_signin_client.h" 5 #include "chrome/browser/signin/chrome_signin_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/content_settings/cookie_settings.h" 12 #include "chrome/browser/content_settings/cookie_settings.h"
13 #include "chrome/browser/net/chrome_cookie_notification_details.h" 13 #include "chrome/browser/net/chrome_cookie_notification_details.h"
14 #include "chrome/browser/profiles/profile_info_cache.h" 14 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/signin/local_auth.h" 16 #include "chrome/browser/signin/local_auth.h"
17 #include "chrome/browser/signin/signin_cookie_changed_subscription.h"
17 #include "chrome/browser/webdata/web_data_service_factory.h" 18 #include "chrome/browser/webdata/web_data_service_factory.h"
18 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
19 #include "components/metrics/metrics_service.h" 20 #include "components/metrics/metrics_service.h"
20 #include "components/signin/core/common/profile_management_switches.h" 21 #include "components/signin/core/common/profile_management_switches.h"
21 #include "components/signin/core/common/signin_pref_names.h" 22 #include "components/signin/core/common/signin_pref_names.h"
22 #include "components/signin/core/common/signin_switches.h" 23 #include "components/signin/core/common/signin_switches.h"
23 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_source.h" 25 #include "content/public/browser/notification_source.h"
droger 2014/11/04 10:31:36 Do we need these includes?
msarda 2014/11/04 12:06:06 Done.
25 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
26 #include "content/public/common/child_process_host.h" 27 #include "content/public/common/child_process_host.h"
28 #include "net/url_request/url_request_context_getter.h"
27 #include "url/gurl.h" 29 #include "url/gurl.h"
28 30
29 #if defined(ENABLE_MANAGED_USERS) 31 #if defined(ENABLE_MANAGED_USERS)
30 #include "chrome/browser/supervised_user/supervised_user_constants.h" 32 #include "chrome/browser/supervised_user/supervised_user_constants.h"
31 #endif 33 #endif
32 34
33 #if defined(OS_CHROMEOS) 35 #if defined(OS_CHROMEOS)
34 #include "components/user_manager/user_manager.h" 36 #include "components/user_manager/user_manager.h"
35 #endif 37 #endif
36 38
37 #if !defined(OS_ANDROID) 39 #if !defined(OS_ANDROID)
38 #include "chrome/browser/first_run/first_run.h" 40 #include "chrome/browser/first_run/first_run.h"
39 #endif 41 #endif
40 42
41 using content::ChildProcessHost; 43 using content::ChildProcessHost;
42 using content::RenderProcessHost; 44 using content::RenderProcessHost;
43 45
44 namespace { 46 namespace {
45 47
46 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; 48 const char kGoogleAccountsUrl[] = "https://accounts.google.com";
47 49
48 } // namespace 50 } // namespace
49 51
50 ChromeSigninClient::ChromeSigninClient(Profile* profile) 52 ChromeSigninClient::ChromeSigninClient(Profile* profile)
51 : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) { 53 : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) {
52 callbacks_.set_removal_callback(
53 base::Bind(&ChromeSigninClient::UnregisterForCookieChangedNotification,
54 base::Unretained(this)));
55 } 54 }
56 55
57 ChromeSigninClient::~ChromeSigninClient() { 56 ChromeSigninClient::~ChromeSigninClient() {
58 UnregisterForCookieChangedNotification();
59
60 std::set<RenderProcessHost*>::iterator i; 57 std::set<RenderProcessHost*>::iterator i;
61 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end(); 58 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end();
62 ++i) { 59 ++i) {
63 (*i)->RemoveObserver(this); 60 (*i)->RemoveObserver(this);
64 } 61 }
65 } 62 }
66 63
67 // static 64 // static
68 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { 65 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) {
69 CookieSettings* cookie_settings = 66 CookieSettings* cookie_settings =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 #else 189 #else
193 return first_run::IsChromeFirstRun(); 190 return first_run::IsChromeFirstRun();
194 #endif 191 #endif
195 } 192 }
196 193
197 base::Time ChromeSigninClient::GetInstallDate() { 194 base::Time ChromeSigninClient::GetInstallDate() {
198 return base::Time::FromTimeT( 195 return base::Time::FromTimeT(
199 g_browser_process->metrics_service()->GetInstallDate()); 196 g_browser_process->metrics_service()->GetInstallDate());
200 } 197 }
201 198
202 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> 199 scoped_ptr<SigninClient::CookieChangedSubscription>
203 ChromeSigninClient::AddCookieChangedCallback( 200 ChromeSigninClient::AddCookieChangedCallback(
204 const CookieChangedCallback& callback) { 201 const GURL& url,
205 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> 202 const std::string& name,
206 subscription = callbacks_.Add(callback); 203 const net::CookieStore::CookieChangedCallback& callback) {
207 RegisterForCookieChangedNotification(); 204 scoped_refptr<net::URLRequestContextGetter> context_getter =
208 return subscription.Pass(); 205 profile_->GetRequestContext();
206 DCHECK(context_getter.get());
207 scoped_ptr<SigninCookieChangedSubscription> subscription(
208 new SigninCookieChangedSubscription(callback));
209 subscription->RegisterForCookieChangedNotifications(
210 context_getter, url, name);
211 return scoped_ptr<CookieChangedSubscription>(subscription.release());
209 } 212 }
210 213
211 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& account_id, 214 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& account_id,
212 const std::string& username, 215 const std::string& username,
213 const std::string& password) { 216 const std::string& password) {
214 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) 217 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
215 // Don't store password hash except for users of new profile management. 218 // Don't store password hash except for users of new profile management.
216 if (switches::IsNewProfileManagement()) 219 if (switches::IsNewProfileManagement())
217 chrome::SetLocalAuthCredentials(profile_, password); 220 chrome::SetLocalAuthCredentials(profile_, password);
218 #endif 221 #endif
219 } 222 }
220
221 void ChromeSigninClient::Observe(int type,
222 const content::NotificationSource& source,
223 const content::NotificationDetails& details) {
224 switch (type) {
225 case chrome::NOTIFICATION_COOKIE_CHANGED: {
226 DCHECK(!callbacks_.empty());
227 const net::CanonicalCookie* cookie =
228 content::Details<ChromeCookieDetails>(details).ptr()->cookie;
229 callbacks_.Notify(cookie);
230 break;
231 }
232 default:
233 NOTREACHED();
234 break;
235 }
236 }
237
238 void ChromeSigninClient::RegisterForCookieChangedNotification() {
239 if (callbacks_.empty())
240 return;
241 content::Source<Profile> source(profile_);
242 if (!registrar_.IsRegistered(
243 this, chrome::NOTIFICATION_COOKIE_CHANGED, source))
244 registrar_.Add(this, chrome::NOTIFICATION_COOKIE_CHANGED, source);
245 }
246
247 void ChromeSigninClient::UnregisterForCookieChangedNotification() {
248 if (!callbacks_.empty())
249 return;
250 // Note that it's allowed to call this method multiple times without an
251 // intervening call to |RegisterForCookieChangedNotification()|.
252 content::Source<Profile> source(profile_);
253 if (!registrar_.IsRegistered(
254 this, chrome::NOTIFICATION_COOKIE_CHANGED, source))
255 return;
256 registrar_.Remove(this, chrome::NOTIFICATION_COOKIE_CHANGED, source);
257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698