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

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

Issue 2887953002: Remove usage of SequencedWorkerPool::GetNamedSequenceToken from net/extras/sqlite/. (Closed)
Patch Set: CR-remove-comment Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/extras/sqlite/sqlite_persistent_cookie_store.h" 5 #include "net/extras/sqlite/sqlite_persistent_cookie_store.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/sequenced_task_runner.h" 12 #include "base/sequenced_task_runner.h"
14 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
15 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/task_scheduler/post_task.h"
16 #include "base/test/perf_time_logger.h" 16 #include "base/test/perf_time_logger.h"
17 #include "base/test/sequenced_worker_pool_owner.h" 17 #include "base/test/scoped_task_environment.h"
18 #include "base/threading/sequenced_worker_pool.h"
19 #include "net/cookies/canonical_cookie.h" 18 #include "net/cookies/canonical_cookie.h"
20 #include "net/cookies/cookie_constants.h" 19 #include "net/cookies/cookie_constants.h"
21 #include "net/extras/sqlite/cookie_crypto_delegate.h" 20 #include "net/extras/sqlite/cookie_crypto_delegate.h"
22 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
23 #include "url/gurl.h" 22 #include "url/gurl.h"
24 23
25 namespace net { 24 namespace net {
26 25
27 namespace { 26 namespace {
28 27
29 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies"); 28 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies");
30 29
31 } // namespace 30 } // namespace
32 31
33 class SQLitePersistentCookieStorePerfTest : public testing::Test { 32 class SQLitePersistentCookieStorePerfTest : public testing::Test {
34 public: 33 public:
35 SQLitePersistentCookieStorePerfTest() 34 SQLitePersistentCookieStorePerfTest()
36 : pool_owner_(new base::SequencedWorkerPoolOwner(2, "SetupPool")), 35 : loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
37 loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
38 base::WaitableEvent::InitialState::NOT_SIGNALED), 36 base::WaitableEvent::InitialState::NOT_SIGNALED),
39 key_loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 37 key_loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
40 base::WaitableEvent::InitialState::NOT_SIGNALED) {} 38 base::WaitableEvent::InitialState::NOT_SIGNALED) {}
41 39
42 void OnLoaded(std::vector<std::unique_ptr<CanonicalCookie>> cookies) { 40 void OnLoaded(std::vector<std::unique_ptr<CanonicalCookie>> cookies) {
43 cookies_.swap(cookies); 41 cookies_.swap(cookies);
44 loaded_event_.Signal(); 42 loaded_event_.Signal();
45 } 43 }
46 44
47 void OnKeyLoaded(std::vector<std::unique_ptr<CanonicalCookie>> cookies) { 45 void OnKeyLoaded(std::vector<std::unique_ptr<CanonicalCookie>> cookies) {
48 cookies_.swap(cookies); 46 cookies_.swap(cookies);
49 key_loaded_event_.Signal(); 47 key_loaded_event_.Signal();
50 } 48 }
51 49
52 void Load() { 50 void Load() {
53 store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded, 51 store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded,
54 base::Unretained(this))); 52 base::Unretained(this)));
55 loaded_event_.Wait(); 53 loaded_event_.Wait();
56 } 54 }
57 55
58 scoped_refptr<base::SequencedTaskRunner> background_task_runner() {
59 return pool_owner_->pool()->GetSequencedTaskRunner(
60 pool_owner_->pool()->GetNamedSequenceToken("background"));
61 }
62
63 scoped_refptr<base::SequencedTaskRunner> client_task_runner() {
64 return pool_owner_->pool()->GetSequencedTaskRunner(
65 pool_owner_->pool()->GetNamedSequenceToken("client"));
66 }
67
68 void SetUp() override { 56 void SetUp() override {
69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 57 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
70 store_ = new SQLitePersistentCookieStore( 58 store_ = new SQLitePersistentCookieStore(
71 temp_dir_.GetPath().Append(cookie_filename), client_task_runner(), 59 temp_dir_.GetPath().Append(cookie_filename), client_task_runner_,
72 background_task_runner(), false, NULL); 60 background_task_runner_, false, NULL);
73 std::vector<CanonicalCookie*> cookies; 61 std::vector<CanonicalCookie*> cookies;
74 Load(); 62 Load();
75 ASSERT_EQ(0u, cookies_.size()); 63 ASSERT_EQ(0u, cookies_.size());
76 // Creates 15000 cookies from 300 eTLD+1s. 64 // Creates 15000 cookies from 300 eTLD+1s.
77 base::Time t = base::Time::Now(); 65 base::Time t = base::Time::Now();
78 for (int domain_num = 0; domain_num < 300; domain_num++) { 66 for (int domain_num = 0; domain_num < 300; domain_num++) {
79 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); 67 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num));
80 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { 68 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) {
81 t += base::TimeDelta::FromInternalValue(10); 69 t += base::TimeDelta::FromInternalValue(10);
82 store_->AddCookie(CanonicalCookie( 70 store_->AddCookie(CanonicalCookie(
83 base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name, "/", 71 base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name, "/",
84 t, t, t, false, false, CookieSameSite::DEFAULT_MODE, 72 t, t, t, false, false, CookieSameSite::DEFAULT_MODE,
85 COOKIE_PRIORITY_DEFAULT)); 73 COOKIE_PRIORITY_DEFAULT));
86 } 74 }
87 } 75 }
88 // Replace the store effectively destroying the current one and forcing it 76 // Replace the store effectively destroying the current one and forcing it
89 // to write its data to disk. 77 // to write its data to disk.
90 store_ = NULL; 78 store_ = NULL;
91 79
92 // Shut down the pool, causing deferred (no-op) commits to be discarded. 80 // Flush TaskScheduler tasks, causing pending commits to run.
93 pool_owner_->pool()->Shutdown(); 81 scoped_task_environment_.RunUntilIdle();
94 // ~SequencedWorkerPoolOwner blocks on pool shutdown.
95 pool_owner_.reset(new base::SequencedWorkerPoolOwner(2, "TestPool"));
96 82
97 store_ = new SQLitePersistentCookieStore( 83 store_ = new SQLitePersistentCookieStore(
98 temp_dir_.GetPath().Append(cookie_filename), client_task_runner(), 84 temp_dir_.GetPath().Append(cookie_filename), client_task_runner_,
99 background_task_runner(), false, NULL); 85 background_task_runner_, false, NULL);
100 } 86 }
101 87
102 void TearDown() override { 88 void TearDown() override {
103 store_ = NULL; 89 store_ = NULL;
104 } 90 }
105 91
106 protected: 92 protected:
107 base::MessageLoop main_loop_; 93 base::test::ScopedTaskEnvironment scoped_task_environment_;
108 std::unique_ptr<base::SequencedWorkerPoolOwner> pool_owner_; 94 const scoped_refptr<base::SequencedTaskRunner> background_task_runner_ =
95 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()});
96 const scoped_refptr<base::SequencedTaskRunner> client_task_runner_ =
97 base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()});
109 base::WaitableEvent loaded_event_; 98 base::WaitableEvent loaded_event_;
110 base::WaitableEvent key_loaded_event_; 99 base::WaitableEvent key_loaded_event_;
111 std::vector<std::unique_ptr<CanonicalCookie>> cookies_; 100 std::vector<std::unique_ptr<CanonicalCookie>> cookies_;
112 base::ScopedTempDir temp_dir_; 101 base::ScopedTempDir temp_dir_;
113 scoped_refptr<SQLitePersistentCookieStore> store_; 102 scoped_refptr<SQLitePersistentCookieStore> store_;
114 }; 103 };
115 104
116 // Test the performance of priority load of cookies for a specific domain key 105 // Test the performance of priority load of cookies for a specific domain key
117 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { 106 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) {
118 for (int domain_num = 0; domain_num < 3; ++domain_num) { 107 for (int domain_num = 0; domain_num < 3; ++domain_num) {
(...skipping 14 matching lines...) Expand all
133 // Test the performance of load 122 // Test the performance of load
134 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { 123 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) {
135 base::PerfTimeLogger timer("Load all cookies"); 124 base::PerfTimeLogger timer("Load all cookies");
136 Load(); 125 Load();
137 timer.Done(); 126 timer.Done();
138 127
139 ASSERT_EQ(15000U, cookies_.size()); 128 ASSERT_EQ(15000U, cookies_.size());
140 } 129 }
141 130
142 } // namespace net 131 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/extras/sqlite/sqlite_persistent_cookie_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698