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 private: |
| 29 // Holder of a cookie store cookie changed subscription. |
| 30 struct SubscriptionHolder { |
| 31 scoped_ptr<net::CookieStore::CookieChangedSubscription> subscription; |
| 32 SubscriptionHolder(); |
| 33 ~SubscriptionHolder(); |
| 34 }; |
| 35 |
| 36 // Adds a callback for cookie changed events. This method is called on the |
| 37 // network thread, so it is safe to access the cookie store. |
| 38 static void RegisterForCookieChangesOnIOThread( |
| 39 scoped_refptr<net::URLRequestContextGetter> context_getter, |
| 40 const GURL url, |
| 41 const std::string name, |
| 42 const net::CookieStore::CookieChangedCallback callback, |
| 43 SigninCookieChangedSubscription::SubscriptionHolder* |
| 44 out_subscription_holder); |
| 45 |
| 46 void RegisterForCookieChangedNotifications(const GURL& url, |
| 47 const std::string& name); |
| 48 |
| 49 // Posts a task on the |proxy| task runner that calls |OnCookieChanged| on |
| 50 // |subscription|. |
| 51 // Note that this method is called on the network thread, so |subscription| |
| 52 // must not be used here, it is only passed around. |
| 53 static void RunAsyncOnCookieChanged( |
| 54 scoped_refptr<base::TaskRunner> proxy, |
| 55 base::WeakPtr<SigninCookieChangedSubscription> subscription, |
| 56 const net::CanonicalCookie& cookie, |
| 57 bool removed); |
| 58 |
| 59 // Handler for cookie changed events. |
| 60 void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed); |
| 61 |
| 62 // The context getter. |
| 63 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
| 64 |
| 65 // The holder of a cookie changed subscription. Must be destroyed on the |
| 66 // network thread. |
| 67 scoped_ptr<SubscriptionHolder> subscription_holder_io_; |
| 68 |
| 69 // Callback to be run on cookie changed events. |
| 70 net::CookieStore::CookieChangedCallback callback_; |
| 71 |
| 72 base::ThreadChecker thread_checker_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(SigninCookieChangedSubscription); |
| 75 }; |
| 76 |
| 77 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_COOKIE_CHANGED_SUBSCRIPTION_H_ |
OLD | NEW |