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

Side by Side Diff: net/extras/sqlite/sqlite_persistent_cookie_store_perftest.cc

Issue 1016643004: Moves SQLitePersistentCookieStore to net/extras/sqlite. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cookies
Patch Set: Remove NET_EXPORT. Created 5 years, 9 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
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 #include "content/browser/net/sqlite_persistent_cookie_store.h" 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h"
Ryan Sleevi 2015/03/19 03:37:51 Use a TaskRunner instead
rohitrao (ping after 24h) 2015/03/19 14:55:42 All of the code is using TaskRunners, but it seeme
10 #include "base/sequenced_task_runner.h" 11 #include "base/sequenced_task_runner.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
12 #include "base/synchronization/waitable_event.h" 13 #include "base/synchronization/waitable_event.h"
13 #include "base/test/perf_time_logger.h" 14 #include "base/test/perf_time_logger.h"
14 #include "base/test/sequenced_worker_pool_owner.h" 15 #include "base/test/sequenced_worker_pool_owner.h"
15 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
16 #include "net/cookies/canonical_cookie.h" 17 #include "net/cookies/canonical_cookie.h"
17 #include "net/cookies/cookie_constants.h" 18 #include "net/cookies/cookie_constants.h"
18 #include "net/extras/sqlite/cookie_crypto_delegate.h" 19 #include "net/extras/sqlite/cookie_crypto_delegate.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/gurl.h" 21 #include "url/gurl.h"
21 22
22 namespace content { 23 namespace net {
23 24
24 namespace { 25 namespace {
25 26
26 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies"); 27 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies");
27 28
28 } // namespace 29 } // namespace
29 30
30 class SQLitePersistentCookieStorePerfTest : public testing::Test { 31 class SQLitePersistentCookieStorePerfTest : public testing::Test {
31 public: 32 public:
32 SQLitePersistentCookieStorePerfTest() 33 SQLitePersistentCookieStorePerfTest()
(...skipping 27 matching lines...) Expand all
60 return pool_owner_->pool()->GetSequencedTaskRunner( 61 return pool_owner_->pool()->GetSequencedTaskRunner(
61 pool_owner_->pool()->GetNamedSequenceToken("client")); 62 pool_owner_->pool()->GetNamedSequenceToken("client"));
62 } 63 }
63 64
64 void SetUp() override { 65 void SetUp() override {
65 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 66 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
66 store_ = new SQLitePersistentCookieStore( 67 store_ = new SQLitePersistentCookieStore(
67 temp_dir_.path().Append(cookie_filename), 68 temp_dir_.path().Append(cookie_filename),
68 client_task_runner(), 69 client_task_runner(),
69 background_task_runner(), 70 background_task_runner(),
70 false, NULL, NULL); 71 false, NULL);
71 std::vector<net::CanonicalCookie*> cookies; 72 std::vector<net::CanonicalCookie*> cookies;
72 Load(); 73 Load();
73 ASSERT_EQ(0u, cookies_.size()); 74 ASSERT_EQ(0u, cookies_.size());
74 // Creates 15000 cookies from 300 eTLD+1s. 75 // Creates 15000 cookies from 300 eTLD+1s.
75 base::Time t = base::Time::Now(); 76 base::Time t = base::Time::Now();
76 for (int domain_num = 0; domain_num < 300; domain_num++) { 77 for (int domain_num = 0; domain_num < 300; domain_num++) {
77 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); 78 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num));
78 GURL gurl("www" + domain_name); 79 GURL gurl("www" + domain_name);
79 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { 80 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) {
80 t += base::TimeDelta::FromInternalValue(10); 81 t += base::TimeDelta::FromInternalValue(10);
81 store_->AddCookie(net::CanonicalCookie( 82 store_->AddCookie(net::CanonicalCookie(
82 gurl, base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name, 83 gurl, base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name,
83 "/", t, t, t, false, false, false, net::COOKIE_PRIORITY_DEFAULT)); 84 "/", t, t, t, false, false, false, net::COOKIE_PRIORITY_DEFAULT));
84 } 85 }
85 } 86 }
86 // Replace the store effectively destroying the current one and forcing it 87 // Replace the store effectively destroying the current one and forcing it
87 // to write its data to disk. 88 // to write its data to disk.
88 store_ = NULL; 89 store_ = NULL;
89 90
90 // Shut down the pool, causing deferred (no-op) commits to be discarded. 91 // Shut down the pool, causing deferred (no-op) commits to be discarded.
91 pool_owner_->pool()->Shutdown(); 92 pool_owner_->pool()->Shutdown();
92 // ~SequencedWorkerPoolOwner blocks on pool shutdown. 93 // ~SequencedWorkerPoolOwner blocks on pool shutdown.
93 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); 94 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool"));
94 95
95 store_ = new SQLitePersistentCookieStore( 96 store_ = new SQLitePersistentCookieStore(
96 temp_dir_.path().Append(cookie_filename), 97 temp_dir_.path().Append(cookie_filename),
97 client_task_runner(), 98 client_task_runner(),
98 background_task_runner(), 99 background_task_runner(),
99 false, NULL, NULL); 100 false, NULL);
100 } 101 }
101 102
102 void TearDown() override { 103 void TearDown() override {
103 store_ = NULL; 104 store_ = NULL;
104 pool_owner_->pool()->Shutdown(); 105 pool_owner_->pool()->Shutdown();
105 } 106 }
106 107
107 protected: 108 protected:
109 base::MessageLoop main_loop_;
108 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; 110 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_;
109 base::WaitableEvent loaded_event_; 111 base::WaitableEvent loaded_event_;
110 base::WaitableEvent key_loaded_event_; 112 base::WaitableEvent key_loaded_event_;
111 std::vector<net::CanonicalCookie*> cookies_; 113 std::vector<net::CanonicalCookie*> cookies_;
112 base::ScopedTempDir temp_dir_; 114 base::ScopedTempDir temp_dir_;
113 scoped_refptr<SQLitePersistentCookieStore> store_; 115 scoped_refptr<SQLitePersistentCookieStore> store_;
114 }; 116 };
115 117
116 // Test the performance of priority load of cookies for a specfic domain key 118 // Test the performance of priority load of cookies for a specfic domain key
117 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { 119 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) {
(...skipping 13 matching lines...) Expand all
131 133
132 // Test the performance of load 134 // Test the performance of load
133 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { 135 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) {
134 base::PerfTimeLogger timer("Load all cookies"); 136 base::PerfTimeLogger timer("Load all cookies");
135 Load(); 137 Load();
136 timer.Done(); 138 timer.Done();
137 139
138 ASSERT_EQ(15000U, cookies_.size()); 140 ASSERT_EQ(15000U, cookies_.size());
139 } 141 }
140 142
141 } // namespace content 143 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698