Commit 1860223c authored by rohitrao's avatar rohitrao Committed by Commit bot

Reland "Moves SQLitePersistentCookieStore to net/extras/sqlite."

The application of special storage policy is split out into a new class,
QuotaPolicyCookieStore, in content/browser/net.

This reverts commit ac4f4964.

TBR=avi@chromium.org
BUG=467596
TEST=No visible impact.

Review URL: https://codereview.chromium.org/1138643004

Cr-Commit-Position: refs/heads/master@{#330257}
parent ce0d1804
...@@ -34,6 +34,7 @@ source_set("browser") { ...@@ -34,6 +34,7 @@ source_set("browser") {
"//device/vibration", "//device/vibration",
"//google_apis", "//google_apis",
"//net", "//net",
"//net:extras",
"//skia", "//skia",
"//sql", "//sql",
"//third_party/npapi", "//third_party/npapi",
......
// 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 scoped_refptr<net::SQLitePersistentCookieStore>& cookie_store,
storage::SpecialStoragePolicy* special_storage_policy)
: special_storage_policy_(special_storage_policy),
persistent_store_(cookie_store) {
}
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) {
continue;
}
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));
}
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) {
net::SQLitePersistentCookieStore::CookieOrigin origin(
cc.Domain(), cc.IsSecure());
++cookies_per_origin_[origin];
persistent_store_->AddCookie(cc);
}
void QuotaPolicyCookieStore::UpdateCookieAccessTime(
const net::CanonicalCookie& cc) {
persistent_store_->UpdateCookieAccessTime(cc);
}
void QuotaPolicyCookieStore::DeleteCookie(const net::CanonicalCookie& cc) {
net::SQLitePersistentCookieStore::CookieOrigin origin(
cc.Domain(), cc.IsSecure());
DCHECK_GE(cookies_per_origin_[origin], 1U);
--cookies_per_origin_[origin];
persistent_store_->DeleteCookie(cc);
}
void QuotaPolicyCookieStore::SetForceKeepSessionState() {
special_storage_policy_ = nullptr;
}
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) {
net::SQLitePersistentCookieStore::CookieOrigin origin(
cookie->Domain(), cookie->IsSecure());
++cookies_per_origin_[origin];
}
loaded_callback.Run(cookies);
}
CookieStoreConfig::CookieStoreConfig()
: session_cookie_mode(EPHEMERAL_SESSION_COOKIES),
crypto_delegate(nullptr) {
// 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(nullptr) {
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 = nullptr;
if (config.path.empty()) {
// Empty path means in-memory store.
cookie_monster = new net::CookieMonster(nullptr,
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());
}
scoped_refptr<net::SQLitePersistentCookieStore> sqlite_store(
new net::SQLitePersistentCookieStore(
config.path,
client_task_runner,
background_task_runner,
(config.session_cookie_mode ==
CookieStoreConfig::RESTORED_SESSION_COOKIES),
config.crypto_delegate));
QuotaPolicyCookieStore* persistent_store =
new QuotaPolicyCookieStore(
sqlite_store.get(),
config.storage_policy.get());
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
// 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.
#ifndef CONTENT_BROWSER_NET_QUOTA_POLICY_COOKIE_STORE_H_
#define CONTENT_BROWSER_NET_QUOTA_POLICY_COOKIE_STORE_H_
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "net/cookies/cookie_monster.h"
#include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
class Task;
namespace base {
class FilePath;
class SequencedTaskRunner;
} // namespace base
namespace net {
class CanonicalCookie;
class CookieCryptoDelegate;
} // namespace net
namespace storage {
class SpecialStoragePolicy;
} // namespace storage
namespace content {
// Implements a PersistentCookieStore that deletes session cookies on
// shutdown. For documentation about the actual member functions consult the
// parent class |net::CookieMonster::PersistentCookieStore|. If provided, a
// |SpecialStoragePolicy| is consulted when the SQLite database is closed to
// decide which cookies to keep.
class CONTENT_EXPORT QuotaPolicyCookieStore
: public net::CookieMonster::PersistentCookieStore {
public:
// Wraps the passed-in |cookie_store|.
QuotaPolicyCookieStore(
const scoped_refptr<net::SQLitePersistentCookieStore>& cookie_store,
storage::SpecialStoragePolicy* special_storage_policy);
// net::CookieMonster::PersistentCookieStore:
void Load(const LoadedCallback& loaded_callback) override;
void LoadCookiesForKey(const std::string& key,
const LoadedCallback& callback) override;
void AddCookie(const net::CanonicalCookie& cc) override;
void UpdateCookieAccessTime(const net::CanonicalCookie& cc) override;
void DeleteCookie(const net::CanonicalCookie& cc) override;
void SetForceKeepSessionState() override;
void Flush(const base::Closure& callback) override;
private:
typedef std::map<net::SQLitePersistentCookieStore::CookieOrigin, size_t>
CookiesPerOriginMap;
~QuotaPolicyCookieStore() override;
// Called after cookies are loaded from the database. Calls |loaded_callback|
// when done.
void OnLoad(const LoadedCallback& loaded_callback,
const std::vector<net::CanonicalCookie*>& cookies);
// Map of (domain keys(eTLD+1), is secure cookie) to number of cookies in the
// database.
CookiesPerOriginMap cookies_per_origin_;
scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_;
scoped_refptr<net::SQLitePersistentCookieStore> persistent_store_;
DISALLOW_COPY_AND_ASSIGN(QuotaPolicyCookieStore);
};
} // namespace content
#endif // CONTENT_BROWSER_NET_QUOTA_POLICY_COOKIE_STORE_H_
This diff is collapsed.
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
'../device/vibration/vibration.gyp:device_vibration_mojo_bindings', '../device/vibration/vibration.gyp:device_vibration_mojo_bindings',
'../google_apis/google_apis.gyp:google_apis', '../google_apis/google_apis.gyp:google_apis',
'../net/net.gyp:net', '../net/net.gyp:net',
'../net/net.gyp:net_extras',
'../skia/skia.gyp:skia', '../skia/skia.gyp:skia',
'../sql/sql.gyp:sql', '../sql/sql.gyp:sql',
'../third_party/re2/re2.gyp:re2', '../third_party/re2/re2.gyp:re2',
...@@ -1028,8 +1029,8 @@ ...@@ -1028,8 +1029,8 @@
'browser/navigator_connect/navigator_connect_service_worker_service_factory.h', 'browser/navigator_connect/navigator_connect_service_worker_service_factory.h',
'browser/net/browser_online_state_observer.cc', 'browser/net/browser_online_state_observer.cc',
'browser/net/browser_online_state_observer.h', 'browser/net/browser_online_state_observer.h',
'browser/net/sqlite_persistent_cookie_store.cc', 'browser/net/quota_policy_cookie_store.cc',
'browser/net/sqlite_persistent_cookie_store.h', 'browser/net/quota_policy_cookie_store.h',
'browser/net/view_blob_internals_job_factory.cc', 'browser/net/view_blob_internals_job_factory.cc',
'browser/net/view_blob_internals_job_factory.h', 'browser/net/view_blob_internals_job_factory.h',
'browser/net/view_http_cache_job_factory.cc', 'browser/net/view_http_cache_job_factory.cc',
......
...@@ -480,7 +480,7 @@ ...@@ -480,7 +480,7 @@
'browser/media/media_internals_unittest.cc', 'browser/media/media_internals_unittest.cc',
'browser/media/midi_host_unittest.cc', 'browser/media/midi_host_unittest.cc',
'browser/media/webrtc_identity_store_unittest.cc', 'browser/media/webrtc_identity_store_unittest.cc',
'browser/net/sqlite_persistent_cookie_store_unittest.cc', 'browser/net/quota_policy_cookie_store_unittest.cc',
'browser/notification_service_impl_unittest.cc', 'browser/notification_service_impl_unittest.cc',
'browser/notifications/notification_database_data_unittest.cc', 'browser/notifications/notification_database_data_unittest.cc',
'browser/notifications/notification_database_unittest.cc', 'browser/notifications/notification_database_unittest.cc',
...@@ -979,6 +979,7 @@ ...@@ -979,6 +979,7 @@
'../device/battery/battery.gyp:device_battery', '../device/battery/battery.gyp:device_battery',
'../device/battery/battery.gyp:device_battery_mojo_bindings', '../device/battery/battery.gyp:device_battery_mojo_bindings',
'../mojo/mojo_base.gyp:mojo_environment_chromium', '../mojo/mojo_base.gyp:mojo_environment_chromium',
'../net/net.gyp:net_extras',
'../net/net.gyp:net_test_support', '../net/net.gyp:net_test_support',
'../skia/skia.gyp:skia', '../skia/skia.gyp:skia',
'../sql/sql.gyp:sql', '../sql/sql.gyp:sql',
...@@ -1253,7 +1254,6 @@ ...@@ -1253,7 +1254,6 @@
'..', '..',
], ],
'sources': [ 'sources': [
'browser/net/sqlite_persistent_cookie_store_perftest.cc',
'browser/renderer_host/input/input_router_impl_perftest.cc', 'browser/renderer_host/input/input_router_impl_perftest.cc',
'common/cc_messages_perftest.cc', 'common/cc_messages_perftest.cc',
'common/discardable_shared_memory_heap_perftest.cc', 'common/discardable_shared_memory_heap_perftest.cc',
......
...@@ -439,6 +439,7 @@ test("content_unittests") { ...@@ -439,6 +439,7 @@ test("content_unittests") {
"//device/battery", "//device/battery",
"//device/battery:mojo_bindings", "//device/battery:mojo_bindings",
"//mojo/environment:chromium", "//mojo/environment:chromium",
"//net:extras",
"//net:test_support", "//net:test_support",
"//skia", "//skia",
"//sql", "//sql",
...@@ -622,7 +623,6 @@ test("content_unittests") { ...@@ -622,7 +623,6 @@ test("content_unittests") {
if (!is_mac) { # TODO(GYP) enable on Mac once it links. if (!is_mac) { # TODO(GYP) enable on Mac once it links.
test("content_perftests") { test("content_perftests") {
sources = [ sources = [
"../browser/net/sqlite_persistent_cookie_store_perftest.cc",
"../browser/renderer_host/input/input_router_impl_perftest.cc", "../browser/renderer_host/input/input_router_impl_perftest.cc",
"../common/cc_messages_perftest.cc", "../common/cc_messages_perftest.cc",
"../test/run_all_perftests.cc", "../test/run_all_perftests.cc",
......
...@@ -1591,6 +1591,7 @@ executable("net_perftests") { ...@@ -1591,6 +1591,7 @@ executable("net_perftests") {
sources = [ sources = [
"cookies/cookie_monster_perftest.cc", "cookies/cookie_monster_perftest.cc",
"disk_cache/blockfile/disk_cache_perftest.cc", "disk_cache/blockfile/disk_cache_perftest.cc",
"extras/sqlite/sqlite_persistent_cookie_store_perftest.cc",
"proxy/proxy_resolver_perftest.cc", "proxy/proxy_resolver_perftest.cc",
"udp/udp_socket_perftest.cc", "udp/udp_socket_perftest.cc",
] ]
...@@ -1603,6 +1604,7 @@ executable("net_perftests") { ...@@ -1603,6 +1604,7 @@ executable("net_perftests") {
"//base/test:test_support_perf", "//base/test:test_support_perf",
"//testing/gtest", "//testing/gtest",
"//url", "//url",
":extras",
":net", ":net",
":test_support", ":test_support",
] ]
......
...@@ -2,18 +2,16 @@ ...@@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// A sqlite implementation of a cookie monster persistent store. #ifndef NET_EXTRAS_SQLITE_SQLITE_PERSISTENT_COOKIE_STORE_H_
#define NET_EXTRAS_SQLITE_SQLITE_PERSISTENT_COOKIE_STORE_H_
#ifndef CONTENT_BROWSER_NET_SQLITE_PERSISTENT_COOKIE_STORE_H_
#define CONTENT_BROWSER_NET_SQLITE_PERSISTENT_COOKIE_STORE_H_
#include <list>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "net/cookies/cookie_monster.h" #include "net/cookies/cookie_monster.h"
class Task; class Task;
...@@ -21,27 +19,22 @@ class Task; ...@@ -21,27 +19,22 @@ class Task;
namespace base { namespace base {
class FilePath; class FilePath;
class SequencedTaskRunner; class SequencedTaskRunner;
} } // namespace base
namespace net { namespace net {
class CanonicalCookie; class CanonicalCookie;
class CookieCryptoDelegate; class CookieCryptoDelegate;
}
namespace storage {
class SpecialStoragePolicy;
}
namespace content {
// Implements the PersistentCookieStore interface in terms of a SQLite database. // Implements the PersistentCookieStore interface in terms of a SQLite database.
// For documentation about the actual member functions consult the documentation // For documentation about the actual member functions consult the documentation
// of the parent class |net::CookieMonster::PersistentCookieStore|. // of the parent class |CookieMonster::PersistentCookieStore|.
// If provided, a |SpecialStoragePolicy| is consulted when the SQLite database class SQLitePersistentCookieStore
// is closed to decide which cookies to keep. : public CookieMonster::PersistentCookieStore {
class CONTENT_EXPORT SQLitePersistentCookieStore
: public net::CookieMonster::PersistentCookieStore {
public: public:
// Contains the origin and a bool indicating whether or not the
// origin is secure.
typedef std::pair<std::string, bool> CookieOrigin;
// All blocking database accesses will be performed on // All blocking database accesses will be performed on
// |background_task_runner|, while |client_task_runner| is used to invoke // |background_task_runner|, while |client_task_runner| is used to invoke
// callbacks. // callbacks.
...@@ -50,23 +43,24 @@ class CONTENT_EXPORT SQLitePersistentCookieStore ...@@ -50,23 +43,24 @@ class CONTENT_EXPORT SQLitePersistentCookieStore
const scoped_refptr<base::SequencedTaskRunner>& client_task_runner, const scoped_refptr<base::SequencedTaskRunner>& client_task_runner,
const scoped_refptr<base::SequencedTaskRunner>& background_task_runner, const scoped_refptr<base::SequencedTaskRunner>& background_task_runner,
bool restore_old_session_cookies, bool restore_old_session_cookies,
storage::SpecialStoragePolicy* special_storage_policy, CookieCryptoDelegate* crypto_delegate);
net::CookieCryptoDelegate* crypto_delegate);
// net::CookieMonster::PersistentCookieStore: // Deletes the cookies whose origins match those given in |cookies|.
void DeleteAllInList(const std::list<CookieOrigin>& cookies);
// CookieMonster::PersistentCookieStore:
void Load(const LoadedCallback& loaded_callback) override; void Load(const LoadedCallback& loaded_callback) override;
void LoadCookiesForKey(const std::string& key, void LoadCookiesForKey(const std::string& key,
const LoadedCallback& callback) override; const LoadedCallback& callback) override;
void AddCookie(const net::CanonicalCookie& cc) override; void AddCookie(const CanonicalCookie& cc) override;
void UpdateCookieAccessTime(const net::CanonicalCookie& cc) override; void UpdateCookieAccessTime(const CanonicalCookie& cc) override;
void DeleteCookie(const net::CanonicalCookie& cc) override; void DeleteCookie(const CanonicalCookie& cc) override;
void SetForceKeepSessionState() override; void SetForceKeepSessionState() override;
void Flush(const base::Closure& callback) override; void Flush(const base::Closure& callback) override;
protected: private:
~SQLitePersistentCookieStore() override; ~SQLitePersistentCookieStore() override;
private:
class Backend; class Backend;
scoped_refptr<Backend> backend_; scoped_refptr<Backend> backend_;
...@@ -74,6 +68,6 @@ class CONTENT_EXPORT SQLitePersistentCookieStore ...@@ -74,6 +68,6 @@ class CONTENT_EXPORT SQLitePersistentCookieStore
DISALLOW_COPY_AND_ASSIGN(SQLitePersistentCookieStore); DISALLOW_COPY_AND_ASSIGN(SQLitePersistentCookieStore);
}; };
} // namespace content } // namespace net
#endif // CONTENT_BROWSER_NET_SQLITE_PERSISTENT_COOKIE_STORE_H_ #endif // NET_EXTRAS_SQLITE_SQLITE_PERSISTENT_COOKIE_STORE_H_
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "content/browser/net/sqlite_persistent_cookie_store.h" #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
#include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/message_loop/message_loop.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
...@@ -19,7 +22,7 @@ ...@@ -19,7 +22,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace content { namespace net {
namespace { namespace {
...@@ -32,22 +35,21 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test { ...@@ -32,22 +35,21 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test {
SQLitePersistentCookieStorePerfTest() SQLitePersistentCookieStorePerfTest()
: pool_owner_(new base::SequencedWorkerPoolOwner(1, "Background Pool")), : pool_owner_(new base::SequencedWorkerPoolOwner(1, "Background Pool")),
loaded_event_(false, false), loaded_event_(false, false),
key_loaded_event_(false, false) { key_loaded_event_(false, false) {}
}
void OnLoaded(const std::vector<net::CanonicalCookie*>& cookies) { void OnLoaded(const std::vector<CanonicalCookie*>& cookies) {
cookies_ = cookies; cookies_ = cookies;
loaded_event_.Signal(); loaded_event_.Signal();
} }
void OnKeyLoaded(const std::vector<net::CanonicalCookie*>& cookies) { void OnKeyLoaded(const std::vector<CanonicalCookie*>& cookies) {
cookies_ = cookies; cookies_ = cookies;
key_loaded_event_.Signal(); key_loaded_event_.Signal();
} }
void Load() { void Load() {
store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded, store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded,
base::Unretained(this))); base::Unretained(this)));
loaded_event_.Wait(); loaded_event_.Wait();
} }
...@@ -64,11 +66,9 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test { ...@@ -64,11 +66,9 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test {
void SetUp() override { void SetUp() override {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
store_ = new SQLitePersistentCookieStore( store_ = new SQLitePersistentCookieStore(
temp_dir_.path().Append(cookie_filename), temp_dir_.path().Append(cookie_filename), client_task_runner(),
client_task_runner(), background_task_runner(), false, NULL);
background_task_runner(), std::vector<CanonicalCookie*> cookies;
false, NULL, NULL);
std::vector<net::CanonicalCookie*> cookies;
Load(); Load();
ASSERT_EQ(0u, cookies_.size()); ASSERT_EQ(0u, cookies_.size());
// Creates 15000 cookies from 300 eTLD+1s. // Creates 15000 cookies from 300 eTLD+1s.
...@@ -78,9 +78,9 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test { ...@@ -78,9 +78,9 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test {
GURL gurl("www" + domain_name); GURL gurl("www" + domain_name);
for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { for (int cookie_num = 0; cookie_num < 50; ++cookie_num) {
t += base::TimeDelta::FromInternalValue(10); t += base::TimeDelta::FromInternalValue(10);
store_->AddCookie(net::CanonicalCookie( store_->AddCookie(CanonicalCookie(
gurl, base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name, gurl, base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name,
"/", t, t, t, false, false, false, net::COOKIE_PRIORITY_DEFAULT)); "/", t, t, t, false, false, false, COOKIE_PRIORITY_DEFAULT));
} }
} }
// Replace the store effectively destroying the current one and forcing it // Replace the store effectively destroying the current one and forcing it
...@@ -93,10 +93,8 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test { ...@@ -93,10 +93,8 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test {
pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool"));
store_ = new SQLitePersistentCookieStore( store_ = new SQLitePersistentCookieStore(
temp_dir_.path().Append(cookie_filename), temp_dir_.path().Append(cookie_filename), client_task_runner(),
client_task_runner(), background_task_runner(), false, NULL);
background_task_runner(),
false, NULL, NULL);
} }
void TearDown() override { void TearDown() override {
...@@ -105,10 +103,11 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test { ...@@ -105,10 +103,11 @@ class SQLitePersistentCookieStorePerfTest : public testing::Test {
} }
protected: protected:
base::MessageLoop main_loop_;
scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_;
base::WaitableEvent loaded_event_; base::WaitableEvent loaded_event_;
base::WaitableEvent key_loaded_event_; base::WaitableEvent key_loaded_event_;
std::vector<net::CanonicalCookie*> cookies_; std::vector<CanonicalCookie*> cookies_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
scoped_refptr<SQLitePersistentCookieStore> store_; scoped_refptr<SQLitePersistentCookieStore> store_;
}; };
...@@ -118,10 +117,11 @@ TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { ...@@ -118,10 +117,11 @@ TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) {
for (int domain_num = 0; domain_num < 3; ++domain_num) { for (int domain_num = 0; domain_num < 3; ++domain_num) {
std::string domain_name(base::StringPrintf("domain_%d.com", domain_num)); std::string domain_name(base::StringPrintf("domain_%d.com", domain_num));
base::PerfTimeLogger timer( base::PerfTimeLogger timer(
("Load cookies for the eTLD+1 " + domain_name).c_str()); ("Load cookies for the eTLD+1 " + domain_name).c_str());
store_->LoadCookiesForKey(domain_name, store_->LoadCookiesForKey(
base::Bind(&SQLitePersistentCookieStorePerfTest::OnKeyLoaded, domain_name,
base::Unretained(this))); base::Bind(&SQLitePersistentCookieStorePerfTest::OnKeyLoaded,
base::Unretained(this)));
key_loaded_event_.Wait(); key_loaded_event_.Wait();
timer.Done(); timer.Done();
...@@ -138,4 +138,4 @@ TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { ...@@ -138,4 +138,4 @@ TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) {
ASSERT_EQ(15000U, cookies_.size()); ASSERT_EQ(15000U, cookies_.size());
} }
} // namespace content } // namespace net
...@@ -451,11 +451,13 @@ ...@@ -451,11 +451,13 @@
'../testing/gtest.gyp:gtest', '../testing/gtest.gyp:gtest',
'../url/url.gyp:url_lib', '../url/url.gyp:url_lib',
'net', 'net',
'net_extras',
'net_test_support', 'net_test_support',
], ],
'sources': [ 'sources': [
'cookies/cookie_monster_perftest.cc', 'cookies/cookie_monster_perftest.cc',
'disk_cache/blockfile/disk_cache_perftest.cc', 'disk_cache/blockfile/disk_cache_perftest.cc',
'extras/sqlite/sqlite_persistent_cookie_store_perftest.cc',
'proxy/proxy_resolver_perftest.cc', 'proxy/proxy_resolver_perftest.cc',
'udp/udp_socket_perftest.cc', 'udp/udp_socket_perftest.cc',
'websockets/websocket_frame_perftest.cc', 'websockets/websocket_frame_perftest.cc',
......
...@@ -1273,6 +1273,8 @@ ...@@ -1273,6 +1273,8 @@
'extras/sqlite/cookie_crypto_delegate.h', 'extras/sqlite/cookie_crypto_delegate.h',
'extras/sqlite/sqlite_channel_id_store.cc', 'extras/sqlite/sqlite_channel_id_store.cc',
'extras/sqlite/sqlite_channel_id_store.h', 'extras/sqlite/sqlite_channel_id_store.h',
'extras/sqlite/sqlite_persistent_cookie_store.cc',
'extras/sqlite/sqlite_persistent_cookie_store.h',
], ],
'net_test_sources': [ 'net_test_sources': [
'android/keystore_unittest.cc', 'android/keystore_unittest.cc',
...@@ -1389,6 +1391,7 @@ ...@@ -1389,6 +1391,7 @@
'dns/serial_worker_unittest.cc', 'dns/serial_worker_unittest.cc',
'dns/single_request_host_resolver_unittest.cc', 'dns/single_request_host_resolver_unittest.cc',
'extras/sqlite/sqlite_channel_id_store_unittest.cc', 'extras/sqlite/sqlite_channel_id_store_unittest.cc',
'extras/sqlite/sqlite_persistent_cookie_store_unittest.cc',
'filter/filter_unittest.cc', 'filter/filter_unittest.cc',
'filter/gzip_filter_unittest.cc', 'filter/gzip_filter_unittest.cc',
'filter/mock_filter_context.cc', 'filter/mock_filter_context.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment