base::Time multiplicative operator overloading
[chromium-blink-merge.git] / chrome / browser / signin / signin_cookie_changed_subscription.h
blob5befe06cf02a4fadb7376b7c2e7f5fd3d66e2aa0
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.
5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_COOKIE_CHANGED_SUBSCRIPTION_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_COOKIE_CHANGED_SUBSCRIPTION_H_
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"
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;
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();
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);
46 void RegisterForCookieChangedNotifications(const GURL& url,
47 const std::string& name);
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);
59 // Handler for cookie changed events.
60 void OnCookieChanged(const net::CanonicalCookie& cookie, bool removed);
62 // The context getter.
63 scoped_refptr<net::URLRequestContextGetter> context_getter_;
65 // The holder of a cookie changed subscription. Must be destroyed on the
66 // network thread.
67 scoped_ptr<SubscriptionHolder> subscription_holder_io_;
69 // Callback to be run on cookie changed events.
70 net::CookieStore::CookieChangedCallback callback_;
72 base::ThreadChecker thread_checker_;
74 DISALLOW_COPY_AND_ASSIGN(SigninCookieChangedSubscription);
77 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_COOKIE_CHANGED_SUBSCRIPTION_H_