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

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

Issue 280383002: Revert 269855 "Only commit cookie changes in prerenders after a ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 #include <algorithm> 47 #include <algorithm>
48 #include <functional> 48 #include <functional>
49 #include <set> 49 #include <set>
50 50
51 #include "base/basictypes.h" 51 #include "base/basictypes.h"
52 #include "base/bind.h" 52 #include "base/bind.h"
53 #include "base/callback.h" 53 #include "base/callback.h"
54 #include "base/logging.h" 54 #include "base/logging.h"
55 #include "base/memory/scoped_ptr.h" 55 #include "base/memory/scoped_ptr.h"
56 #include "base/memory/scoped_vector.h"
57 #include "base/message_loop/message_loop.h" 56 #include "base/message_loop/message_loop.h"
58 #include "base/message_loop/message_loop_proxy.h" 57 #include "base/message_loop/message_loop_proxy.h"
59 #include "base/metrics/histogram.h" 58 #include "base/metrics/histogram.h"
60 #include "base/strings/string_util.h" 59 #include "base/strings/string_util.h"
61 #include "base/strings/stringprintf.h" 60 #include "base/strings/stringprintf.h"
62 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 61 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
63 #include "net/cookies/canonical_cookie.h" 62 #include "net/cookies/canonical_cookie.h"
64 #include "net/cookies/cookie_util.h" 63 #include "net/cookies/cookie_util.h"
65 #include "net/cookies/parsed_cookie.h" 64 #include "net/cookies/parsed_cookie.h"
66 #include "url/gurl.h" 65 #include "url/gurl.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 cookie_line += (*it)->Value(); 304 cookie_line += (*it)->Value();
306 } 305 }
307 return cookie_line; 306 return cookie_line;
308 } 307 }
309 308
310 } // namespace 309 } // namespace
311 310
312 CookieMonster::CookieMonster(PersistentCookieStore* store, 311 CookieMonster::CookieMonster(PersistentCookieStore* store,
313 CookieMonsterDelegate* delegate) 312 CookieMonsterDelegate* delegate)
314 : initialized_(false), 313 : initialized_(false),
315 loaded_(store == NULL), 314 loaded_(false),
316 store_(store), 315 store_(store),
317 last_access_threshold_( 316 last_access_threshold_(
318 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), 317 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
319 delegate_(delegate), 318 delegate_(delegate),
320 last_statistic_record_time_(Time::Now()), 319 last_statistic_record_time_(Time::Now()),
321 keep_expired_cookies_(false), 320 keep_expired_cookies_(false),
322 persist_session_cookies_(false) { 321 persist_session_cookies_(false) {
323 InitializeHistograms(); 322 InitializeHistograms();
324 SetDefaultCookieableSchemes(); 323 SetDefaultCookieableSchemes();
325 } 324 }
326 325
327 CookieMonster::CookieMonster(PersistentCookieStore* store, 326 CookieMonster::CookieMonster(PersistentCookieStore* store,
328 CookieMonsterDelegate* delegate, 327 CookieMonsterDelegate* delegate,
329 int last_access_threshold_milliseconds) 328 int last_access_threshold_milliseconds)
330 : initialized_(false), 329 : initialized_(false),
331 loaded_(store == NULL), 330 loaded_(false),
332 store_(store), 331 store_(store),
333 last_access_threshold_(base::TimeDelta::FromMilliseconds( 332 last_access_threshold_(base::TimeDelta::FromMilliseconds(
334 last_access_threshold_milliseconds)), 333 last_access_threshold_milliseconds)),
335 delegate_(delegate), 334 delegate_(delegate),
336 last_statistic_record_time_(base::Time::Now()), 335 last_statistic_record_time_(base::Time::Now()),
337 keep_expired_cookies_(false), 336 keep_expired_cookies_(false),
338 persist_session_cookies_(false) { 337 persist_session_cookies_(false) {
339 InitializeHistograms(); 338 InitializeHistograms();
340 SetDefaultCookieableSchemes(); 339 SetDefaultCookieableSchemes();
341 } 340 }
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 } 1426 }
1428 1427
1429 void CookieMonster::InitStore() { 1428 void CookieMonster::InitStore() {
1430 DCHECK(store_.get()) << "Store must exist to initialize"; 1429 DCHECK(store_.get()) << "Store must exist to initialize";
1431 1430
1432 // We bind in the current time so that we can report the wall-clock time for 1431 // We bind in the current time so that we can report the wall-clock time for
1433 // loading cookies. 1432 // loading cookies.
1434 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now())); 1433 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now()));
1435 } 1434 }
1436 1435
1437 void CookieMonster::ReportLoaded() {
1438 if (delegate_.get())
1439 delegate_->OnLoaded();
1440 }
1441
1442 void CookieMonster::OnLoaded(TimeTicks beginning_time, 1436 void CookieMonster::OnLoaded(TimeTicks beginning_time,
1443 const std::vector<CanonicalCookie*>& cookies) { 1437 const std::vector<CanonicalCookie*>& cookies) {
1444 StoreLoadedCookies(cookies); 1438 StoreLoadedCookies(cookies);
1445 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time); 1439 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time);
1446 1440
1447 // Invoke the task queue of cookie request. 1441 // Invoke the task queue of cookie request.
1448 InvokeQueue(); 1442 InvokeQueue();
1449
1450 ReportLoaded();
1451 } 1443 }
1452 1444
1453 void CookieMonster::OnKeyLoaded(const std::string& key, 1445 void CookieMonster::OnKeyLoaded(const std::string& key,
1454 const std::vector<CanonicalCookie*>& cookies) { 1446 const std::vector<CanonicalCookie*>& cookies) {
1455 // This function does its own separate locking. 1447 // This function does its own separate locking.
1456 StoreLoadedCookies(cookies); 1448 StoreLoadedCookies(cookies);
1457 1449
1458 std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key; 1450 std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key;
1459 1451
1460 // We need to do this repeatedly until no more tasks were added to the queue 1452 // We need to do this repeatedly until no more tasks were added to the queue
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 2238
2247 2239
2248 // The system resolution is not high enough, so we can have multiple 2240 // The system resolution is not high enough, so we can have multiple
2249 // set cookies that result in the same system time. When this happens, we 2241 // set cookies that result in the same system time. When this happens, we
2250 // increment by one Time unit. Let's hope computers don't get too fast. 2242 // increment by one Time unit. Let's hope computers don't get too fast.
2251 Time CookieMonster::CurrentTime() { 2243 Time CookieMonster::CurrentTime() {
2252 return std::max(Time::Now(), 2244 return std::max(Time::Now(),
2253 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); 2245 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
2254 } 2246 }
2255 2247
2256 bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster(
2257 std::string key,
2258 CookieMonster* other) {
2259 ScopedVector<CanonicalCookie> duplicated_cookies;
2260
2261 {
2262 base::AutoLock autolock(lock_);
2263 DCHECK(other);
2264 if (!loaded_)
2265 return false;
2266
2267 for (CookieMapItPair its = cookies_.equal_range(key);
2268 its.first != its.second;
2269 ++its.first) {
2270 CookieMap::iterator curit = its.first;
2271 CanonicalCookie* cc = curit->second;
2272
2273 duplicated_cookies.push_back(cc->Duplicate());
2274 }
2275 }
2276
2277 {
2278 base::AutoLock autolock(other->lock_);
2279 if (!other->loaded_)
2280 return false;
2281
2282 // There must not exist any entries for the key to be copied in |other|.
2283 CookieMapItPair its = other->cookies_.equal_range(key);
2284 if (its.first != its.second)
2285 return false;
2286
2287 // Store the copied cookies in |other|.
2288 for (ScopedVector<CanonicalCookie>::const_iterator it =
2289 duplicated_cookies.begin();
2290 it != duplicated_cookies.end();
2291 ++it) {
2292 other->InternalInsertCookie(key, *it, true);
2293 }
2294
2295 // Since the cookies are owned by |other| now, weak clear must be used.
2296 duplicated_cookies.weak_clear();
2297 }
2298
2299 return true;
2300 }
2301
2302 bool CookieMonster::loaded() {
2303 base::AutoLock autolock(lock_);
2304 return loaded_;
2305 }
2306
2307 } // namespace net 2248 } // 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