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

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

Issue 23551005: Revert 219709 "Remove the Extensions URLRequestContext." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // first iterator with access date >= |access_date|, or cookie_its_end if this 249 // first iterator with access date >= |access_date|, or cookie_its_end if this
250 // holds for all. 250 // holds for all.
251 CookieMonster::CookieItVector::iterator LowerBoundAccessDate( 251 CookieMonster::CookieItVector::iterator LowerBoundAccessDate(
252 const CookieMonster::CookieItVector::iterator its_begin, 252 const CookieMonster::CookieItVector::iterator its_begin,
253 const CookieMonster::CookieItVector::iterator its_end, 253 const CookieMonster::CookieItVector::iterator its_end,
254 const Time& access_date) { 254 const Time& access_date) {
255 return std::lower_bound(its_begin, its_end, access_date, 255 return std::lower_bound(its_begin, its_end, access_date,
256 LowerBoundAccessDateComparator); 256 LowerBoundAccessDateComparator);
257 } 257 }
258 258
259 // Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the 259 // Mapping between DeletionCause and Delegate::ChangeCause; the mapping also
260 // mapping also provides a boolean that specifies whether or not an 260 // provides a boolean that specifies whether or not an OnCookieChanged
261 // OnCookieChanged notification ought to be generated. 261 // notification ought to be generated.
262 typedef struct ChangeCausePair_struct { 262 typedef struct ChangeCausePair_struct {
263 CookieMonsterDelegate::ChangeCause cause; 263 CookieMonster::Delegate::ChangeCause cause;
264 bool notify; 264 bool notify;
265 } ChangeCausePair; 265 } ChangeCausePair;
266 ChangeCausePair ChangeCauseMapping[] = { 266 ChangeCausePair ChangeCauseMapping[] = {
267 // DELETE_COOKIE_EXPLICIT 267 // DELETE_COOKIE_EXPLICIT
268 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true }, 268 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, true },
269 // DELETE_COOKIE_OVERWRITE 269 // DELETE_COOKIE_OVERWRITE
270 { CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true }, 270 { CookieMonster::Delegate::CHANGE_COOKIE_OVERWRITE, true },
271 // DELETE_COOKIE_EXPIRED 271 // DELETE_COOKIE_EXPIRED
272 { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true }, 272 { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED, true },
273 // DELETE_COOKIE_EVICTED 273 // DELETE_COOKIE_EVICTED
274 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, 274 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
275 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE 275 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE
276 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, 276 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false },
277 // DELETE_COOKIE_DONT_RECORD 277 // DELETE_COOKIE_DONT_RECORD
278 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false }, 278 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false },
279 // DELETE_COOKIE_EVICTED_DOMAIN 279 // DELETE_COOKIE_EVICTED_DOMAIN
280 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, 280 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
281 // DELETE_COOKIE_EVICTED_GLOBAL 281 // DELETE_COOKIE_EVICTED_GLOBAL
282 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, 282 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
283 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE 283 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE
284 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, 284 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
285 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE 285 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE
286 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true }, 286 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true },
287 // DELETE_COOKIE_EXPIRED_OVERWRITE 287 // DELETE_COOKIE_EXPIRED_OVERWRITE
288 { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, 288 { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true },
289 // DELETE_COOKIE_LAST_ENTRY 289 // DELETE_COOKIE_LAST_ENTRY
290 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false } 290 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }
291 }; 291 };
292 292
293 std::string BuildCookieLine(const CanonicalCookieVector& cookies) { 293 std::string BuildCookieLine(const CanonicalCookieVector& cookies) {
294 std::string cookie_line; 294 std::string cookie_line;
295 for (CanonicalCookieVector::const_iterator it = cookies.begin(); 295 for (CanonicalCookieVector::const_iterator it = cookies.begin();
296 it != cookies.end(); ++it) { 296 it != cookies.end(); ++it) {
297 if (it != cookies.begin()) 297 if (it != cookies.begin())
298 cookie_line += "; "; 298 cookie_line += "; ";
299 // In Mozilla if you set a cookie like AAAA, it will have an empty token 299 // In Mozilla if you set a cookie like AAAA, it will have an empty token
300 // and a value of AAAA. When it sends the cookie back, it will send AAAA, 300 // and a value of AAAA. When it sends the cookie back, it will send AAAA,
301 // so we need to avoid sending =AAAA for a blank token value. 301 // so we need to avoid sending =AAAA for a blank token value.
302 if (!(*it)->Name().empty()) 302 if (!(*it)->Name().empty())
303 cookie_line += (*it)->Name() + "="; 303 cookie_line += (*it)->Name() + "=";
304 cookie_line += (*it)->Value(); 304 cookie_line += (*it)->Value();
305 } 305 }
306 return cookie_line; 306 return cookie_line;
307 } 307 }
308 308
309 } // namespace 309 } // namespace
310 310
311 CookieMonster::CookieMonster(PersistentCookieStore* store, 311 // static
312 CookieMonsterDelegate* delegate) 312 bool CookieMonster::default_enable_file_scheme_ = false;
313
314 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate)
313 : initialized_(false), 315 : initialized_(false),
314 loaded_(false), 316 loaded_(false),
315 store_(store), 317 store_(store),
316 last_access_threshold_( 318 last_access_threshold_(
317 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), 319 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
318 delegate_(delegate), 320 delegate_(delegate),
319 last_statistic_record_time_(Time::Now()), 321 last_statistic_record_time_(Time::Now()),
320 keep_expired_cookies_(false), 322 keep_expired_cookies_(false),
321 persist_session_cookies_(false), 323 persist_session_cookies_(false),
322 priority_aware_garbage_collection_(false) { 324 priority_aware_garbage_collection_(false) {
323 InitializeHistograms(); 325 InitializeHistograms();
324 SetDefaultCookieableSchemes(); 326 SetDefaultCookieableSchemes();
325 } 327 }
326 328
327 CookieMonster::CookieMonster(PersistentCookieStore* store, 329 CookieMonster::CookieMonster(PersistentCookieStore* store,
328 CookieMonsterDelegate* delegate, 330 Delegate* delegate,
329 int last_access_threshold_milliseconds) 331 int last_access_threshold_milliseconds)
330 : initialized_(false), 332 : initialized_(false),
331 loaded_(false), 333 loaded_(false),
332 store_(store), 334 store_(store),
333 last_access_threshold_(base::TimeDelta::FromMilliseconds( 335 last_access_threshold_(base::TimeDelta::FromMilliseconds(
334 last_access_threshold_milliseconds)), 336 last_access_threshold_milliseconds)),
335 delegate_(delegate), 337 delegate_(delegate),
336 last_statistic_record_time_(base::Time::Now()), 338 last_statistic_record_time_(base::Time::Now()),
337 keep_expired_cookies_(false), 339 keep_expired_cookies_(false),
338 persist_session_cookies_(false), 340 persist_session_cookies_(false),
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 // above kDefaultCookieableSchemes. 1272 // above kDefaultCookieableSchemes.
1271 int num_schemes = accept ? kDefaultCookieableSchemesCount : 1273 int num_schemes = accept ? kDefaultCookieableSchemesCount :
1272 kDefaultCookieableSchemesCount - 1; 1274 kDefaultCookieableSchemesCount - 1;
1273 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); 1275 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes);
1274 } 1276 }
1275 1277
1276 void CookieMonster::SetKeepExpiredCookies() { 1278 void CookieMonster::SetKeepExpiredCookies() {
1277 keep_expired_cookies_ = true; 1279 keep_expired_cookies_ = true;
1278 } 1280 }
1279 1281
1282 // static
1283 void CookieMonster::EnableFileScheme() {
1284 default_enable_file_scheme_ = true;
1285 }
1286
1280 void CookieMonster::FlushStore(const base::Closure& callback) { 1287 void CookieMonster::FlushStore(const base::Closure& callback) {
1281 base::AutoLock autolock(lock_); 1288 base::AutoLock autolock(lock_);
1282 if (initialized_ && store_.get()) 1289 if (initialized_ && store_.get())
1283 store_->Flush(callback); 1290 store_->Flush(callback);
1284 else if (!callback.is_null()) 1291 else if (!callback.is_null())
1285 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 1292 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
1286 } 1293 }
1287 1294
1288 bool CookieMonster::SetCookieWithOptions(const GURL& url, 1295 bool CookieMonster::SetCookieWithOptions(const GURL& url,
1289 const std::string& cookie_line, 1296 const std::string& cookie_line,
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 return num_duplicates; 1635 return num_duplicates;
1629 } 1636 }
1630 1637
1631 // Note: file must be the last scheme. 1638 // Note: file must be the last scheme.
1632 const char* CookieMonster::kDefaultCookieableSchemes[] = 1639 const char* CookieMonster::kDefaultCookieableSchemes[] =
1633 { "http", "https", "file" }; 1640 { "http", "https", "file" };
1634 const int CookieMonster::kDefaultCookieableSchemesCount = 1641 const int CookieMonster::kDefaultCookieableSchemesCount =
1635 arraysize(CookieMonster::kDefaultCookieableSchemes); 1642 arraysize(CookieMonster::kDefaultCookieableSchemes);
1636 1643
1637 void CookieMonster::SetDefaultCookieableSchemes() { 1644 void CookieMonster::SetDefaultCookieableSchemes() {
1638 // Always disable file scheme unless SetEnableFileScheme(true) is called. 1645 int num_schemes = default_enable_file_scheme_ ?
1639 SetCookieableSchemes(kDefaultCookieableSchemes, 1646 kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1;
1640 kDefaultCookieableSchemesCount - 1); 1647 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes);
1641 } 1648 }
1642 1649
1643 void CookieMonster::FindCookiesForHostAndDomain( 1650 void CookieMonster::FindCookiesForHostAndDomain(
1644 const GURL& url, 1651 const GURL& url,
1645 const CookieOptions& options, 1652 const CookieOptions& options,
1646 bool update_access_time, 1653 bool update_access_time,
1647 std::vector<CanonicalCookie*>* cookies) { 1654 std::vector<CanonicalCookie*>* cookies) {
1648 lock_.AssertAcquired(); 1655 lock_.AssertAcquired();
1649 1656
1650 const Time current_time(CurrentTime()); 1657 const Time current_time(CurrentTime());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 CanonicalCookie* cc, 1737 CanonicalCookie* cc,
1731 bool sync_to_store) { 1738 bool sync_to_store) {
1732 lock_.AssertAcquired(); 1739 lock_.AssertAcquired();
1733 1740
1734 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && 1741 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() &&
1735 sync_to_store) 1742 sync_to_store)
1736 store_->AddCookie(*cc); 1743 store_->AddCookie(*cc);
1737 cookies_.insert(CookieMap::value_type(key, cc)); 1744 cookies_.insert(CookieMap::value_type(key, cc));
1738 if (delegate_.get()) { 1745 if (delegate_.get()) {
1739 delegate_->OnCookieChanged( 1746 delegate_->OnCookieChanged(
1740 *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT); 1747 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT);
1741 } 1748 }
1742 } 1749 }
1743 1750
1744 bool CookieMonster::SetCookieWithCreationTimeAndOptions( 1751 bool CookieMonster::SetCookieWithCreationTimeAndOptions(
1745 const GURL& url, 1752 const GURL& url,
1746 const std::string& cookie_line, 1753 const std::string& cookie_line,
1747 const Time& creation_time_or_null, 1754 const Time& creation_time_or_null,
1748 const CookieOptions& options) { 1755 const CookieOptions& options) {
1749 lock_.AssertAcquired(); 1756 lock_.AssertAcquired();
1750 1757
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2207 2214
2208 // The system resolution is not high enough, so we can have multiple 2215 // The system resolution is not high enough, so we can have multiple
2209 // set cookies that result in the same system time. When this happens, we 2216 // set cookies that result in the same system time. When this happens, we
2210 // increment by one Time unit. Let's hope computers don't get too fast. 2217 // increment by one Time unit. Let's hope computers don't get too fast.
2211 Time CookieMonster::CurrentTime() { 2218 Time CookieMonster::CurrentTime() {
2212 return std::max(Time::Now(), 2219 return std::max(Time::Now(),
2213 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); 2220 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
2214 } 2221 }
2215 2222
2216 } // namespace net 2223 } // namespace net
OLDNEW
« no previous file with comments | « trunk/src/net/cookies/cookie_monster.h ('k') | trunk/src/net/cookies/cookie_monster_store_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698