Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_COOKIE_CHANGED_SUBSCRIPTION_H_ | |
| 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_COOKIE_CHANGED_SUBSCRIPTION_H_ | |
| 7 | |
| 8 #include "base/memory/weak_ptr.h" | |
| 9 #include "base/threading/thread_checker.h" | |
| 10 #include "components/signin/core/browser/signin_client.h" | |
| 11 #include "net/url_request/url_request_context_getter.h" | |
| 12 | |
| 13 // The subscription for a cookie changed events. This class lives on the | |
| 14 // main thread. | |
| 15 class SigninCookieChangedSubscription | |
| 16 : public SigninClient::CookieChangedSubscription, | |
| 17 public base::SupportsWeakPtr<SigninCookieChangedSubscription> { | |
| 18 public: | |
| 19 // Creates a cookie changed subscription and registers for cookie changed | |
| 20 // events. | |
| 21 SigninCookieChangedSubscription( | |
| 22 scoped_refptr<net::URLRequestContextGetter> context_getter, | |
| 23 const GURL& url, | |
| 24 const std::string& name, | |
| 25 const net::CookieStore::CookieChangedCallback& callback); | |
| 26 ~SigninCookieChangedSubscription() override; | |
| 27 | |
| 28 // Handler for cookie changed events. | |
| 29 void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed); | |
| 30 | |
| 31 private: | |
| 32 // Holder of a cookie store cookie changed subscription. | |
| 33 struct SubscriptionHolder { | |
| 34 scoped_ptr<net::CookieStore::CookieChangedSubscription> subscription; | |
| 35 SubscriptionHolder(); | |
| 36 ~SubscriptionHolder(); | |
| 37 }; | |
| 38 | |
| 39 // Adds a callback for cookie changed events. This method is called on the | |
| 40 // network thread, so it is safe to access the cookie store. | |
| 41 static void RegisterForCookieChangesOnIOThread( | |
| 42 scoped_refptr<net::URLRequestContextGetter> context_getter, | |
| 43 const GURL url, | |
| 44 const std::string name, | |
| 45 const net::CookieStore::CookieChangedCallback callback, | |
| 46 SigninCookieChangedSubscription::SubscriptionHolder* | |
| 47 out_subscription_holder); | |
| 48 | |
| 49 void RegisterForCookieChangedNotifications(const GURL& url, | |
| 50 const std::string& name); | |
| 51 | |
| 52 // The context getter. | |
| 53 scoped_refptr<net::URLRequestContextGetter> context_getter_; | |
|
droger
2014/11/04 12:44:49
Why not just keep a reference on the SingleThreadT
msarda
2014/11/04 12:53:19
No particular reason. It made more sense to me whe
droger
2014/11/04 13:08:40
You are retaining the object and thus you may exte
| |
| 54 | |
| 55 // The holder of a cookie changed subscription. Must be destroyed on the | |
| 56 // network thread. | |
| 57 scoped_ptr<SubscriptionHolder> subscription_holder_io_; | |
| 58 | |
| 59 // Callback to be run on cookie changed events. | |
| 60 net::CookieStore::CookieChangedCallback callback_; | |
| 61 | |
| 62 base::ThreadChecker thread_checker_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(SigninCookieChangedSubscription); | |
| 65 }; | |
| 66 | |
| 67 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_COOKIE_CHANGED_SUBSCRIPTION_H_ | |
| OLD | NEW |