OLD | NEW |
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/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 using content::ChildProcessHost; | 33 using content::ChildProcessHost; |
34 using content::RenderProcessHost; | 34 using content::RenderProcessHost; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; | 38 const char kGoogleAccountsUrl[] = "https://accounts.google.com"; |
39 | 39 |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 ChromeSigninClient::ChromeSigninClient(Profile* profile) | 42 ChromeSigninClient::ChromeSigninClient(Profile* profile) |
43 : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) {} | 43 : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) { |
| 44 callbacks_.set_removal_callback( |
| 45 base::Bind(&ChromeSigninClient::UnregisterForCookieChangedNotification, |
| 46 base::Unretained(this))); |
| 47 } |
44 | 48 |
45 ChromeSigninClient::~ChromeSigninClient() { | 49 ChromeSigninClient::~ChromeSigninClient() { |
46 UnregisterForCookieChangedNotification(); | 50 UnregisterForCookieChangedNotification(); |
47 | 51 |
48 std::set<RenderProcessHost*>::iterator i; | 52 std::set<RenderProcessHost*>::iterator i; |
49 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end(); | 53 for (i = signin_hosts_observed_.begin(); i != signin_hosts_observed_.end(); |
50 ++i) { | 54 ++i) { |
51 (*i)->RemoveObserver(this); | 55 (*i)->RemoveObserver(this); |
52 } | 56 } |
53 } | 57 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 !switches::IsEnableAccountConsistency(); | 169 !switches::IsEnableAccountConsistency(); |
166 } | 170 } |
167 | 171 |
168 std::string ChromeSigninClient::GetProductVersion() { | 172 std::string ChromeSigninClient::GetProductVersion() { |
169 chrome::VersionInfo chrome_version; | 173 chrome::VersionInfo chrome_version; |
170 if (!chrome_version.is_valid()) | 174 if (!chrome_version.is_valid()) |
171 return "invalid"; | 175 return "invalid"; |
172 return chrome_version.CreateVersionString(); | 176 return chrome_version.CreateVersionString(); |
173 } | 177 } |
174 | 178 |
175 void ChromeSigninClient::SetCookieChangedCallback( | 179 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> |
| 180 ChromeSigninClient::AddCookieChangedCallback( |
176 const CookieChangedCallback& callback) { | 181 const CookieChangedCallback& callback) { |
177 if (callback_.Equals(callback)) | 182 scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> |
178 return; | 183 subscription = callbacks_.Add(callback); |
179 | 184 RegisterForCookieChangedNotification(); |
180 // There should be only one callback active at a time. | 185 return subscription.Pass(); |
181 DCHECK(callback.is_null() || callback_.is_null()); | |
182 callback_ = callback; | |
183 if (!callback_.is_null()) | |
184 RegisterForCookieChangedNotification(); | |
185 else | |
186 UnregisterForCookieChangedNotification(); | |
187 } | 186 } |
188 | 187 |
189 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& username, | 188 void ChromeSigninClient::GoogleSigninSucceeded(const std::string& username, |
190 const std::string& password) { | 189 const std::string& password) { |
191 #if !defined(OS_ANDROID) | 190 #if !defined(OS_ANDROID) |
192 // Don't store password hash except for users of account consistency features. | 191 // Don't store password hash except for users of account consistency features. |
193 if (switches::IsEnableAccountConsistency()) | 192 if (switches::IsEnableAccountConsistency()) |
194 chrome::SetLocalAuthCredentials(profile_, password); | 193 chrome::SetLocalAuthCredentials(profile_, password); |
195 #endif | 194 #endif |
196 } | 195 } |
197 | 196 |
198 void ChromeSigninClient::Observe(int type, | 197 void ChromeSigninClient::Observe(int type, |
199 const content::NotificationSource& source, | 198 const content::NotificationSource& source, |
200 const content::NotificationDetails& details) { | 199 const content::NotificationDetails& details) { |
201 switch (type) { | 200 switch (type) { |
202 case chrome::NOTIFICATION_COOKIE_CHANGED: { | 201 case chrome::NOTIFICATION_COOKIE_CHANGED: { |
203 DCHECK(!callback_.is_null()); | 202 DCHECK(!callbacks_.empty()); |
204 const net::CanonicalCookie* cookie = | 203 const net::CanonicalCookie* cookie = |
205 content::Details<ChromeCookieDetails>(details).ptr()->cookie; | 204 content::Details<ChromeCookieDetails>(details).ptr()->cookie; |
206 callback_.Run(cookie); | 205 callbacks_.Notify(cookie); |
207 break; | 206 break; |
208 } | 207 } |
209 default: | 208 default: |
210 NOTREACHED(); | 209 NOTREACHED(); |
211 break; | 210 break; |
212 } | 211 } |
213 } | 212 } |
214 | 213 |
215 void ChromeSigninClient::RegisterForCookieChangedNotification() { | 214 void ChromeSigninClient::RegisterForCookieChangedNotification() { |
| 215 if (callbacks_.empty()) |
| 216 return; |
216 content::Source<Profile> source(profile_); | 217 content::Source<Profile> source(profile_); |
217 DCHECK(!registrar_.IsRegistered( | 218 if (!registrar_.IsRegistered( |
218 this, chrome::NOTIFICATION_COOKIE_CHANGED, source)); | 219 this, chrome::NOTIFICATION_COOKIE_CHANGED, source)) |
219 registrar_.Add(this, chrome::NOTIFICATION_COOKIE_CHANGED, source); | 220 registrar_.Add(this, chrome::NOTIFICATION_COOKIE_CHANGED, source); |
220 } | 221 } |
221 | 222 |
222 void ChromeSigninClient::UnregisterForCookieChangedNotification() { | 223 void ChromeSigninClient::UnregisterForCookieChangedNotification() { |
| 224 if (!callbacks_.empty()) |
| 225 return; |
223 // Note that it's allowed to call this method multiple times without an | 226 // Note that it's allowed to call this method multiple times without an |
224 // intervening call to |RegisterForCookieChangedNotification()|. | 227 // intervening call to |RegisterForCookieChangedNotification()|. |
225 content::Source<Profile> source(profile_); | 228 content::Source<Profile> source(profile_); |
226 if (!registrar_.IsRegistered( | 229 if (!registrar_.IsRegistered( |
227 this, chrome::NOTIFICATION_COOKIE_CHANGED, source)) | 230 this, chrome::NOTIFICATION_COOKIE_CHANGED, source)) |
228 return; | 231 return; |
229 registrar_.Remove(this, chrome::NOTIFICATION_COOKIE_CHANGED, source); | 232 registrar_.Remove(this, chrome::NOTIFICATION_COOKIE_CHANGED, source); |
230 } | 233 } |
OLD | NEW |