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

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

Issue 1000103002: Add a method to override all the cookies in CookieMonster (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 9 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
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 // Brought to you by the letter D and the number 2. 5 // Brought to you by the letter D and the number 2.
6 6
7 #ifndef NET_COOKIES_COOKIE_MONSTER_H_ 7 #ifndef NET_COOKIES_COOKIE_MONSTER_H_
8 #define NET_COOKIES_COOKIE_MONSTER_H_ 8 #define NET_COOKIES_COOKIE_MONSTER_H_
9 9
10 #include <deque> 10 #include <deque>
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void SetForceKeepSessionState(); 227 void SetForceKeepSessionState();
228 228
229 // Flush the backing store (if any) to disk and post the given callback when 229 // Flush the backing store (if any) to disk and post the given callback when
230 // done. 230 // done.
231 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE. 231 // WARNING: THE CALLBACK WILL RUN ON A RANDOM THREAD. IT MUST BE THREAD SAFE.
232 // It may be posted to the current thread, or it may run on the thread that 232 // It may be posted to the current thread, or it may run on the thread that
233 // actually does the flushing. Your Task should generally post a notification 233 // actually does the flushing. Your Task should generally post a notification
234 // to the thread you actually want to be notified on. 234 // to the thread you actually want to be notified on.
235 void FlushStore(const base::Closure& callback); 235 void FlushStore(const base::Closure& callback);
236 236
237 // Replaces all the cookies by |list|. This method does not flush the backend.
238 void SetAllCookiesAsync(const CookieList& list,
239 const SetCookiesCallback& callback);
240
237 // CookieStore implementation. 241 // CookieStore implementation.
238 242
239 // Sets the cookies specified by |cookie_list| returned from |url| 243 // Sets the cookies specified by |cookie_list| returned from |url|
240 // with options |options| in effect. 244 // with options |options| in effect.
241 void SetCookieWithOptionsAsync(const GURL& url, 245 void SetCookieWithOptionsAsync(const GURL& url,
242 const std::string& cookie_line, 246 const std::string& cookie_line,
243 const CookieOptions& options, 247 const CookieOptions& options,
244 const SetCookiesCallback& callback) override; 248 const SetCookiesCallback& callback) override;
245 249
246 // Gets all cookies that apply to |url| given |options|. 250 // Gets all cookies that apply to |url| given |options|.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 class DeleteTask; 319 class DeleteTask;
316 class DeleteAllCreatedBetweenTask; 320 class DeleteAllCreatedBetweenTask;
317 class DeleteAllCreatedBetweenForHostTask; 321 class DeleteAllCreatedBetweenForHostTask;
318 class DeleteAllForHostTask; 322 class DeleteAllForHostTask;
319 class DeleteAllTask; 323 class DeleteAllTask;
320 class DeleteCookieTask; 324 class DeleteCookieTask;
321 class DeleteCanonicalCookieTask; 325 class DeleteCanonicalCookieTask;
322 class GetAllCookiesForURLWithOptionsTask; 326 class GetAllCookiesForURLWithOptionsTask;
323 class GetAllCookiesTask; 327 class GetAllCookiesTask;
324 class GetCookiesWithOptionsTask; 328 class GetCookiesWithOptionsTask;
329 class SetAllCookiesTask;
325 class SetCookieWithDetailsTask; 330 class SetCookieWithDetailsTask;
326 class SetCookieWithOptionsTask; 331 class SetCookieWithOptionsTask;
327 class DeleteSessionCookiesTask; 332 class DeleteSessionCookiesTask;
328 class HasCookiesForETLDP1Task; 333 class HasCookiesForETLDP1Task;
329 334
330 // Testing support. 335 // Testing support.
331 // For SetCookieWithCreationTime. 336 // For SetCookieWithCreationTime.
332 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, 337 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest,
333 TestCookieDeleteAllCreatedBetweenTimestamps); 338 TestCookieDeleteAllCreatedBetweenTimestamps);
334 // For SetCookieWithCreationTime. 339 // For SetCookieWithCreationTime.
335 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCookieMonsterTest, 340 FRIEND_TEST_ALL_PREFIXES(MultiThreadedCookieMonsterTest,
336 ThreadCheckDeleteAllCreatedBetweenForHost); 341 ThreadCheckDeleteAllCreatedBetweenForHost);
337 342
338 // For gargage collection constants. 343 // For gargage collection constants.
339 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection); 344 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestHostGarbageCollection);
340 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection); 345 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestTotalGarbageCollection);
341 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers); 346 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GarbageCollectionTriggers);
342 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes); 347 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGCTimes);
343 348
344 // For validation of key values. 349 // For validation of key values.
345 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestDomainTree); 350 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestDomainTree);
346 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestImport); 351 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestImport);
347 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey); 352 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, GetKey);
348 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey); 353 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, TestGetKey);
349 354
350 // For FindCookiesForKey. 355 // For FindCookiesForKey.
351 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies); 356 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ShortLivedSessionCookies);
352 357
358 // For ComputeCookieDiff.
359 FRIEND_TEST_ALL_PREFIXES(CookieMonsterTest, ComputeCookieDiff);
360
353 // Internal reasons for deletion, used to populate informative histograms 361 // Internal reasons for deletion, used to populate informative histograms
354 // and to provide a public cause for onCookieChange notifications. 362 // and to provide a public cause for onCookieChange notifications.
355 // 363 //
356 // If you add or remove causes from this list, please be sure to also update 364 // If you add or remove causes from this list, please be sure to also update
357 // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping. 365 // the CookieMonsterDelegate::ChangeCause mapping inside ChangeCauseMapping.
358 // Moreover, these are used as array indexes, so avoid reordering to keep the 366 // Moreover, these are used as array indexes, so avoid reordering to keep the
359 // histogram buckets consistent. New items (if necessary) should be added 367 // histogram buckets consistent. New items (if necessary) should be added
360 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY. 368 // at the end of the list, just before DELETE_COOKIE_LAST_ENTRY.
361 enum DeletionCause { 369 enum DeletionCause {
362 DELETE_COOKIE_EXPLICIT = 0, 370 DELETE_COOKIE_EXPLICIT = 0,
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 const std::string& cookie_line, 545 const std::string& cookie_line,
538 const base::Time& creation_time, 546 const base::Time& creation_time,
539 const CookieOptions& options); 547 const CookieOptions& options);
540 548
541 // Helper function that sets a canonical cookie, deleting equivalents and 549 // Helper function that sets a canonical cookie, deleting equivalents and
542 // performing garbage collection. 550 // performing garbage collection.
543 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc, 551 bool SetCanonicalCookie(scoped_ptr<CanonicalCookie>* cc,
544 const base::Time& creation_time, 552 const base::Time& creation_time,
545 const CookieOptions& options); 553 const CookieOptions& options);
546 554
555 // Helper function calling SetCanonicalCookie() for all cookies in |list|.
556 bool SetCanonicalCookies(const CookieList& list);
557
547 void InternalUpdateCookieAccessTime(CanonicalCookie* cc, 558 void InternalUpdateCookieAccessTime(CanonicalCookie* cc,
548 const base::Time& current_time); 559 const base::Time& current_time);
549 560
550 // |deletion_cause| argument is used for collecting statistics and choosing 561 // |deletion_cause| argument is used for collecting statistics and choosing
551 // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged 562 // the correct CookieMonsterDelegate::ChangeCause for OnCookieChanged
552 // notifications. Guarantee: All iterators to cookies_ except to the 563 // notifications. Guarantee: All iterators to cookies_ except to the
553 // deleted entry remain vaild. 564 // deleted entry remain vaild.
554 void InternalDeleteCookie(CookieMap::iterator it, 565 void InternalDeleteCookie(CookieMap::iterator it,
555 bool sync_to_store, 566 bool sync_to_store,
556 DeletionCause deletion_cause); 567 DeletionCause deletion_cause);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 612
602 // Runs the task if, or defers the task until, the full cookie database is 613 // Runs the task if, or defers the task until, the full cookie database is
603 // loaded. 614 // loaded.
604 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item); 615 void DoCookieTask(const scoped_refptr<CookieMonsterTask>& task_item);
605 616
606 // Runs the task if, or defers the task until, the cookies for the given URL 617 // Runs the task if, or defers the task until, the cookies for the given URL
607 // are loaded. 618 // are loaded.
608 void DoCookieTaskForURL(const scoped_refptr<CookieMonsterTask>& task_item, 619 void DoCookieTaskForURL(const scoped_refptr<CookieMonsterTask>& task_item,
609 const GURL& url); 620 const GURL& url);
610 621
622 // Computes the difference between |old_cookies| and |new_cookies|, and writes
623 // the result in |cookies_to_add| and |cookies_to_delete|.
624 // This function has the side effect of changing the order of |old_cookies|
625 // and |new_cookies|. |cookies_to_add| and |cookies_to_delete| must be empty,
626 // and none of the arguments can be null.
627 void ComputeCookieDiff(CookieList* old_cookies,
628 CookieList* new_cookies,
629 CookieList* cookies_to_add,
630 CookieList* cookies_to_delete);
631
611 // Run all cookie changed callbacks that are monitoring |cookie|. 632 // Run all cookie changed callbacks that are monitoring |cookie|.
612 // |removed| is true if the cookie was deleted. 633 // |removed| is true if the cookie was deleted.
613 void RunCallbacks(const CanonicalCookie& cookie, bool removed); 634 void RunCallbacks(const CanonicalCookie& cookie, bool removed);
614 635
615 // Histogram variables; see CookieMonster::InitializeHistograms() in 636 // Histogram variables; see CookieMonster::InitializeHistograms() in
616 // cookie_monster.cc for details. 637 // cookie_monster.cc for details.
617 base::HistogramBase* histogram_expiration_duration_minutes_; 638 base::HistogramBase* histogram_expiration_duration_minutes_;
618 base::HistogramBase* histogram_between_access_interval_minutes_; 639 base::HistogramBase* histogram_between_access_interval_minutes_;
619 base::HistogramBase* histogram_evicted_last_access_minutes_; 640 base::HistogramBase* histogram_evicted_last_access_minutes_;
620 base::HistogramBase* histogram_count_; 641 base::HistogramBase* histogram_count_;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 virtual ~PersistentCookieStore() {} 793 virtual ~PersistentCookieStore() {}
773 794
774 private: 795 private:
775 friend class base::RefCountedThreadSafe<PersistentCookieStore>; 796 friend class base::RefCountedThreadSafe<PersistentCookieStore>;
776 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore); 797 DISALLOW_COPY_AND_ASSIGN(PersistentCookieStore);
777 }; 798 };
778 799
779 } // namespace net 800 } // namespace net
780 801
781 #endif // NET_COOKIES_COOKIE_MONSTER_H_ 802 #endif // NET_COOKIES_COOKIE_MONSTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698