| Index: net/cookies/cookie_monster.cc
|
| ===================================================================
|
| --- net/cookies/cookie_monster.cc (revision 269838)
|
| +++ 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
|
|
|