Chromium Code Reviews| Index: chrome/browser/signin/chrome_signin_client.cc |
| diff --git a/chrome/browser/signin/chrome_signin_client.cc b/chrome/browser/signin/chrome_signin_client.cc |
| index c533ab3f3558e7d25497f4ab2ba86965efe434e1..dd909b6b71a2a5334153a934e0fa000dcb7cd061 100644 |
| --- a/chrome/browser/signin/chrome_signin_client.cc |
| +++ b/chrome/browser/signin/chrome_signin_client.cc |
| @@ -40,7 +40,11 @@ const char kGoogleAccountsUrl[] = "https://accounts.google.com"; |
| } // namespace |
| ChromeSigninClient::ChromeSigninClient(Profile* profile) |
| - : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) {} |
| + : profile_(profile), signin_host_id_(ChildProcessHost::kInvalidUniqueID) { |
| + callbacks_.set_removal_callback( |
| + base::Bind(&ChromeSigninClient::UnregisterForCookieChangedNotification, |
| + base::Unretained(this))); |
| +} |
| ChromeSigninClient::~ChromeSigninClient() { |
| UnregisterForCookieChangedNotification(); |
| @@ -172,18 +176,13 @@ std::string ChromeSigninClient::GetProductVersion() { |
| return chrome_version.CreateVersionString(); |
| } |
| -void ChromeSigninClient::SetCookieChangedCallback( |
| +scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> |
| +ChromeSigninClient::AddCookieChangedCallback( |
| const CookieChangedCallback& callback) { |
| - if (callback_.Equals(callback)) |
| - return; |
| - |
| - // There should be only one callback active at a time. |
| - DCHECK(callback.is_null() || callback_.is_null()); |
| - callback_ = callback; |
| - if (!callback_.is_null()) |
| - RegisterForCookieChangedNotification(); |
| - else |
| - UnregisterForCookieChangedNotification(); |
| + scoped_ptr<SigninClient::CookieChangedCallbackList::Subscription> |
| + subscription = callbacks_.Add(callback); |
| + RegisterForCookieChangedNotification(); |
| + return subscription.Pass(); |
| } |
| void ChromeSigninClient::GoogleSigninSucceeded(const std::string& username, |
| @@ -200,10 +199,10 @@ void ChromeSigninClient::Observe(int type, |
| const content::NotificationDetails& details) { |
| switch (type) { |
| case chrome::NOTIFICATION_COOKIE_CHANGED: { |
| - DCHECK(!callback_.is_null()); |
| + DCHECK(!callbacks_.empty()); |
|
Roger Tawa OOO till Jul 10th
2014/08/06 20:29:41
Maybe don't need this DCHECK anymore?
Mike Lerman
2014/08/07 16:39:25
It still seems like valid for sanity - we should n
|
| const net::CanonicalCookie* cookie = |
| content::Details<ChromeCookieDetails>(details).ptr()->cookie; |
| - callback_.Run(cookie); |
| + callbacks_.Notify(cookie); |
| break; |
| } |
| default: |
| @@ -213,13 +212,17 @@ void ChromeSigninClient::Observe(int type, |
| } |
| void ChromeSigninClient::RegisterForCookieChangedNotification() { |
| + if (callbacks_.empty()) |
| + return; |
| content::Source<Profile> source(profile_); |
| - DCHECK(!registrar_.IsRegistered( |
| - this, chrome::NOTIFICATION_COOKIE_CHANGED, source)); |
| + if (!registrar_.IsRegistered( |
| + this, chrome::NOTIFICATION_COOKIE_CHANGED, source)) |
| registrar_.Add(this, chrome::NOTIFICATION_COOKIE_CHANGED, source); |
| } |
| void ChromeSigninClient::UnregisterForCookieChangedNotification() { |
| + if (!callbacks_.empty()) |
| + return; |
| // Note that it's allowed to call this method multiple times without an |
| // intervening call to |RegisterForCookieChangedNotification()|. |
| content::Source<Profile> source(profile_); |