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

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: Nits 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"
12 #include "chrome/browser/content_settings/cookie_settings.h" 11 #include "chrome/browser/content_settings/cookie_settings.h"
13 #include "chrome/browser/net/chrome_cookie_notification_details.h" 12 #include "chrome/browser/net/chrome_cookie_notification_details.h"
14 #include "chrome/browser/profiles/profile_info_cache.h" 13 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_manager.h" 14 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/signin/local_auth.h" 15 #include "chrome/browser/signin/local_auth.h"
16 #include "chrome/browser/signin/signin_cookie_changed_subscription.h"
17 #include "chrome/browser/webdata/web_data_service_factory.h" 17 #include "chrome/browser/webdata/web_data_service_factory.h"
18 #include "chrome/common/chrome_version_info.h" 18 #include "chrome/common/chrome_version_info.h"
19 #include "components/metrics/metrics_service.h" 19 #include "components/metrics/metrics_service.h"
20 #include "components/signin/core/common/profile_management_switches.h" 20 #include "components/signin/core/common/profile_management_switches.h"
21 #include "components/signin/core/common/signin_pref_names.h" 21 #include "components/signin/core/common/signin_pref_names.h"
22 #include "components/signin/core/common/signin_switches.h" 22 #include "components/signin/core/common/signin_switches.h"
23 #include "content/public/browser/notification_details.h"
24 #include "content/public/browser/notification_source.h"
25 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
26 #include "content/public/common/child_process_host.h" 24 #include "content/public/common/child_process_host.h"
25 #include "net/url_request/url_request_context_getter.h"
27 #include "url/gurl.h" 26 #include "url/gurl.h"
28 27
29 #if defined(ENABLE_MANAGED_USERS) 28 #if defined(ENABLE_MANAGED_USERS)
30 #include "chrome/browser/supervised_user/supervised_user_constants.h" 29 #include "chrome/browser/supervised_user/supervised_user_constants.h"
31 #endif 30 #endif
32 31
33 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
34 #include "components/user_manager/user_manager.h" 33 #include "components/user_manager/user_manager.h"
35 #endif 34 #endif
36 35
37 #if !defined(OS_ANDROID) 36 #if !defined(OS_ANDROID)
38 #include "chrome/browser/first_run/first_run.h" 37 #include "chrome/browser/first_run/first_run.h"
39 #endif 38 #endif
40 39
41 using content::ChildProcessHost; 40 using content::ChildProcessHost;
42 using content::RenderProcessHost; 41 using content::RenderProcessHost;
43 42
44 namespace { 43 namespace {
45 44
46 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; 45 const char kGoogleAccountsUrl[] = "https://accounts.google.com";
47 46
48 } // namespace 47 } // namespace
49 48
50 ChromeSigninClient::ChromeSigninClient(Profile* profile) 49 ChromeSigninClient::ChromeSigninClient(Profile* profile)
51 : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) { 50 : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) {
52 callbacks_.set_removal_callback(
53 base::Bind(&ChromeSigninClient::UnregisterForCookieChangedNotification,
54 base::Unretained(this)));
55 } 51 }
56 52
57 ChromeSigninClient::~ChromeSigninClient() { 53 ChromeSigninClient::~ChromeSigninClient() {
58 UnregisterForCookieChangedNotification();
59
60 std::set<RenderProcessHost*>::iterator i; 54 std::set<RenderProcessHost*>::iterator i;
61 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end(); 55 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end();
62 ++i) { 56 ++i) {
63 (*i)->RemoveObserver(this); 57 (*i)->RemoveObserver(this);
64 } 58 }
65 } 59 }
66 60
67 // static 61 // static
68 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { 62 bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) {
69 CookieSettings* cookie_settings = 63 CookieSettings* cookie_settings =
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 #else 186 #else
193 return first_run::IsChromeFirstRun(); 187 return first_run::IsChromeFirstRun();
194 #endif 188 #endif
195 } 189 }
196 190
197 base::Time ChromeSigninClient::GetInstallDate() { 191 base::Time ChromeSigninClient::GetInstallDate() {
198 return base::Time::FromTimeT( 192 return base::Time::FromTimeT(
199 g_browser_process->metrics_service()->GetInstallDate()); 193 g_browser_process->metrics_service()->GetInstallDate());
200 } 194 }
201 195
202 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> 196 scoped_ptr<SigninClient::CookieChangedSubscription>
203 ChromeSigninClient::AddCookieChangedCallback( 197 ChromeSigninClient::AddCookieChangedCallback(
204 const CookieChangedCallback& callback) { 198 const GURL& url,
205 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> 199 const std::string& name,
206 subscription = callbacks_.Add(callback); 200 const net::CookieStore::CookieChangedCallback& callback) {
207 RegisterForCookieChangedNotification(); 201 scoped_refptr<net::URLRequestContextGetter> context_getter =
202 profile_->GetRequestContext();
203 DCHECK(context_getter.get());
204 scoped_ptr<SigninCookieChangedSubscription> subscription(
205 new SigninCookieChangedSubscription(context_getter, url, name, callback));
208 return subscription.Pass(); 206 return subscription.Pass();
209 } 207 }
210 208
211 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& account_id, 209 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& account_id,
212 const std::string& username, 210 const std::string& username,
213 const std::string& password) { 211 const std::string& password) {
214 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) 212 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS)
215 // Don't store password hash except for users of new profile management. 213 // Don't store password hash except for users of new profile management.
216 if (switches::IsNewProfileManagement()) 214 if (switches::IsNewProfileManagement())
217 chrome::SetLocalAuthCredentials(profile_, password); 215 chrome::SetLocalAuthCredentials(profile_, password);
218 #endif 216 #endif
219 } 217 }
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
« no previous file with comments | « chrome/browser/signin/chrome_signin_client.h ('k') | chrome/browser/signin/signin_cookie_changed_subscription.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698