OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 #include <algorithm> | 47 #include <algorithm> |
48 #include <functional> | 48 #include <functional> |
49 #include <set> | 49 #include <set> |
50 | 50 |
51 #include "base/basictypes.h" | 51 #include "base/basictypes.h" |
52 #include "base/bind.h" | 52 #include "base/bind.h" |
53 #include "base/callback.h" | 53 #include "base/callback.h" |
54 #include "base/logging.h" | 54 #include "base/logging.h" |
55 #include "base/memory/scoped_ptr.h" | 55 #include "base/memory/scoped_ptr.h" |
56 #include "base/message_loop/message_loop.h" | 56 #include "base/message_loop/message_loop.h" |
57 #include "base/message_loop/message_loop_proxy.h" | |
58 #include "base/metrics/field_trial.h" | 57 #include "base/metrics/field_trial.h" |
59 #include "base/metrics/histogram.h" | 58 #include "base/metrics/histogram.h" |
60 #include "base/profiler/scoped_tracker.h" | 59 #include "base/profiler/scoped_tracker.h" |
| 60 #include "base/single_thread_task_runner.h" |
61 #include "base/strings/string_util.h" | 61 #include "base/strings/string_util.h" |
62 #include "base/strings/stringprintf.h" | 62 #include "base/strings/stringprintf.h" |
| 63 #include "base/thread_task_runner_handle.h" |
63 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 64 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
64 #include "net/cookies/canonical_cookie.h" | 65 #include "net/cookies/canonical_cookie.h" |
65 #include "net/cookies/cookie_util.h" | 66 #include "net/cookies/cookie_util.h" |
66 #include "net/cookies/parsed_cookie.h" | 67 #include "net/cookies/parsed_cookie.h" |
67 | 68 |
68 using base::Time; | 69 using base::Time; |
69 using base::TimeDelta; | 70 using base::TimeDelta; |
70 using base::TimeTicks; | 71 using base::TimeTicks; |
71 | 72 |
72 // In steady state, most cookie requests can be satisfied by the in memory | 73 // In steady state, most cookie requests can be satisfied by the in memory |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 // appropriate thread. Maintains a reference to this CookieMonsterTask | 387 // appropriate thread. Maintains a reference to this CookieMonsterTask |
387 // instance until the callback completes. | 388 // instance until the callback completes. |
388 void InvokeCallback(base::Closure callback); | 389 void InvokeCallback(base::Closure callback); |
389 | 390 |
390 CookieMonster* cookie_monster() { return cookie_monster_; } | 391 CookieMonster* cookie_monster() { return cookie_monster_; } |
391 | 392 |
392 private: | 393 private: |
393 friend class base::RefCountedThreadSafe<CookieMonsterTask>; | 394 friend class base::RefCountedThreadSafe<CookieMonsterTask>; |
394 | 395 |
395 CookieMonster* cookie_monster_; | 396 CookieMonster* cookie_monster_; |
396 scoped_refptr<base::MessageLoopProxy> thread_; | 397 scoped_refptr<base::SingleThreadTaskRunner> thread_; |
397 | 398 |
398 DISALLOW_COPY_AND_ASSIGN(CookieMonsterTask); | 399 DISALLOW_COPY_AND_ASSIGN(CookieMonsterTask); |
399 }; | 400 }; |
400 | 401 |
401 CookieMonster::CookieMonsterTask::CookieMonsterTask( | 402 CookieMonster::CookieMonsterTask::CookieMonsterTask( |
402 CookieMonster* cookie_monster) | 403 CookieMonster* cookie_monster) |
403 : cookie_monster_(cookie_monster), | 404 : cookie_monster_(cookie_monster), |
404 thread_(base::MessageLoopProxy::current()) { | 405 thread_(base::ThreadTaskRunnerHandle::Get()) { |
405 } | 406 } |
406 | 407 |
407 CookieMonster::CookieMonsterTask::~CookieMonsterTask() { | 408 CookieMonster::CookieMonsterTask::~CookieMonsterTask() { |
408 } | 409 } |
409 | 410 |
410 // Unfortunately, one cannot re-bind a Callback with parameters into a closure. | 411 // Unfortunately, one cannot re-bind a Callback with parameters into a closure. |
411 // Therefore, the closure passed to InvokeCallback is a clumsy binding of | 412 // Therefore, the closure passed to InvokeCallback is a clumsy binding of |
412 // Callback::Run on a wrapped Callback instance. Since Callback is not | 413 // Callback::Run on a wrapped Callback instance. Since Callback is not |
413 // reference counted, we bind to an instance that is a member of the | 414 // reference counted, we bind to an instance that is a member of the |
414 // CookieMonsterTask subclass. Then, we cannot simply post the callback to a | 415 // CookieMonsterTask subclass. Then, we cannot simply post the callback to a |
(...skipping 2006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2421 | 2422 |
2422 scoped_ptr<CookieStore::CookieChangedSubscription> | 2423 scoped_ptr<CookieStore::CookieChangedSubscription> |
2423 CookieMonster::AddCallbackForCookie(const GURL& gurl, | 2424 CookieMonster::AddCallbackForCookie(const GURL& gurl, |
2424 const std::string& name, | 2425 const std::string& name, |
2425 const CookieChangedCallback& callback) { | 2426 const CookieChangedCallback& callback) { |
2426 base::AutoLock autolock(lock_); | 2427 base::AutoLock autolock(lock_); |
2427 std::pair<GURL, std::string> key(gurl, name); | 2428 std::pair<GURL, std::string> key(gurl, name); |
2428 if (hook_map_.count(key) == 0) | 2429 if (hook_map_.count(key) == 0) |
2429 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); | 2430 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); |
2430 return hook_map_[key]->Add( | 2431 return hook_map_[key]->Add( |
2431 base::Bind(&RunAsync, base::MessageLoopProxy::current(), callback)); | 2432 base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback)); |
2432 } | 2433 } |
2433 | 2434 |
2434 #if defined(OS_ANDROID) | 2435 #if defined(OS_ANDROID) |
2435 void CookieMonster::SetEnableFileScheme(bool accept) { | 2436 void CookieMonster::SetEnableFileScheme(bool accept) { |
2436 // This assumes "file" is always at the end of the array. See the comment | 2437 // This assumes "file" is always at the end of the array. See the comment |
2437 // above kDefaultCookieableSchemes. | 2438 // above kDefaultCookieableSchemes. |
2438 // | 2439 // |
2439 // TODO(mkwst): We're keeping this method around to support the | 2440 // TODO(mkwst): We're keeping this method around to support the |
2440 // 'CookieManager::setAcceptFileSchemeCookies' method on Android's WebView; | 2441 // 'CookieManager::setAcceptFileSchemeCookies' method on Android's WebView; |
2441 // if/when we can deprecate and remove that method, we can remove this one | 2442 // if/when we can deprecate and remove that method, we can remove this one |
(...skipping 20 matching lines...) Expand all Loading... |
2462 it != hook_map_.end(); ++it) { | 2463 it != hook_map_.end(); ++it) { |
2463 std::pair<GURL, std::string> key = it->first; | 2464 std::pair<GURL, std::string> key = it->first; |
2464 if (cookie.IncludeForRequestURL(key.first, opts) && | 2465 if (cookie.IncludeForRequestURL(key.first, opts) && |
2465 cookie.Name() == key.second) { | 2466 cookie.Name() == key.second) { |
2466 it->second->Notify(cookie, removed); | 2467 it->second->Notify(cookie, removed); |
2467 } | 2468 } |
2468 } | 2469 } |
2469 } | 2470 } |
2470 | 2471 |
2471 } // namespace net | 2472 } // namespace net |
OLD | NEW |