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 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); | 911 DISALLOW_COPY_AND_ASSIGN(DeleteCookieTask); |
912 }; | 912 }; |
913 | 913 |
914 void CookieMonster::DeleteCookieTask::Run() { | 914 void CookieMonster::DeleteCookieTask::Run() { |
915 this->cookie_monster()->DeleteCookie(url_, cookie_name_); | 915 this->cookie_monster()->DeleteCookie(url_, cookie_name_); |
916 if (!callback_.is_null()) { | 916 if (!callback_.is_null()) { |
917 this->InvokeCallback(callback_); | 917 this->InvokeCallback(callback_); |
918 } | 918 } |
919 } | 919 } |
920 | 920 |
| 921 // Task class for DeleteSessionCookies call. |
| 922 class CookieMonster::DeleteSessionCookiesTask |
| 923 : public CookieMonster::CookieMonsterTask { |
| 924 public: |
| 925 DeleteSessionCookiesTask( |
| 926 CookieMonster* cookie_monster, |
| 927 const CookieMonster::DeleteCallback& callback) |
| 928 : CookieMonsterTask(cookie_monster), |
| 929 callback_(callback) { } |
| 930 |
| 931 virtual void Run() OVERRIDE; |
| 932 |
| 933 private: |
| 934 CookieMonster::DeleteCallback callback_; |
| 935 |
| 936 DISALLOW_COPY_AND_ASSIGN(DeleteSessionCookiesTask); |
| 937 }; |
| 938 |
| 939 void CookieMonster::DeleteSessionCookiesTask::Run() { |
| 940 int num_deleted = this->cookie_monster()->DeleteSessionCookies(); |
| 941 if (!callback_.is_null()) { |
| 942 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, |
| 943 base::Unretained(&callback_), num_deleted)); |
| 944 } |
| 945 } |
| 946 |
921 // Asynchronous CookieMonster API | 947 // Asynchronous CookieMonster API |
922 | 948 |
923 void CookieMonster::SetCookieWithDetailsAsync( | 949 void CookieMonster::SetCookieWithDetailsAsync( |
924 const GURL& url, const std::string& name, const std::string& value, | 950 const GURL& url, const std::string& name, const std::string& value, |
925 const std::string& domain, const std::string& path, | 951 const std::string& domain, const std::string& path, |
926 const base::Time& expiration_time, bool secure, bool http_only, | 952 const base::Time& expiration_time, bool secure, bool http_only, |
927 const SetCookiesCallback& callback) { | 953 const SetCookiesCallback& callback) { |
928 scoped_refptr<SetCookieWithDetailsTask> task = | 954 scoped_refptr<SetCookieWithDetailsTask> task = |
929 new SetCookieWithDetailsTask(this, url, name, value, domain, path, | 955 new SetCookieWithDetailsTask(this, url, name, value, domain, path, |
930 expiration_time, secure, http_only, | 956 expiration_time, secure, http_only, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 | 1054 |
1029 void CookieMonster::DeleteCookieAsync(const GURL& url, | 1055 void CookieMonster::DeleteCookieAsync(const GURL& url, |
1030 const std::string& cookie_name, | 1056 const std::string& cookie_name, |
1031 const base::Closure& callback) { | 1057 const base::Closure& callback) { |
1032 scoped_refptr<DeleteCookieTask> task = | 1058 scoped_refptr<DeleteCookieTask> task = |
1033 new DeleteCookieTask(this, url, cookie_name, callback); | 1059 new DeleteCookieTask(this, url, cookie_name, callback); |
1034 | 1060 |
1035 DoCookieTaskForURL(task, url); | 1061 DoCookieTaskForURL(task, url); |
1036 } | 1062 } |
1037 | 1063 |
| 1064 void CookieMonster::DeleteSessionCookiesAsync( |
| 1065 const CookieStore::DeleteCallback& callback) { |
| 1066 scoped_refptr<DeleteSessionCookiesTask> task = |
| 1067 new DeleteSessionCookiesTask(this, callback); |
| 1068 |
| 1069 DoCookieTask(task); |
| 1070 } |
| 1071 |
1038 void CookieMonster::DoCookieTask( | 1072 void CookieMonster::DoCookieTask( |
1039 const scoped_refptr<CookieMonsterTask>& task_item) { | 1073 const scoped_refptr<CookieMonsterTask>& task_item) { |
1040 { | 1074 { |
1041 base::AutoLock autolock(lock_); | 1075 base::AutoLock autolock(lock_); |
1042 InitIfNecessary(); | 1076 InitIfNecessary(); |
1043 if (!loaded_) { | 1077 if (!loaded_) { |
1044 queue_.push(task_item); | 1078 queue_.push(task_item); |
1045 return; | 1079 return; |
1046 } | 1080 } |
1047 } | 1081 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1417 |
1384 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { | 1418 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
1385 CookieMap::iterator curit = it; | 1419 CookieMap::iterator curit = it; |
1386 ++it; | 1420 ++it; |
1387 if (matching_cookies.find(curit->second) != matching_cookies.end()) { | 1421 if (matching_cookies.find(curit->second) != matching_cookies.end()) { |
1388 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); | 1422 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); |
1389 } | 1423 } |
1390 } | 1424 } |
1391 } | 1425 } |
1392 | 1426 |
| 1427 int CookieMonster::DeleteSessionCookies() { |
| 1428 base::AutoLock autolock(lock_); |
| 1429 |
| 1430 int num_deleted = 0; |
| 1431 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { |
| 1432 CookieMap::iterator curit = it; |
| 1433 CanonicalCookie* cc = curit->second; |
| 1434 ++it; |
| 1435 |
| 1436 if (!cc->IsPersistent()) { |
| 1437 InternalDeleteCookie(curit, |
| 1438 true, /*sync_to_store*/ |
| 1439 DELETE_COOKIE_EXPIRED); |
| 1440 ++num_deleted; |
| 1441 } |
| 1442 } |
| 1443 |
| 1444 return num_deleted; |
| 1445 } |
| 1446 |
1393 CookieMonster* CookieMonster::GetCookieMonster() { | 1447 CookieMonster* CookieMonster::GetCookieMonster() { |
1394 return this; | 1448 return this; |
1395 } | 1449 } |
1396 | 1450 |
1397 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { | 1451 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { |
1398 // This function must be called before the CookieMonster is used. | 1452 // This function must be called before the CookieMonster is used. |
1399 DCHECK(!initialized_); | 1453 DCHECK(!initialized_); |
1400 persist_session_cookies_ = persist_session_cookies; | 1454 persist_session_cookies_ = persist_session_cookies; |
1401 } | 1455 } |
1402 | 1456 |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2732 std::string CookieMonster::CanonicalCookie::DebugString() const { | 2786 std::string CookieMonster::CanonicalCookie::DebugString() const { |
2733 return base::StringPrintf( | 2787 return base::StringPrintf( |
2734 "name: %s value: %s domain: %s path: %s creation: %" | 2788 "name: %s value: %s domain: %s path: %s creation: %" |
2735 PRId64, | 2789 PRId64, |
2736 name_.c_str(), value_.c_str(), | 2790 name_.c_str(), value_.c_str(), |
2737 domain_.c_str(), path_.c_str(), | 2791 domain_.c_str(), path_.c_str(), |
2738 static_cast<int64>(creation_date_.ToTimeT())); | 2792 static_cast<int64>(creation_date_.ToTimeT())); |
2739 } | 2793 } |
2740 | 2794 |
2741 } // namespace | 2795 } // namespace |
OLD | NEW |