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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 }; | 758 }; |
759 | 759 |
760 void CookieMonster::DeleteSessionCookiesTask::Run() { | 760 void CookieMonster::DeleteSessionCookiesTask::Run() { |
761 int num_deleted = this->cookie_monster()->DeleteSessionCookies(); | 761 int num_deleted = this->cookie_monster()->DeleteSessionCookies(); |
762 if (!callback_.is_null()) { | 762 if (!callback_.is_null()) { |
763 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, | 763 this->InvokeCallback(base::Bind(&CookieMonster::DeleteCallback::Run, |
764 base::Unretained(&callback_), num_deleted)); | 764 base::Unretained(&callback_), num_deleted)); |
765 } | 765 } |
766 } | 766 } |
767 | 767 |
| 768 // Task class for HasCookiesForETLDP1Task call. |
| 769 class CookieMonster::HasCookiesForETLDP1Task |
| 770 : public CookieMonster::CookieMonsterTask { |
| 771 public: |
| 772 HasCookiesForETLDP1Task( |
| 773 CookieMonster* cookie_monster, |
| 774 const std::string& etldp1, |
| 775 const CookieMonster::HasCookiesForETLDP1Callback& callback) |
| 776 : CookieMonsterTask(cookie_monster), |
| 777 etldp1_(etldp1), |
| 778 callback_(callback) { |
| 779 } |
| 780 |
| 781 // CookieMonster::CookieMonsterTask: |
| 782 virtual void Run() OVERRIDE; |
| 783 |
| 784 protected: |
| 785 virtual ~HasCookiesForETLDP1Task() {} |
| 786 |
| 787 private: |
| 788 std::string etldp1_; |
| 789 CookieMonster::HasCookiesForETLDP1Callback callback_; |
| 790 |
| 791 DISALLOW_COPY_AND_ASSIGN(HasCookiesForETLDP1Task); |
| 792 }; |
| 793 |
| 794 void CookieMonster::HasCookiesForETLDP1Task::Run() { |
| 795 bool result = this->cookie_monster()->HasCookiesForETLDP1(etldp1_); |
| 796 if (!callback_.is_null()) { |
| 797 this->InvokeCallback( |
| 798 base::Bind(&CookieMonster::HasCookiesForETLDP1Callback::Run, |
| 799 base::Unretained(&callback_), result)); |
| 800 } |
| 801 } |
| 802 |
768 // Asynchronous CookieMonster API | 803 // Asynchronous CookieMonster API |
769 | 804 |
770 void CookieMonster::SetCookieWithDetailsAsync( | 805 void CookieMonster::SetCookieWithDetailsAsync( |
771 const GURL& url, | 806 const GURL& url, |
772 const std::string& name, | 807 const std::string& name, |
773 const std::string& value, | 808 const std::string& value, |
774 const std::string& domain, | 809 const std::string& domain, |
775 const std::string& path, | 810 const std::string& path, |
776 const base::Time& expiration_time, | 811 const base::Time& expiration_time, |
777 bool secure, | 812 bool secure, |
(...skipping 28 matching lines...) Expand all Loading... |
806 void CookieMonster::GetAllCookiesForURLAsync( | 841 void CookieMonster::GetAllCookiesForURLAsync( |
807 const GURL& url, const GetCookieListCallback& callback) { | 842 const GURL& url, const GetCookieListCallback& callback) { |
808 CookieOptions options; | 843 CookieOptions options; |
809 options.set_include_httponly(); | 844 options.set_include_httponly(); |
810 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = | 845 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = |
811 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); | 846 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); |
812 | 847 |
813 DoCookieTaskForURL(task, url); | 848 DoCookieTaskForURL(task, url); |
814 } | 849 } |
815 | 850 |
| 851 void CookieMonster::HasCookiesForETLDP1Async( |
| 852 const std::string& etldp1, |
| 853 const HasCookiesForETLDP1Callback& callback) { |
| 854 scoped_refptr<HasCookiesForETLDP1Task> task = |
| 855 new HasCookiesForETLDP1Task(this, etldp1, callback); |
| 856 |
| 857 DoCookieTaskForURL(task, GURL("http://" + etldp1)); |
| 858 } |
| 859 |
816 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { | 860 void CookieMonster::DeleteAllAsync(const DeleteCallback& callback) { |
817 scoped_refptr<DeleteAllTask> task = | 861 scoped_refptr<DeleteAllTask> task = |
818 new DeleteAllTask(this, callback); | 862 new DeleteAllTask(this, callback); |
819 | 863 |
820 DoCookieTask(task); | 864 DoCookieTask(task); |
821 } | 865 } |
822 | 866 |
823 void CookieMonster::DeleteAllCreatedBetweenAsync( | 867 void CookieMonster::DeleteAllCreatedBetweenAsync( |
824 const Time& delete_begin, const Time& delete_end, | 868 const Time& delete_begin, const Time& delete_end, |
825 const DeleteCallback& callback) { | 869 const DeleteCallback& callback) { |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 InternalDeleteCookie(curit, | 1269 InternalDeleteCookie(curit, |
1226 true, /*sync_to_store*/ | 1270 true, /*sync_to_store*/ |
1227 DELETE_COOKIE_EXPIRED); | 1271 DELETE_COOKIE_EXPIRED); |
1228 ++num_deleted; | 1272 ++num_deleted; |
1229 } | 1273 } |
1230 } | 1274 } |
1231 | 1275 |
1232 return num_deleted; | 1276 return num_deleted; |
1233 } | 1277 } |
1234 | 1278 |
| 1279 bool CookieMonster::HasCookiesForETLDP1(const std::string& etldp1) { |
| 1280 base::AutoLock autolock(lock_); |
| 1281 |
| 1282 const std::string key(GetKey(etldp1)); |
| 1283 |
| 1284 CookieMapItPair its = cookies_.equal_range(key); |
| 1285 return its.first != its.second; |
| 1286 } |
| 1287 |
1235 CookieMonster* CookieMonster::GetCookieMonster() { | 1288 CookieMonster* CookieMonster::GetCookieMonster() { |
1236 return this; | 1289 return this; |
1237 } | 1290 } |
1238 | 1291 |
1239 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { | 1292 void CookieMonster::SetPersistSessionCookies(bool persist_session_cookies) { |
1240 // This function must be called before the CookieMonster is used. | 1293 // This function must be called before the CookieMonster is used. |
1241 DCHECK(!initialized_); | 1294 DCHECK(!initialized_); |
1242 persist_session_cookies_ = persist_session_cookies; | 1295 persist_session_cookies_ = persist_session_cookies; |
1243 } | 1296 } |
1244 | 1297 |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 | 2064 |
2012 // The system resolution is not high enough, so we can have multiple | 2065 // The system resolution is not high enough, so we can have multiple |
2013 // set cookies that result in the same system time. When this happens, we | 2066 // set cookies that result in the same system time. When this happens, we |
2014 // increment by one Time unit. Let's hope computers don't get too fast. | 2067 // increment by one Time unit. Let's hope computers don't get too fast. |
2015 Time CookieMonster::CurrentTime() { | 2068 Time CookieMonster::CurrentTime() { |
2016 return std::max(Time::Now(), | 2069 return std::max(Time::Now(), |
2017 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); | 2070 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); |
2018 } | 2071 } |
2019 | 2072 |
2020 } // namespace net | 2073 } // namespace net |
OLD | NEW |