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

Unified Diff: content/browser/net/quota_policy_cookie_store.cc

Issue 1016643004: Moves SQLitePersistentCookieStore to net/extras/sqlite. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cookies
Patch Set: Better timestamp fix. Created 5 years, 8 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
Index: content/browser/net/quota_policy_cookie_store.cc
diff --git a/content/browser/net/quota_policy_cookie_store.cc b/content/browser/net/quota_policy_cookie_store.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2b9786f0c432a613159d4e4598732baa6e7c0953
--- /dev/null
+++ b/content/browser/net/quota_policy_cookie_store.cc
@@ -0,0 +1,194 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/net/quota_policy_cookie_store.h"
+
+#include <list>
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/profiler/scoped_tracker.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/cookie_store_factory.h"
+#include "net/cookies/canonical_cookie.h"
+#include "net/cookies/cookie_constants.h"
+#include "net/cookies/cookie_util.h"
+#include "net/extras/sqlite/cookie_crypto_delegate.h"
+#include "storage/browser/quota/special_storage_policy.h"
+#include "url/gurl.h"
+
+namespace content {
+
+QuotaPolicyCookieStore::QuotaPolicyCookieStore(
+ const base::FilePath& path,
+ const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
+ const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
+ bool restore_old_session_cookies,
+ storage::SpecialStoragePolicy* special_storage_policy,
+ net::CookieCryptoDelegate* crypto_delegate)
+ : special_storage_policy_(special_storage_policy),
+ persistent_store_(
+ new net::SQLitePersistentCookieStore(path,
+ client_task_runner,
+ background_task_runner,
+ restore_old_session_cookies,
+ crypto_delegate)) {
Ryan Sleevi 2015/05/06 00:44:18 DESIGN: Does it make more sense to have the caller
rohitrao (ping after 24h) 2015/05/11 19:25:29 Makes sense, changed the API.
+ DCHECK(client_task_runner);
+ DCHECK(background_task_runner);
Ryan Sleevi 2015/05/06 00:44:18 These aren't needed here, are they? They're invari
rohitrao (ping after 24h) 2015/05/11 19:25:29 Obsolete now.
+}
+
+QuotaPolicyCookieStore::~QuotaPolicyCookieStore() {
+ if (!special_storage_policy_.get() ||
+ !special_storage_policy_->HasSessionOnlyOrigins()) {
+ return;
+ }
+
+ std::list<net::SQLitePersistentCookieStore::CookieOrigin>
+ session_only_cookies;
+ for (const auto& cookie : cookies_per_origin_) {
+ if (cookie.second <= 0) {
+ DCHECK_EQ(0, cookie.second);
+ continue;
+ }
Ryan Sleevi 2015/05/06 00:44:17 Wat? It seems like "<0" is an impossible conditio
rohitrao (ping after 24h) 2015/05/11 19:25:29 Done. I added a new DCHECK to DeleteCookie() to c
+ const GURL url(net::cookie_util::CookieOriginToURL(cookie.first.first,
+ cookie.first.second));
+ if (!url.is_valid() || !special_storage_policy_->IsStorageSessionOnly(url))
+ continue;
+
+ session_only_cookies.push_back(cookie.first);
+ }
+
+ persistent_store_->DeleteAllInList(session_only_cookies);
+}
+
+void QuotaPolicyCookieStore::Load(const LoadedCallback& loaded_callback) {
+ persistent_store_->Load(
+ base::Bind(&QuotaPolicyCookieStore::OnLoad, this, loaded_callback));
Ryan Sleevi 2015/05/06 00:44:18 DESIGN: It does strike me that this may be potenti
rohitrao (ping after 24h) 2015/05/11 19:25:29 Isn't the caller making lifetime assumptions that
Ryan Sleevi 2015/05/12 00:48:33 What lifetime assumptions do you see it making? I
+}
+
+void QuotaPolicyCookieStore::LoadCookiesForKey(
+ const std::string& key,
+ const LoadedCallback& loaded_callback) {
+ persistent_store_->LoadCookiesForKey(
+ key,
+ base::Bind(&QuotaPolicyCookieStore::OnLoad, this, loaded_callback));
+}
+
+void QuotaPolicyCookieStore::AddCookie(const net::CanonicalCookie& cc) {
+ cookies_per_origin_[
+ net::SQLitePersistentCookieStore::CookieOrigin(cc.Domain(),
+ cc.IsSecure())]++;
Ryan Sleevi 2015/05/06 00:44:17 This is valid, but pretty unreadable. net::SQLite
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
+ persistent_store_->AddCookie(cc);
+}
+
+void QuotaPolicyCookieStore::UpdateCookieAccessTime(
+ const net::CanonicalCookie& cc) {
+ persistent_store_->UpdateCookieAccessTime(cc);
+}
+
+void QuotaPolicyCookieStore::DeleteCookie(const net::CanonicalCookie& cc) {
+ cookies_per_origin_[
+ net::SQLitePersistentCookieStore::CookieOrigin(cc.Domain(),
+ cc.IsSecure())]--;
Ryan Sleevi 2015/05/06 00:44:18 ditto here
rohitrao (ping after 24h) 2015/05/11 19:25:29 Done.
+ persistent_store_->DeleteCookie(cc);
+}
+
+void QuotaPolicyCookieStore::SetForceKeepSessionState() {
+ special_storage_policy_ = NULL;
Ryan Sleevi 2015/05/06 00:44:18 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
+}
+
+void QuotaPolicyCookieStore::Flush(const base::Closure& callback) {
+ persistent_store_->Flush(callback);
+}
+
+void QuotaPolicyCookieStore::OnLoad(
+ const LoadedCallback& loaded_callback,
+ const std::vector<net::CanonicalCookie*>& cookies) {
+ for (const auto& cookie : cookies) {
+ cookies_per_origin_[
+ net::SQLitePersistentCookieStore::CookieOrigin(cookie->Domain(),
+ cookie->IsSecure())]++;
+ }
+
+ loaded_callback.Run(cookies);
+}
+
+CookieStoreConfig::CookieStoreConfig()
Ryan Sleevi 2015/05/06 00:44:18 It seems everything from here & below isn't define
rohitrao (ping after 24h) 2015/05/11 19:25:30 This is copied straight from the old content/net/b
Ryan Sleevi 2015/05/12 00:48:33 Yeah, I think splitting it up sounds right, but ha
+ : session_cookie_mode(EPHEMERAL_SESSION_COOKIES),
+ crypto_delegate(NULL) {
Ryan Sleevi 2015/05/06 00:44:18 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
+ // Default to an in-memory cookie store.
+}
+
+CookieStoreConfig::CookieStoreConfig(
+ const base::FilePath& path,
+ SessionCookieMode session_cookie_mode,
+ storage::SpecialStoragePolicy* storage_policy,
+ net::CookieMonsterDelegate* cookie_delegate)
+ : path(path),
+ session_cookie_mode(session_cookie_mode),
+ storage_policy(storage_policy),
+ cookie_delegate(cookie_delegate),
+ crypto_delegate(NULL) {
Ryan Sleevi 2015/05/06 00:44:17 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:30 Done.
+ CHECK(!path.empty() || session_cookie_mode == EPHEMERAL_SESSION_COOKIES);
+}
+
+CookieStoreConfig::~CookieStoreConfig() {
+}
+
+net::CookieStore* CreateCookieStore(const CookieStoreConfig& config) {
+ // TODO(bcwhite): Remove ScopedTracker below once crbug.com/483686 is fixed.
+ tracked_objects::ScopedTracker tracking_profile(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION("483686 content::CreateCookieStore"));
+
+ net::CookieMonster* cookie_monster = NULL;
Ryan Sleevi 2015/05/06 00:44:17 nullptr
rohitrao (ping after 24h) 2015/05/11 19:25:29 Done.
+
+ if (config.path.empty()) {
+ // Empty path means in-memory store.
+ cookie_monster = new net::CookieMonster(NULL, config.cookie_delegate.get());
+ } else {
+ scoped_refptr<base::SequencedTaskRunner> client_task_runner =
+ config.client_task_runner;
+ scoped_refptr<base::SequencedTaskRunner> background_task_runner =
+ config.background_task_runner;
+
+ if (!client_task_runner.get()) {
+ client_task_runner =
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
+ }
+
+ if (!background_task_runner.get()) {
+ background_task_runner =
+ BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
+ BrowserThread::GetBlockingPool()->GetSequenceToken());
+ }
+
+ QuotaPolicyCookieStore* persistent_store =
+ new QuotaPolicyCookieStore(
+ config.path,
+ client_task_runner,
+ background_task_runner,
+ (config.session_cookie_mode ==
+ CookieStoreConfig::RESTORED_SESSION_COOKIES),
Ryan Sleevi 2015/05/06 00:44:17 Is this all formatted with git cl format?
rohitrao (ping after 24h) 2015/05/11 19:25:30 Not yet. I figured we would just take the git cl
+ config.storage_policy.get(),
+ config.crypto_delegate);
+
+ cookie_monster =
+ new net::CookieMonster(persistent_store, config.cookie_delegate.get());
+ if ((config.session_cookie_mode ==
+ CookieStoreConfig::PERSISTANT_SESSION_COOKIES) ||
+ (config.session_cookie_mode ==
+ CookieStoreConfig::RESTORED_SESSION_COOKIES)) {
+ cookie_monster->SetPersistSessionCookies(true);
+ }
+ }
+
+ return cookie_monster;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698