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

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

Issue 233353003: Only commit cookie changes in prerenders after a prerender is shown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync @269781 + 'autlock'->'autolock' from erik's comment that was not included before 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
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_store_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
56 #include "base/message_loop/message_loop.h" 57 #include "base/message_loop/message_loop.h"
57 #include "base/message_loop/message_loop_proxy.h" 58 #include "base/message_loop/message_loop_proxy.h"
58 #include "base/metrics/histogram.h" 59 #include "base/metrics/histogram.h"
59 #include "base/strings/string_util.h" 60 #include "base/strings/string_util.h"
60 #include "base/strings/stringprintf.h" 61 #include "base/strings/stringprintf.h"
61 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 62 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
62 #include "net/cookies/canonical_cookie.h" 63 #include "net/cookies/canonical_cookie.h"
63 #include "net/cookies/cookie_util.h" 64 #include "net/cookies/cookie_util.h"
64 #include "net/cookies/parsed_cookie.h" 65 #include "net/cookies/parsed_cookie.h"
65 #include "url/gurl.h" 66 #include "url/gurl.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 cookie_line += (*it)->Value(); 305 cookie_line += (*it)->Value();
305 } 306 }
306 return cookie_line; 307 return cookie_line;
307 } 308 }
308 309
309 } // namespace 310 } // namespace
310 311
311 CookieMonster::CookieMonster(PersistentCookieStore* store, 312 CookieMonster::CookieMonster(PersistentCookieStore* store,
312 CookieMonsterDelegate* delegate) 313 CookieMonsterDelegate* delegate)
313 : initialized_(false), 314 : initialized_(false),
314 loaded_(false), 315 loaded_(store == NULL),
315 store_(store), 316 store_(store),
316 last_access_threshold_( 317 last_access_threshold_(
317 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)), 318 TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
318 delegate_(delegate), 319 delegate_(delegate),
319 last_statistic_record_time_(Time::Now()), 320 last_statistic_record_time_(Time::Now()),
320 keep_expired_cookies_(false), 321 keep_expired_cookies_(false),
321 persist_session_cookies_(false) { 322 persist_session_cookies_(false) {
322 InitializeHistograms(); 323 InitializeHistograms();
323 SetDefaultCookieableSchemes(); 324 SetDefaultCookieableSchemes();
324 } 325 }
325 326
326 CookieMonster::CookieMonster(PersistentCookieStore* store, 327 CookieMonster::CookieMonster(PersistentCookieStore* store,
327 CookieMonsterDelegate* delegate, 328 CookieMonsterDelegate* delegate,
328 int last_access_threshold_milliseconds) 329 int last_access_threshold_milliseconds)
329 : initialized_(false), 330 : initialized_(false),
330 loaded_(false), 331 loaded_(store == NULL),
331 store_(store), 332 store_(store),
332 last_access_threshold_(base::TimeDelta::FromMilliseconds( 333 last_access_threshold_(base::TimeDelta::FromMilliseconds(
333 last_access_threshold_milliseconds)), 334 last_access_threshold_milliseconds)),
334 delegate_(delegate), 335 delegate_(delegate),
335 last_statistic_record_time_(base::Time::Now()), 336 last_statistic_record_time_(base::Time::Now()),
336 keep_expired_cookies_(false), 337 keep_expired_cookies_(false),
337 persist_session_cookies_(false) { 338 persist_session_cookies_(false) {
338 InitializeHistograms(); 339 InitializeHistograms();
339 SetDefaultCookieableSchemes(); 340 SetDefaultCookieableSchemes();
340 } 341 }
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 } 1427 }
1427 1428
1428 void CookieMonster::InitStore() { 1429 void CookieMonster::InitStore() {
1429 DCHECK(store_.get()) << "Store must exist to initialize"; 1430 DCHECK(store_.get()) << "Store must exist to initialize";
1430 1431
1431 // We bind in the current time so that we can report the wall-clock time for 1432 // We bind in the current time so that we can report the wall-clock time for
1432 // loading cookies. 1433 // loading cookies.
1433 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now())); 1434 store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now()));
1434 } 1435 }
1435 1436
1437 void CookieMonster::ReportLoaded() {
1438 if (delegate_.get())
1439 delegate_->OnLoaded();
1440 }
1441
1436 void CookieMonster::OnLoaded(TimeTicks beginning_time, 1442 void CookieMonster::OnLoaded(TimeTicks beginning_time,
1437 const std::vector<CanonicalCookie*>& cookies) { 1443 const std::vector<CanonicalCookie*>& cookies) {
1438 StoreLoadedCookies(cookies); 1444 StoreLoadedCookies(cookies);
1439 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time); 1445 histogram_time_blocked_on_load_->AddTime(TimeTicks::Now() - beginning_time);
1440 1446
1441 // Invoke the task queue of cookie request. 1447 // Invoke the task queue of cookie request.
1442 InvokeQueue(); 1448 InvokeQueue();
1449
1450 ReportLoaded();
1443 } 1451 }
1444 1452
1445 void CookieMonster::OnKeyLoaded(const std::string& key, 1453 void CookieMonster::OnKeyLoaded(const std::string& key,
1446 const std::vector<CanonicalCookie*>& cookies) { 1454 const std::vector<CanonicalCookie*>& cookies) {
1447 // This function does its own separate locking. 1455 // This function does its own separate locking.
1448 StoreLoadedCookies(cookies); 1456 StoreLoadedCookies(cookies);
1449 1457
1450 std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key; 1458 std::deque<scoped_refptr<CookieMonsterTask> > tasks_pending_for_key;
1451 1459
1452 // We need to do this repeatedly until no more tasks were added to the queue 1460 // 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
2238 2246
2239 2247
2240 // The system resolution is not high enough, so we can have multiple 2248 // The system resolution is not high enough, so we can have multiple
2241 // set cookies that result in the same system time. When this happens, we 2249 // set cookies that result in the same system time. When this happens, we
2242 // increment by one Time unit. Let's hope computers don't get too fast. 2250 // increment by one Time unit. Let's hope computers don't get too fast.
2243 Time CookieMonster::CurrentTime() { 2251 Time CookieMonster::CurrentTime() {
2244 return std::max(Time::Now(), 2252 return std::max(Time::Now(),
2245 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1)); 2253 Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
2246 } 2254 }
2247 2255
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
2248 } // namespace net 2307 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_store_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698