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

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

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: most unittests pass Created 7 years, 4 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 Delegate::ChangeCause; the mapping also 259 // Mapping between DeletionCause and CookieMonsterDelegate::ChangeCause; the
260 // provides a boolean that specifies whether or not an OnCookieChanged 260 // mapping also provides a boolean that specifies whether or not an
261 // notification ought to be generated. 261 // OnCookieChanged notification ought to be generated.
262 typedef struct ChangeCausePair_struct { 262 typedef struct ChangeCausePair_struct {
263 CookieMonster::Delegate::ChangeCause cause; 263 CookieMonsterDelegate::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 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, true }, 268 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, true },
269 // DELETE_COOKIE_OVERWRITE 269 // DELETE_COOKIE_OVERWRITE
270 { CookieMonster::Delegate::CHANGE_COOKIE_OVERWRITE, true }, 270 { CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE, true },
271 // DELETE_COOKIE_EXPIRED 271 // DELETE_COOKIE_EXPIRED
272 { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED, true }, 272 { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED, true },
273 // DELETE_COOKIE_EVICTED 273 // DELETE_COOKIE_EVICTED
274 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 274 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
275 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE 275 // DELETE_COOKIE_DUPLICATE_IN_BACKING_STORE
276 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }, 276 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false },
277 // DELETE_COOKIE_DONT_RECORD 277 // DELETE_COOKIE_DONT_RECORD
278 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false }, 278 { CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT, false },
279 // DELETE_COOKIE_EVICTED_DOMAIN 279 // DELETE_COOKIE_EVICTED_DOMAIN
280 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 280 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
281 // DELETE_COOKIE_EVICTED_GLOBAL 281 // DELETE_COOKIE_EVICTED_GLOBAL
282 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 282 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
283 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE 283 // DELETE_COOKIE_EVICTED_DOMAIN_PRE_SAFE
284 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 284 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
285 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE 285 // DELETE_COOKIE_EVICTED_DOMAIN_POST_SAFE
286 { CookieMonster::Delegate::CHANGE_COOKIE_EVICTED, true }, 286 { CookieMonsterDelegate::CHANGE_COOKIE_EVICTED, true },
287 // DELETE_COOKIE_EXPIRED_OVERWRITE 287 // DELETE_COOKIE_EXPIRED_OVERWRITE
288 { CookieMonster::Delegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true }, 288 { CookieMonsterDelegate::CHANGE_COOKIE_EXPIRED_OVERWRITE, true },
289 // DELETE_COOKIE_LAST_ENTRY 289 // DELETE_COOKIE_LAST_ENTRY
290 { CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT, false } 290 { CookieMonsterDelegate::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 // static 311 // static
312 bool CookieMonster::default_enable_file_scheme_ = false; 312 bool CookieMonster::default_enable_file_scheme_ = false;
313 313
314 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate) 314 CookieMonster::CookieMonster(PersistentCookieStore* store,
315 CookieMonsterDelegate* delegate)
315 : initialized_(false), 316 : initialized_(false),
316 loaded_(false), 317 loaded_(false),
317 store_(store), 318 store_(store),
318 last_access_threshold_( 319 last_access_threshold_(
319 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), 320 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
320 delegate_(delegate), 321 delegate_(delegate),
321 last_statistic_record_time_(Time::Now()), 322 last_statistic_record_time_(Time::Now()),
322 keep_expired_cookies_(false), 323 keep_expired_cookies_(false),
323 persist_session_cookies_(false), 324 persist_session_cookies_(false),
324 priority_aware_garbage_collection_(false) { 325 priority_aware_garbage_collection_(false) {
325 InitializeHistograms(); 326 InitializeHistograms();
326 SetDefaultCookieableSchemes(); 327 SetDefaultCookieableSchemes();
327 } 328 }
328 329
329 CookieMonster::CookieMonster(PersistentCookieStore* store, 330 CookieMonster::CookieMonster(PersistentCookieStore* store,
330 Delegate* delegate, 331 CookieMonsterDelegate* delegate,
331 int last_access_threshold_milliseconds) 332 int last_access_threshold_milliseconds)
332 : initialized_(false), 333 : initialized_(false),
333 loaded_(false), 334 loaded_(false),
334 store_(store), 335 store_(store),
335 last_access_threshold_(base::TimeDelta::FromMilliseconds( 336 last_access_threshold_(base::TimeDelta::FromMilliseconds(
336 last_access_threshold_milliseconds)), 337 last_access_threshold_milliseconds)),
337 delegate_(delegate), 338 delegate_(delegate),
338 last_statistic_record_time_(base::Time::Now()), 339 last_statistic_record_time_(base::Time::Now()),
339 keep_expired_cookies_(false), 340 keep_expired_cookies_(false),
340 persist_session_cookies_(false), 341 persist_session_cookies_(false),
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 CanonicalCookie* cc, 1674 CanonicalCookie* cc,
1674 bool sync_to_store) { 1675 bool sync_to_store) {
1675 lock_.AssertAcquired(); 1676 lock_.AssertAcquired();
1676 1677
1677 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && 1678 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() &&
1678 sync_to_store) 1679 sync_to_store)
1679 store_->AddCookie(*cc); 1680 store_->AddCookie(*cc);
1680 cookies_.insert(CookieMap::value_type(key, cc)); 1681 cookies_.insert(CookieMap::value_type(key, cc));
1681 if (delegate_.get()) { 1682 if (delegate_.get()) {
1682 delegate_->OnCookieChanged( 1683 delegate_->OnCookieChanged(
1683 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT); 1684 *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT);
1684 } 1685 }
1685 } 1686 }
1686 1687
1687 bool CookieMonster::SetCookieWithCreationTimeAndOptions( 1688 bool CookieMonster::SetCookieWithCreationTimeAndOptions(
1688 const GURL& url, 1689 const GURL& url,
1689 const std::string& cookie_line, 1690 const std::string& cookie_line,
1690 const Time& creation_time_or_null, 1691 const Time& creation_time_or_null,
1691 const CookieOptions& options) { 1692 const CookieOptions& options) {
1692 lock_.AssertAcquired(); 1693 lock_.AssertAcquired();
1693 1694
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 2151
2151 // The system resolution is not high enough, so we can have multiple 2152 // The system resolution is not high enough, so we can have multiple
2152 // set cookies that result in the same system time. When this happens, we 2153 // set cookies that result in the same system time. When this happens, we
2153 // increment by one Time unit. Let's hope computers don't get too fast. 2154 // increment by one Time unit. Let's hope computers don't get too fast.
2154 Time CookieMonster::CurrentTime() { 2155 Time CookieMonster::CurrentTime() {
2155 return std::max(Time::Now(), 2156 return std::max(Time::Now(),
2156 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); 2157 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
2157 } 2158 }
2158 2159
2159 } // namespace net 2160 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698