Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: net/cookies/cookie_monster.cc

Issue 1666513002: Promote CookieMonster::DeleteCanonicalCookieAsync to CookieStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cookie_monster13
Patch Set: Rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 693
694 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask); 694 DISALLOW_COPY_AND_ASSIGN(DeleteAllCreatedBetweenForHostTask);
695 }; 695 };
696 696
697 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() { 697 int CookieMonster::DeleteAllCreatedBetweenForHostTask::RunDeleteTask() {
698 return this->cookie_monster()->DeleteAllCreatedBetweenForHost( 698 return this->cookie_monster()->DeleteAllCreatedBetweenForHost(
699 delete_begin_, delete_end_, url_); 699 delete_begin_, delete_end_, url_);
700 } 700 }
701 701
702 // Task class for DeleteCanonicalCookie call. 702 // Task class for DeleteCanonicalCookie call.
703 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<bool> { 703 class CookieMonster::DeleteCanonicalCookieTask : public DeleteTask<int> {
704 public: 704 public:
705 DeleteCanonicalCookieTask(CookieMonster* cookie_monster, 705 DeleteCanonicalCookieTask(CookieMonster* cookie_monster,
706 const CanonicalCookie& cookie, 706 const CanonicalCookie& cookie,
707 const DeleteCookieCallback& callback) 707 const DeleteCallback& callback)
708 : DeleteTask<bool>(cookie_monster, callback), cookie_(cookie) {} 708 : DeleteTask<int>(cookie_monster, callback), cookie_(cookie) {}
709 709
710 // DeleteTask: 710 // DeleteTask:
711 bool RunDeleteTask() override; 711 int RunDeleteTask() override;
712 712
713 protected: 713 protected:
714 ~DeleteCanonicalCookieTask() override {} 714 ~DeleteCanonicalCookieTask() override {}
715 715
716 private: 716 private:
717 CanonicalCookie cookie_; 717 CanonicalCookie cookie_;
718 718
719 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask); 719 DISALLOW_COPY_AND_ASSIGN(DeleteCanonicalCookieTask);
720 }; 720 };
721 721
722 bool CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() { 722 int CookieMonster::DeleteCanonicalCookieTask::RunDeleteTask() {
723 return this->cookie_monster()->DeleteCanonicalCookie(cookie_); 723 return this->cookie_monster()->DeleteCanonicalCookie(cookie_);
724 } 724 }
725 725
726 // Task class for SetCookieWithOptions call. 726 // Task class for SetCookieWithOptions call.
727 class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask { 727 class CookieMonster::SetCookieWithOptionsTask : public CookieMonsterTask {
728 public: 728 public:
729 SetCookieWithOptionsTask(CookieMonster* cookie_monster, 729 SetCookieWithOptionsTask(CookieMonster* cookie_monster,
730 const GURL& url, 730 const GURL& url,
731 const std::string& cookie_line, 731 const std::string& cookie_line,
732 const CookieOptions& options, 732 const CookieOptions& options,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 void CookieMonster::GetAllCookiesForURLWithOptionsAsync( 919 void CookieMonster::GetAllCookiesForURLWithOptionsAsync(
920 const GURL& url, 920 const GURL& url,
921 const CookieOptions& options, 921 const CookieOptions& options,
922 const GetCookieListCallback& callback) { 922 const GetCookieListCallback& callback) {
923 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task = 923 scoped_refptr<GetAllCookiesForURLWithOptionsTask> task =
924 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback); 924 new GetAllCookiesForURLWithOptionsTask(this, url, options, callback);
925 925
926 DoCookieTaskForURL(task, url); 926 DoCookieTaskForURL(task, url);
927 } 927 }
928 928
929 void CookieMonster::DeleteCanonicalCookieAsync(
930 const CanonicalCookie& cookie,
931 const DeleteCookieCallback& callback) {
932 scoped_refptr<DeleteCanonicalCookieTask> task =
933 new DeleteCanonicalCookieTask(this, cookie, callback);
934
935 DoCookieTask(task);
936 }
937
938 void CookieMonster::FlushStore(const base::Closure& callback) { 929 void CookieMonster::FlushStore(const base::Closure& callback) {
939 base::AutoLock autolock(lock_); 930 base::AutoLock autolock(lock_);
940 if (initialized_ && store_.get()) 931 if (initialized_ && store_.get())
941 store_->Flush(callback); 932 store_->Flush(callback);
942 else if (!callback.is_null()) 933 else if (!callback.is_null())
943 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 934 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
944 } 935 }
945 936
946 void CookieMonster::SetAllCookiesAsync(const CookieList& list, 937 void CookieMonster::SetAllCookiesAsync(const CookieList& list,
947 const SetCookiesCallback& callback) { 938 const SetCookiesCallback& callback) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 982
992 void CookieMonster::DeleteCookieAsync(const GURL& url, 983 void CookieMonster::DeleteCookieAsync(const GURL& url,
993 const std::string& cookie_name, 984 const std::string& cookie_name,
994 const base::Closure& callback) { 985 const base::Closure& callback) {
995 scoped_refptr<DeleteCookieTask> task = 986 scoped_refptr<DeleteCookieTask> task =
996 new DeleteCookieTask(this, url, cookie_name, callback); 987 new DeleteCookieTask(this, url, cookie_name, callback);
997 988
998 DoCookieTaskForURL(task, url); 989 DoCookieTaskForURL(task, url);
999 } 990 }
1000 991
992 void CookieMonster::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
993 const DeleteCallback& callback) {
994 scoped_refptr<DeleteCanonicalCookieTask> task =
995 new DeleteCanonicalCookieTask(this, cookie, callback);
996
997 DoCookieTask(task);
998 }
999
1001 void CookieMonster::DeleteAllCreatedBetweenAsync( 1000 void CookieMonster::DeleteAllCreatedBetweenAsync(
1002 const Time& delete_begin, 1001 const Time& delete_begin,
1003 const Time& delete_end, 1002 const Time& delete_end,
1004 const DeleteCallback& callback) { 1003 const DeleteCallback& callback) {
1005 scoped_refptr<DeleteAllCreatedBetweenTask> task = 1004 scoped_refptr<DeleteAllCreatedBetweenTask> task =
1006 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback); 1005 new DeleteAllCreatedBetweenTask(this, delete_begin, delete_end, callback);
1007 1006
1008 DoCookieTask(task); 1007 DoCookieTask(task);
1009 } 1008 }
1010 1009
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1244 (delete_end.is_null() || cc->CreationDate() < delete_end)) { 1243 (delete_end.is_null() || cc->CreationDate() < delete_end)) {
1245 num_deleted++; 1244 num_deleted++;
1246 1245
1247 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); 1246 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT);
1248 } 1247 }
1249 } 1248 }
1250 return num_deleted; 1249 return num_deleted;
1251 } 1250 }
1252 1251
1253 1252
1254 bool CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) {
1255 base::AutoLock autolock(lock_);
1256
1257 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain()));
1258 its.first != its.second; ++its.first) {
1259 // The creation date acts as our unique index...
1260 if (its.first->second->CreationDate() == cookie.CreationDate()) {
1261 InternalDeleteCookie(its.first, true, DELETE_COOKIE_EXPLICIT);
1262 return true;
1263 }
1264 }
1265 return false;
1266 }
1267
1268 bool CookieMonster::SetCookieWithOptions(const GURL& url, 1253 bool CookieMonster::SetCookieWithOptions(const GURL& url,
1269 const std::string& cookie_line, 1254 const std::string& cookie_line,
1270 const CookieOptions& options) { 1255 const CookieOptions& options) {
1271 base::AutoLock autolock(lock_); 1256 base::AutoLock autolock(lock_);
1272 1257
1273 if (!HasCookieableScheme(url)) { 1258 if (!HasCookieableScheme(url)) {
1274 return false; 1259 return false;
1275 } 1260 }
1276 1261
1277 return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options); 1262 return SetCookieWithCreationTimeAndOptions(url, cookie_line, Time(), options);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 1306
1322 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) { 1307 for (CookieMap::iterator it = cookies_.begin(); it != cookies_.end();) {
1323 CookieMap::iterator curit = it; 1308 CookieMap::iterator curit = it;
1324 ++it; 1309 ++it;
1325 if (matching_cookies.find(curit->second) != matching_cookies.end()) { 1310 if (matching_cookies.find(curit->second) != matching_cookies.end()) {
1326 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT); 1311 InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT);
1327 } 1312 }
1328 } 1313 }
1329 } 1314 }
1330 1315
1316 int CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie) {
1317 base::AutoLock autolock(lock_);
1318
1319 for (CookieMapItPair its = cookies_.equal_range(GetKey(cookie.Domain()));
1320 its.first != its.second; ++its.first) {
1321 // The creation date acts as the unique index...
1322 if (its.first->second->CreationDate() == cookie.CreationDate()) {
1323 InternalDeleteCookie(its.first, true, DELETE_COOKIE_EXPLICIT);
1324 return 1;
1325 }
1326 }
1327 return 0;
1328 }
1329
1331 bool CookieMonster::SetCookieWithCreationTime(const GURL& url, 1330 bool CookieMonster::SetCookieWithCreationTime(const GURL& url,
1332 const std::string& cookie_line, 1331 const std::string& cookie_line,
1333 const base::Time& creation_time) { 1332 const base::Time& creation_time) {
1334 DCHECK(!store_.get()) << "This method is only to be used by unit-tests."; 1333 DCHECK(!store_.get()) << "This method is only to be used by unit-tests.";
1335 base::AutoLock autolock(lock_); 1334 base::AutoLock autolock(lock_);
1336 1335
1337 if (!HasCookieableScheme(url)) { 1336 if (!HasCookieableScheme(url)) {
1338 return false; 1337 return false;
1339 } 1338 }
1340 1339
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
2381 it != hook_map_.end(); ++it) { 2380 it != hook_map_.end(); ++it) {
2382 std::pair<GURL, std::string> key = it->first; 2381 std::pair<GURL, std::string> key = it->first;
2383 if (cookie.IncludeForRequestURL(key.first, opts) && 2382 if (cookie.IncludeForRequestURL(key.first, opts) &&
2384 cookie.Name() == key.second) { 2383 cookie.Name() == key.second) {
2385 it->second->Notify(cookie, removed); 2384 it->second->Notify(cookie, removed);
2386 } 2385 }
2387 } 2386 }
2388 } 2387 }
2389 2388
2390 } // namespace net 2389 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698