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/signin_cookie_changed_subscription.h" | 5 #include "chrome/browser/signin/signin_cookie_changed_subscription.h" |
6 | 6 |
| 7 #include "base/thread_task_runner_handle.h" |
7 #include "net/cookies/cookie_store.h" | 8 #include "net/cookies/cookie_store.h" |
8 #include "net/url_request/url_request_context.h" | 9 #include "net/url_request/url_request_context.h" |
9 #include "net/url_request/url_request_context_getter.h" | 10 #include "net/url_request/url_request_context_getter.h" |
10 | 11 |
11 SigninCookieChangedSubscription::SubscriptionHolder::SubscriptionHolder() { | 12 SigninCookieChangedSubscription::SubscriptionHolder::SubscriptionHolder() { |
12 } | 13 } |
13 | 14 |
14 SigninCookieChangedSubscription::SubscriptionHolder::~SubscriptionHolder() { | 15 SigninCookieChangedSubscription::SubscriptionHolder::~SubscriptionHolder() { |
15 } | 16 } |
16 | 17 |
(...skipping 24 matching lines...) Expand all Loading... |
41 const GURL& url, | 42 const GURL& url, |
42 const std::string& name) { | 43 const std::string& name) { |
43 DCHECK(thread_checker_.CalledOnValidThread()); | 44 DCHECK(thread_checker_.CalledOnValidThread()); |
44 | 45 |
45 // The cookie store can only be accessed from the context getter which lives | 46 // The cookie store can only be accessed from the context getter which lives |
46 // on the network thread. As |AddCookieChangedCallback| is called from the | 47 // on the network thread. As |AddCookieChangedCallback| is called from the |
47 // main thread, a thread jump is needed to register for cookie changed | 48 // main thread, a thread jump is needed to register for cookie changed |
48 // notifications. | 49 // notifications. |
49 net::CookieStore::CookieChangedCallback run_on_current_thread_callback = | 50 net::CookieStore::CookieChangedCallback run_on_current_thread_callback = |
50 base::Bind(&SigninCookieChangedSubscription::RunAsyncOnCookieChanged, | 51 base::Bind(&SigninCookieChangedSubscription::RunAsyncOnCookieChanged, |
51 base::MessageLoopProxy::current(), | 52 base::ThreadTaskRunnerHandle::Get(), this->AsWeakPtr()); |
52 this->AsWeakPtr()); | |
53 base::Closure register_closure = | 53 base::Closure register_closure = |
54 base::Bind(&RegisterForCookieChangesOnIOThread, | 54 base::Bind(&RegisterForCookieChangesOnIOThread, |
55 context_getter_, | 55 context_getter_, |
56 url, | 56 url, |
57 name, | 57 name, |
58 run_on_current_thread_callback, | 58 run_on_current_thread_callback, |
59 base::Unretained(subscription_holder_io_.get())); | 59 base::Unretained(subscription_holder_io_.get())); |
60 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner = | 60 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner = |
61 context_getter_->GetNetworkTaskRunner(); | 61 context_getter_->GetNetworkTaskRunner(); |
62 if (network_task_runner->BelongsToCurrentThread()) { | 62 if (network_task_runner->BelongsToCurrentThread()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 96 } |
97 | 97 |
98 void SigninCookieChangedSubscription::OnCookieChanged( | 98 void SigninCookieChangedSubscription::OnCookieChanged( |
99 const net::CanonicalCookie& cookie, | 99 const net::CanonicalCookie& cookie, |
100 bool removed) { | 100 bool removed) { |
101 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
102 if (!callback_.is_null()) { | 102 if (!callback_.is_null()) { |
103 callback_.Run(cookie, removed); | 103 callback_.Run(cookie, removed); |
104 } | 104 } |
105 } | 105 } |
OLD | NEW |