OLD | NEW |
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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 } | 61 } |
62 | 62 |
63 scoped_refptr<base::SequencedTaskRunner> client_task_runner() { | 63 scoped_refptr<base::SequencedTaskRunner> client_task_runner() { |
64 return pool_owner_->pool()->GetSequencedTaskRunner( | 64 return pool_owner_->pool()->GetSequencedTaskRunner( |
65 pool_owner_->pool()->GetNamedSequenceToken("client")); | 65 pool_owner_->pool()->GetNamedSequenceToken("client")); |
66 } | 66 } |
67 | 67 |
68 void SetUp() override { | 68 void SetUp() override { |
69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
70 store_ = new SQLitePersistentCookieStore( | 70 store_ = new SQLitePersistentCookieStore( |
71 temp_dir_.path().Append(cookie_filename), client_task_runner(), | 71 temp_dir_.GetPath().Append(cookie_filename), client_task_runner(), |
72 background_task_runner(), false, NULL); | 72 background_task_runner(), false, NULL); |
73 std::vector<CanonicalCookie*> cookies; | 73 std::vector<CanonicalCookie*> cookies; |
74 Load(); | 74 Load(); |
75 ASSERT_EQ(0u, cookies_.size()); | 75 ASSERT_EQ(0u, cookies_.size()); |
76 // Creates 15000 cookies from 300 eTLD+1s. | 76 // Creates 15000 cookies from 300 eTLD+1s. |
77 base::Time t = base::Time::Now(); | 77 base::Time t = base::Time::Now(); |
78 for (int domain_num = 0; domain_num < 300; domain_num++) { | 78 for (int domain_num = 0; domain_num < 300; domain_num++) { |
79 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); | 79 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); |
80 GURL gurl("http://www" + domain_name); | 80 GURL gurl("http://www" + domain_name); |
81 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { | 81 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { |
82 t += base::TimeDelta::FromInternalValue(10); | 82 t += base::TimeDelta::FromInternalValue(10); |
83 store_->AddCookie(*CanonicalCookie::Create( | 83 store_->AddCookie(*CanonicalCookie::Create( |
84 gurl, base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name, | 84 gurl, base::StringPrintf("Cookie_%d", cookie_num), "1", domain_name, |
85 "/", t, t, false, false, CookieSameSite::DEFAULT_MODE, false, | 85 "/", t, t, false, false, CookieSameSite::DEFAULT_MODE, false, |
86 COOKIE_PRIORITY_DEFAULT)); | 86 COOKIE_PRIORITY_DEFAULT)); |
87 } | 87 } |
88 } | 88 } |
89 // Replace the store effectively destroying the current one and forcing it | 89 // Replace the store effectively destroying the current one and forcing it |
90 // to write its data to disk. | 90 // to write its data to disk. |
91 store_ = NULL; | 91 store_ = NULL; |
92 | 92 |
93 // Shut down the pool, causing deferred (no-op) commits to be discarded. | 93 // Shut down the pool, causing deferred (no-op) commits to be discarded. |
94 pool_owner_->pool()->Shutdown(); | 94 pool_owner_->pool()->Shutdown(); |
95 // ~SequencedWorkerPoolOwner blocks on pool shutdown. | 95 // ~SequencedWorkerPoolOwner blocks on pool shutdown. |
96 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); | 96 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); |
97 | 97 |
98 store_ = new SQLitePersistentCookieStore( | 98 store_ = new SQLitePersistentCookieStore( |
99 temp_dir_.path().Append(cookie_filename), client_task_runner(), | 99 temp_dir_.GetPath().Append(cookie_filename), client_task_runner(), |
100 background_task_runner(), false, NULL); | 100 background_task_runner(), false, NULL); |
101 } | 101 } |
102 | 102 |
103 void TearDown() override { | 103 void TearDown() override { |
104 store_ = NULL; | 104 store_ = NULL; |
105 } | 105 } |
106 | 106 |
107 protected: | 107 protected: |
108 base::MessageLoop main_loop_; | 108 base::MessageLoop main_loop_; |
109 std::unique_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 109 std::unique_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
(...skipping 24 matching lines...) Expand all Loading... |
134 // Test the performance of load | 134 // Test the performance of load |
135 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { | 135 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { |
136 base::PerfTimeLogger timer("Load all cookies"); | 136 base::PerfTimeLogger timer("Load all cookies"); |
137 Load(); | 137 Load(); |
138 timer.Done(); | 138 timer.Done(); |
139 | 139 |
140 ASSERT_EQ(15000U, cookies_.size()); | 140 ASSERT_EQ(15000U, cookies_.size()); |
141 } | 141 } |
142 | 142 |
143 } // namespace net | 143 } // namespace net |
OLD | NEW |