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

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: compile gdi. 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 CookieMonster::CookieMonster(PersistentCookieStore* store,
312 bool CookieMonster::default_enable_file_scheme_ = false; 312 CookieMonsterDelegate* delegate)
313
314 CookieMonster::CookieMonster(PersistentCookieStore* store, Delegate* delegate)
315 : initialized_(false), 313 : initialized_(false),
316 loaded_(false), 314 loaded_(false),
317 store_(store), 315 store_(store),
318 last_access_threshold_( 316 last_access_threshold_(
319 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), 317 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
320 delegate_(delegate), 318 delegate_(delegate),
321 last_statistic_record_time_(Time::Now()), 319 last_statistic_record_time_(Time::Now()),
322 keep_expired_cookies_(false), 320 keep_expired_cookies_(false),
323 persist_session_cookies_(false), 321 persist_session_cookies_(false),
324 priority_aware_garbage_collection_(false) { 322 priority_aware_garbage_collection_(false) {
325 InitializeHistograms(); 323 InitializeHistograms();
326 SetDefaultCookieableSchemes(); 324 SetDefaultCookieableSchemes();
327 } 325 }
328 326
329 CookieMonster::CookieMonster(PersistentCookieStore* store, 327 CookieMonster::CookieMonster(PersistentCookieStore* store,
330 Delegate* delegate, 328 CookieMonsterDelegate* delegate,
331 int last_access_threshold_milliseconds) 329 int last_access_threshold_milliseconds)
332 : initialized_(false), 330 : initialized_(false),
333 loaded_(false), 331 loaded_(false),
334 store_(store), 332 store_(store),
335 last_access_threshold_(base::TimeDelta::FromMilliseconds( 333 last_access_threshold_(base::TimeDelta::FromMilliseconds(
336 last_access_threshold_milliseconds)), 334 last_access_threshold_milliseconds)),
337 delegate_(delegate), 335 delegate_(delegate),
338 last_statistic_record_time_(base::Time::Now()), 336 last_statistic_record_time_(base::Time::Now()),
339 keep_expired_cookies_(false), 337 keep_expired_cookies_(false),
340 persist_session_cookies_(false), 338 persist_session_cookies_(false),
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 // above kDefaultCookieableSchemes. 1206 // above kDefaultCookieableSchemes.
1209 int num_schemes = accept ? kDefaultCookieableSchemesCount : 1207 int num_schemes = accept ? kDefaultCookieableSchemesCount :
1210 kDefaultCookieableSchemesCount - 1; 1208 kDefaultCookieableSchemesCount - 1;
1211 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); 1209 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes);
1212 } 1210 }
1213 1211
1214 void CookieMonster::SetKeepExpiredCookies() { 1212 void CookieMonster::SetKeepExpiredCookies() {
1215 keep_expired_cookies_ = true; 1213 keep_expired_cookies_ = true;
1216 } 1214 }
1217 1215
1218 // static
1219 void CookieMonster::EnableFileScheme() {
1220 default_enable_file_scheme_ = true;
1221 }
1222
1223 void CookieMonster::FlushStore(const base::Closure& callback) { 1216 void CookieMonster::FlushStore(const base::Closure& callback) {
1224 base::AutoLock autolock(lock_); 1217 base::AutoLock autolock(lock_);
1225 if (initialized_ && store_.get()) 1218 if (initialized_ && store_.get())
1226 store_->Flush(callback); 1219 store_->Flush(callback);
1227 else if (!callback.is_null()) 1220 else if (!callback.is_null())
1228 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 1221 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
1229 } 1222 }
1230 1223
1231 bool CookieMonster::SetCookieWithOptions(const GURL& url, 1224 bool CookieMonster::SetCookieWithOptions(const GURL& url,
1232 const std::string& cookie_line, 1225 const std::string& cookie_line,
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 return num_duplicates; 1564 return num_duplicates;
1572 } 1565 }
1573 1566
1574 // Note: file must be the last scheme. 1567 // Note: file must be the last scheme.
1575 const char* CookieMonster::kDefaultCookieableSchemes[] = 1568 const char* CookieMonster::kDefaultCookieableSchemes[] =
1576 { "http", "https", "file" }; 1569 { "http", "https", "file" };
1577 const int CookieMonster::kDefaultCookieableSchemesCount = 1570 const int CookieMonster::kDefaultCookieableSchemesCount =
1578 arraysize(CookieMonster::kDefaultCookieableSchemes); 1571 arraysize(CookieMonster::kDefaultCookieableSchemes);
1579 1572
1580 void CookieMonster::SetDefaultCookieableSchemes() { 1573 void CookieMonster::SetDefaultCookieableSchemes() {
1581 int num_schemes = default_enable_file_scheme_ ? 1574 // Always disable file scheme unless SetEnableFileScheme(true) is called.
1582 kDefaultCookieableSchemesCount : kDefaultCookieableSchemesCount - 1; 1575 SetCookieableSchemes(kDefaultCookieableSchemes,
1583 SetCookieableSchemes(kDefaultCookieableSchemes, num_schemes); 1576 kDefaultCookieableSchemesCount - 1);
1584 } 1577 }
1585 1578
1586 void CookieMonster::FindCookiesForHostAndDomain( 1579 void CookieMonster::FindCookiesForHostAndDomain(
1587 const GURL& url, 1580 const GURL& url,
1588 const CookieOptions& options, 1581 const CookieOptions& options,
1589 bool update_access_time, 1582 bool update_access_time,
1590 std::vector<CanonicalCookie*>* cookies) { 1583 std::vector<CanonicalCookie*>* cookies) {
1591 lock_.AssertAcquired(); 1584 lock_.AssertAcquired();
1592 1585
1593 const Time current_time(CurrentTime()); 1586 const Time current_time(CurrentTime());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 CanonicalCookie* cc, 1666 CanonicalCookie* cc,
1674 bool sync_to_store) { 1667 bool sync_to_store) {
1675 lock_.AssertAcquired(); 1668 lock_.AssertAcquired();
1676 1669
1677 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() && 1670 if ((cc->IsPersistent() || persist_session_cookies_) && store_.get() &&
1678 sync_to_store) 1671 sync_to_store)
1679 store_->AddCookie(*cc); 1672 store_->AddCookie(*cc);
1680 cookies_.insert(CookieMap::value_type(key, cc)); 1673 cookies_.insert(CookieMap::value_type(key, cc));
1681 if (delegate_.get()) { 1674 if (delegate_.get()) {
1682 delegate_->OnCookieChanged( 1675 delegate_->OnCookieChanged(
1683 *cc, false, CookieMonster::Delegate::CHANGE_COOKIE_EXPLICIT); 1676 *cc, false, CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT);
1684 } 1677 }
1685 } 1678 }
1686 1679
1687 bool CookieMonster::SetCookieWithCreationTimeAndOptions( 1680 bool CookieMonster::SetCookieWithCreationTimeAndOptions(
1688 const GURL& url, 1681 const GURL& url,
1689 const std::string& cookie_line, 1682 const std::string& cookie_line,
1690 const Time& creation_time_or_null, 1683 const Time& creation_time_or_null,
1691 const CookieOptions& options) { 1684 const CookieOptions& options) {
1692 lock_.AssertAcquired(); 1685 lock_.AssertAcquired();
1693 1686
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 2143
2151 // The system resolution is not high enough, so we can have multiple 2144 // 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 2145 // 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. 2146 // increment by one Time unit. Let's hope computers don't get too fast.
2154 Time CookieMonster::CurrentTime() { 2147 Time CookieMonster::CurrentTime() {
2155 return std::max(Time::Now(), 2148 return std::max(Time::Now(),
2156 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); 2149 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
2157 } 2150 }
2158 2151
2159 } // namespace net 2152 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698