| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "android_webview/browser/net/aw_cookie_store_wrapper.h" | 5 #include "android_webview/browser/net/aw_cookie_store_wrapper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "android_webview/browser/net/init_native_callback.h" | 9 #include "android_webview/browser/net/init_native_callback.h" |
| 10 #include "base/memory/ref_counted_delete_on_message_loop.h" | 10 #include "base/memory/ref_counted_delete_on_message_loop.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 // Wraps a subscription to cookie change notifications for the global | 23 // Wraps a subscription to cookie change notifications for the global |
| 24 // CookieStore for a consumer that lives on another thread. Handles passing | 24 // CookieStore for a consumer that lives on another thread. Handles passing |
| 25 // messages between thread, and destroys itself when the consumer unsubscribes. | 25 // messages between thread, and destroys itself when the consumer unsubscribes. |
| 26 // Must be created on the consumer's thread. Each instance only supports a | 26 // Must be created on the consumer's thread. Each instance only supports a |
| 27 // single subscription. | 27 // single subscription. |
| 28 class SubscriptionWrapper { | 28 class SubscriptionWrapper { |
| 29 public: | 29 public: |
| 30 SubscriptionWrapper() : weak_factory_(this) {} | 30 SubscriptionWrapper() : weak_factory_(this) {} |
| 31 | 31 |
| 32 scoped_ptr<net::CookieStore::CookieChangedSubscription> Subscribe( | 32 std::unique_ptr<net::CookieStore::CookieChangedSubscription> Subscribe( |
| 33 const GURL& url, | 33 const GURL& url, |
| 34 const std::string& name, | 34 const std::string& name, |
| 35 const net::CookieStore::CookieChangedCallback& callback) { | 35 const net::CookieStore::CookieChangedCallback& callback) { |
| 36 // This class is only intended to be used for a single subscription. | 36 // This class is only intended to be used for a single subscription. |
| 37 DCHECK(callback_list_.empty()); | 37 DCHECK(callback_list_.empty()); |
| 38 | 38 |
| 39 nested_subscription_ = | 39 nested_subscription_ = |
| 40 new NestedSubscription(url, name, weak_factory_.GetWeakPtr()); | 40 new NestedSubscription(url, name, weak_factory_.GetWeakPtr()); |
| 41 return callback_list_.Add(callback); | 41 return callback_list_.Add(callback); |
| 42 } | 42 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 72 | 72 |
| 73 void OnChanged(const net::CanonicalCookie& cookie, bool removed) { | 73 void OnChanged(const net::CanonicalCookie& cookie, bool removed) { |
| 74 client_task_runner_->PostTask( | 74 client_task_runner_->PostTask( |
| 75 FROM_HERE, base::Bind(&SubscriptionWrapper::OnChanged, | 75 FROM_HERE, base::Bind(&SubscriptionWrapper::OnChanged, |
| 76 subscription_wrapper_, cookie, removed)); | 76 subscription_wrapper_, cookie, removed)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 base::WeakPtr<SubscriptionWrapper> subscription_wrapper_; | 79 base::WeakPtr<SubscriptionWrapper> subscription_wrapper_; |
| 80 scoped_refptr<base::TaskRunner> client_task_runner_; | 80 scoped_refptr<base::TaskRunner> client_task_runner_; |
| 81 | 81 |
| 82 scoped_ptr<net::CookieStore::CookieChangedSubscription> subscription_; | 82 std::unique_ptr<net::CookieStore::CookieChangedSubscription> subscription_; |
| 83 | 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(NestedSubscription); | 84 DISALLOW_COPY_AND_ASSIGN(NestedSubscription); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 void OnChanged(const net::CanonicalCookie& cookie, bool removed) { | 87 void OnChanged(const net::CanonicalCookie& cookie, bool removed) { |
| 88 callback_list_.Notify(cookie, removed); | 88 callback_list_.Notify(cookie, removed); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // The "list" only had one entry, so can just clean up now. | 91 // The "list" only had one entry, so can just clean up now. |
| 92 void OnUnsubscribe() { delete this; } | 92 void OnUnsubscribe() { delete this; } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 PostTaskToCookieStoreTaskRunner(base::Bind( | 311 PostTaskToCookieStoreTaskRunner(base::Bind( |
| 312 &FlushStoreOnCookieThread, CreateWrappedClosureCallback(callback))); | 312 &FlushStoreOnCookieThread, CreateWrappedClosureCallback(callback))); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void AwCookieStoreWrapper::SetForceKeepSessionState() { | 315 void AwCookieStoreWrapper::SetForceKeepSessionState() { |
| 316 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); | 316 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); |
| 317 PostTaskToCookieStoreTaskRunner( | 317 PostTaskToCookieStoreTaskRunner( |
| 318 base::Bind(&SetForceKeepSessionStateOnCookieThread)); | 318 base::Bind(&SetForceKeepSessionStateOnCookieThread)); |
| 319 } | 319 } |
| 320 | 320 |
| 321 scoped_ptr<net::CookieStore::CookieChangedSubscription> | 321 std::unique_ptr<net::CookieStore::CookieChangedSubscription> |
| 322 AwCookieStoreWrapper::AddCallbackForCookie( | 322 AwCookieStoreWrapper::AddCallbackForCookie( |
| 323 const GURL& url, | 323 const GURL& url, |
| 324 const std::string& name, | 324 const std::string& name, |
| 325 const CookieChangedCallback& callback) { | 325 const CookieChangedCallback& callback) { |
| 326 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); | 326 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); |
| 327 | 327 |
| 328 // The SubscriptionWrapper is owned by the subscription itself, and has no | 328 // The SubscriptionWrapper is owned by the subscription itself, and has no |
| 329 // connection to the AwCookieStoreWrapper after creation. Other CookieStore | 329 // connection to the AwCookieStoreWrapper after creation. Other CookieStore |
| 330 // implementations DCHECK if a subscription outlasts the cookie store, | 330 // implementations DCHECK if a subscription outlasts the cookie store, |
| 331 // unfortunately, this design makes DCHECKing if there's an outstanding | 331 // unfortunately, this design makes DCHECKing if there's an outstanding |
| (...skipping 16 matching lines...) Expand all Loading... |
| 348 base::Bind(&AwCookieStoreWrapper::RunClosureCallback, | 348 base::Bind(&AwCookieStoreWrapper::RunClosureCallback, |
| 349 weak_factory_.GetWeakPtr(), callback)); | 349 weak_factory_.GetWeakPtr(), callback)); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void AwCookieStoreWrapper::RunClosureCallback(const base::Closure& callback) { | 352 void AwCookieStoreWrapper::RunClosureCallback(const base::Closure& callback) { |
| 353 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); | 353 DCHECK(client_task_runner_->RunsTasksOnCurrentThread()); |
| 354 callback.Run(); | 354 callback.Run(); |
| 355 } | 355 } |
| 356 | 356 |
| 357 } // namespace android_webview | 357 } // namespace android_webview |
| OLD | NEW |