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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/cookies/cookie_monster.h ('k') | net/cookies/cookie_monster_store_test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/cookie_monster.cc
===================================================================
--- net/cookies/cookie_monster.cc (revision 269781)
+++ net/cookies/cookie_monster.cc (working copy)
@@ -53,6 +53,7 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/scoped_vector.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
@@ -311,7 +312,7 @@
CookieMonster::CookieMonster(PersistentCookieStore* store,
CookieMonsterDelegate* delegate)
: initialized_(false),
- loaded_(false),
+ loaded_(store == NULL),
store_(store),
last_access_threshold_(
TimeDelta::FromSeconds(kDefaultAccessUpdateThresholdSeconds)),
@@ -327,7 +328,7 @@
CookieMonsterDelegate* delegate,
int last_access_threshold_milliseconds)
: initialized_(false),
- loaded_(false),
+ loaded_(store == NULL),
store_(store),
last_access_threshold_(base::TimeDelta::FromMilliseconds(
last_access_threshold_milliseconds)),
@@ -1433,6 +1434,11 @@
store_->Load(base::Bind(&CookieMonster::OnLoaded, this, TimeTicks::Now()));
}
+void CookieMonster::ReportLoaded() {
+ if (delegate_.get())
+ delegate_->OnLoaded();
+}
+
void CookieMonster::OnLoaded(TimeTicks beginning_time,
const std::vector<CanonicalCookie*>& cookies) {
StoreLoadedCookies(cookies);
@@ -1440,6 +1446,8 @@
// Invoke the task queue of cookie request.
InvokeQueue();
+
+ ReportLoaded();
}
void CookieMonster::OnKeyLoaded(const std::string& key,
@@ -2245,4 +2253,55 @@
Time::FromInternalValue(last_time_seen_.ToInternalValue() + 1));
}
+bool CookieMonster::CopyCookiesForKeyToOtherCookieMonster(
+ std::string key,
+ CookieMonster* other) {
+ ScopedVector<CanonicalCookie> duplicated_cookies;
+
+ {
+ base::AutoLock autolock(lock_);
+ DCHECK(other);
+ if (!loaded_)
+ return false;
+
+ for (CookieMapItPair its = cookies_.equal_range(key);
+ its.first != its.second;
+ ++its.first) {
+ CookieMap::iterator curit = its.first;
+ CanonicalCookie* cc = curit->second;
+
+ duplicated_cookies.push_back(cc->Duplicate());
+ }
+ }
+
+ {
+ base::AutoLock autolock(other->lock_);
+ if (!other->loaded_)
+ return false;
+
+ // There must not exist any entries for the key to be copied in |other|.
+ CookieMapItPair its = other->cookies_.equal_range(key);
+ if (its.first != its.second)
+ return false;
+
+ // Store the copied cookies in |other|.
+ for (ScopedVector<CanonicalCookie>::const_iterator it =
+ duplicated_cookies.begin();
+ it != duplicated_cookies.end();
+ ++it) {
+ other->InternalInsertCookie(key, *it, true);
+ }
+
+ // Since the cookies are owned by |other| now, weak clear must be used.
+ duplicated_cookies.weak_clear();
+ }
+
+ return true;
+}
+
+bool CookieMonster::loaded() {
+ base::AutoLock autolock(lock_);
+ return loaded_;
+}
+
} // namespace net
« 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