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

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

Issue 1701063002: CookieStore: Remove reference counting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@threadsafe
Patch Set: Fix leak Created 4 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 // 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 delegate_(delegate), 345 delegate_(delegate),
346 last_statistic_record_time_(base::Time::Now()), 346 last_statistic_record_time_(base::Time::Now()),
347 persist_session_cookies_(false), 347 persist_session_cookies_(false),
348 weak_ptr_factory_(this) { 348 weak_ptr_factory_(this) {
349 InitializeHistograms(); 349 InitializeHistograms();
350 cookieable_schemes_.insert( 350 cookieable_schemes_.insert(
351 cookieable_schemes_.begin(), kDefaultCookieableSchemes, 351 cookieable_schemes_.begin(), kDefaultCookieableSchemes,
352 kDefaultCookieableSchemes + kDefaultCookieableSchemesCount); 352 kDefaultCookieableSchemes + kDefaultCookieableSchemesCount);
353 } 353 }
354 354
355 CookieMonster::~CookieMonster() {
356 DCHECK(thread_checker_.CalledOnValidThread());
357
358 // TODO(mmenke): Does it really make sense to run |delegate_| and
359 // CookieChanged callbacks when the CookieStore is destroyed?
360 for (CookieMap::iterator cookie_it = cookies_.begin();
361 cookie_it != cookies_.end();) {
362 CookieMap::iterator current_cookie_it = cookie_it;
363 ++cookie_it;
364 InternalDeleteCookie(current_cookie_it, false /* sync_to_store */,
365 DELETE_COOKIE_DONT_RECORD);
366 }
367 }
368
355 // Task classes for queueing the coming request. 369 // Task classes for queueing the coming request.
356 370
357 class CookieMonster::CookieMonsterTask 371 class CookieMonster::CookieMonsterTask
358 : public base::RefCountedThreadSafe<CookieMonsterTask> { 372 : public base::RefCountedThreadSafe<CookieMonsterTask> {
359 public: 373 public:
360 // Runs the task and invokes the client callback on the thread that 374 // Runs the task and invokes the client callback on the thread that
361 // originally constructed the task. 375 // originally constructed the task.
362 virtual void Run() = 0; 376 virtual void Run() = 0;
363 377
364 protected: 378 protected:
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 const SetCookiesCallback& callback) { 860 const SetCookiesCallback& callback) {
847 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask( 861 scoped_refptr<SetCookieWithDetailsTask> task = new SetCookieWithDetailsTask(
848 this, url, name, value, domain, path, creation_time, expiration_time, 862 this, url, name, value, domain, path, creation_time, expiration_time,
849 last_access_time, secure, http_only, same_site, enforce_strict_secure, 863 last_access_time, secure, http_only, same_site, enforce_strict_secure,
850 priority, callback); 864 priority, callback);
851 DoCookieTaskForURL(task, url); 865 DoCookieTaskForURL(task, url);
852 } 866 }
853 867
854 void CookieMonster::FlushStore(const base::Closure& callback) { 868 void CookieMonster::FlushStore(const base::Closure& callback) {
855 DCHECK(thread_checker_.CalledOnValidThread()); 869 DCHECK(thread_checker_.CalledOnValidThread());
870
856 if (initialized_ && store_.get()) 871 if (initialized_ && store_.get())
857 store_->Flush(callback); 872 store_->Flush(callback);
858 else if (!callback.is_null()) 873 else if (!callback.is_null())
859 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 874 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
860 } 875 }
861 876
862 void CookieMonster::SetForceKeepSessionState() { 877 void CookieMonster::SetForceKeepSessionState() {
863 DCHECK(thread_checker_.CalledOnValidThread()); 878 DCHECK(thread_checker_.CalledOnValidThread());
879
864 if (store_) 880 if (store_)
865 store_->SetForceKeepSessionState(); 881 store_->SetForceKeepSessionState();
866 } 882 }
867 883
868 void CookieMonster::SetAllCookiesAsync(const CookieList& list, 884 void CookieMonster::SetAllCookiesAsync(const CookieList& list,
869 const SetCookiesCallback& callback) { 885 const SetCookiesCallback& callback) {
870 scoped_refptr<SetAllCookiesTask> task = 886 scoped_refptr<SetAllCookiesTask> task =
871 new SetAllCookiesTask(this, list, callback); 887 new SetAllCookiesTask(this, list, callback);
872 DoCookieTask(task); 888 DoCookieTask(task);
873 } 889 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", "https", 1001 const char* const CookieMonster::kDefaultCookieableSchemes[] = {"http", "https",
986 "ws", "wss"}; 1002 "ws", "wss"};
987 const int CookieMonster::kDefaultCookieableSchemesCount = 1003 const int CookieMonster::kDefaultCookieableSchemesCount =
988 arraysize(kDefaultCookieableSchemes); 1004 arraysize(kDefaultCookieableSchemes);
989 1005
990 scoped_ptr<CookieStore::CookieChangedSubscription> 1006 scoped_ptr<CookieStore::CookieChangedSubscription>
991 CookieMonster::AddCallbackForCookie(const GURL& gurl, 1007 CookieMonster::AddCallbackForCookie(const GURL& gurl,
992 const std::string& name, 1008 const std::string& name,
993 const CookieChangedCallback& callback) { 1009 const CookieChangedCallback& callback) {
994 DCHECK(thread_checker_.CalledOnValidThread()); 1010 DCHECK(thread_checker_.CalledOnValidThread());
1011
995 std::pair<GURL, std::string> key(gurl, name); 1012 std::pair<GURL, std::string> key(gurl, name);
996 if (hook_map_.count(key) == 0) 1013 if (hook_map_.count(key) == 0)
997 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList()); 1014 hook_map_[key] = make_linked_ptr(new CookieChangedCallbackList());
998 return hook_map_[key]->Add( 1015 return hook_map_[key]->Add(
999 base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback)); 1016 base::Bind(&RunAsync, base::ThreadTaskRunnerHandle::Get(), callback));
1000 } 1017 }
1001 1018
1002 CookieMonster::~CookieMonster() {
1003 DCHECK(thread_checker_.CalledOnValidThread());
1004
1005 for (CookieMap::iterator cookie_it = cookies_.begin();
1006 cookie_it != cookies_.end();) {
1007 CookieMap::iterator current_cookie_it = cookie_it;
1008 ++cookie_it;
1009 InternalDeleteCookie(current_cookie_it, false /* sync_to_store */,
1010 DELETE_COOKIE_DONT_RECORD);
1011 }
1012 }
1013
1014 bool CookieMonster::SetCookieWithDetails(const GURL& url, 1019 bool CookieMonster::SetCookieWithDetails(const GURL& url,
1015 const std::string& name, 1020 const std::string& name,
1016 const std::string& value, 1021 const std::string& value,
1017 const std::string& domain, 1022 const std::string& domain,
1018 const std::string& path, 1023 const std::string& path,
1019 base::Time creation_time, 1024 base::Time creation_time,
1020 base::Time expiration_time, 1025 base::Time expiration_time,
1021 base::Time last_access_time, 1026 base::Time last_access_time,
1022 bool secure, 1027 bool secure,
1023 bool http_only, 1028 bool http_only,
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie, 2403 void CookieMonster::RunCookieChangedCallbacks(const CanonicalCookie& cookie,
2399 bool removed) { 2404 bool removed) {
2400 DCHECK(thread_checker_.CalledOnValidThread()); 2405 DCHECK(thread_checker_.CalledOnValidThread());
2401 2406
2402 CookieOptions opts; 2407 CookieOptions opts;
2403 opts.set_include_httponly(); 2408 opts.set_include_httponly();
2404 opts.set_include_same_site(); 2409 opts.set_include_same_site();
2405 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they 2410 // Note that the callbacks in hook_map_ are wrapped with RunAsync(), so they
2406 // are guaranteed to not take long - they just post a RunAsync task back to 2411 // are guaranteed to not take long - they just post a RunAsync task back to
2407 // the appropriate thread's message loop and return. 2412 // the appropriate thread's message loop and return.
2408 // TODO(mmenke): Consider running these synchronously? 2413 // TODO(mmenke): Consider running these synchronously, and/or cancelling them
2414 // when the CookieMonster is destroyed?
2409 for (CookieChangedHookMap::iterator it = hook_map_.begin(); 2415 for (CookieChangedHookMap::iterator it = hook_map_.begin();
2410 it != hook_map_.end(); ++it) { 2416 it != hook_map_.end(); ++it) {
2411 std::pair<GURL, std::string> key = it->first; 2417 std::pair<GURL, std::string> key = it->first;
2412 if (cookie.IncludeForRequestURL(key.first, opts) && 2418 if (cookie.IncludeForRequestURL(key.first, opts) &&
2413 cookie.Name() == key.second) { 2419 cookie.Name() == key.second) {
2414 it->second->Notify(cookie, removed); 2420 it->second->Notify(cookie, removed);
2415 } 2421 }
2416 } 2422 }
2417 } 2423 }
2418 2424
2419 } // namespace net 2425 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698