Chromium Code Reviews| 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 "content/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "content/browser/net/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/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/test/perf_time_logger.h" | 13 #include "base/test/perf_time_logger.h" |
| 14 #include "base/test/sequenced_worker_pool_owner.h" | 14 #include "base/test/sequenced_worker_pool_owner.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "content/public/browser/cookie_crypto_delegate.h" | |
|
erikwright (departed)
2013/10/22 23:58:14
forward-decl
bcwhite
2013/10/23 19:36:23
Done.
| |
| 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 "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies"); | 26 const base::FilePath::CharType cookie_filename[] = FILE_PATH_LITERAL("Cookies"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 return pool_owner_->pool()->GetSequencedTaskRunner( | 60 return pool_owner_->pool()->GetSequencedTaskRunner( |
| 60 pool_owner_->pool()->GetNamedSequenceToken("client")); | 61 pool_owner_->pool()->GetNamedSequenceToken("client")); |
| 61 } | 62 } |
| 62 | 63 |
| 63 virtual void SetUp() OVERRIDE { | 64 virtual void SetUp() OVERRIDE { |
| 64 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 65 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 65 store_ = new SQLitePersistentCookieStore( | 66 store_ = new SQLitePersistentCookieStore( |
| 66 temp_dir_.path().Append(cookie_filename), | 67 temp_dir_.path().Append(cookie_filename), |
| 67 client_task_runner(), | 68 client_task_runner(), |
| 68 background_task_runner(), | 69 background_task_runner(), |
| 69 false, NULL); | 70 false, NULL, |
| 71 scoped_ptr<content::CookieCryptoDelegate>()); | |
| 70 std::vector<net::CanonicalCookie*> cookies; | 72 std::vector<net::CanonicalCookie*> cookies; |
| 71 Load(); | 73 Load(); |
| 72 ASSERT_EQ(0u, cookies_.size()); | 74 ASSERT_EQ(0u, cookies_.size()); |
| 73 // Creates 15000 cookies from 300 eTLD+1s. | 75 // Creates 15000 cookies from 300 eTLD+1s. |
| 74 base::Time t = base::Time::Now(); | 76 base::Time t = base::Time::Now(); |
| 75 for (int domain_num = 0; domain_num < 300; domain_num++) { | 77 for (int domain_num = 0; domain_num < 300; domain_num++) { |
| 76 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); | 78 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); |
| 77 GURL gurl("www" + domain_name); | 79 GURL gurl("www" + domain_name); |
| 78 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { | 80 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { |
| 79 t += base::TimeDelta::FromInternalValue(10); | 81 t += base::TimeDelta::FromInternalValue(10); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 90 | 92 |
| 91 // 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. |
| 92 pool_owner_->pool()->Shutdown(); | 94 pool_owner_->pool()->Shutdown(); |
| 93 // ~SequencedWorkerPoolOwner blocks on pool shutdown. | 95 // ~SequencedWorkerPoolOwner blocks on pool shutdown. |
| 94 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); | 96 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); |
| 95 | 97 |
| 96 store_ = new SQLitePersistentCookieStore( | 98 store_ = new SQLitePersistentCookieStore( |
| 97 temp_dir_.path().Append(cookie_filename), | 99 temp_dir_.path().Append(cookie_filename), |
| 98 client_task_runner(), | 100 client_task_runner(), |
| 99 background_task_runner(), | 101 background_task_runner(), |
| 100 false, NULL); | 102 false, NULL, |
| 103 scoped_ptr<content::CookieCryptoDelegate>()); | |
| 101 } | 104 } |
| 102 | 105 |
| 103 virtual void TearDown() OVERRIDE { | 106 virtual void TearDown() OVERRIDE { |
| 104 store_ = NULL; | 107 store_ = NULL; |
| 105 pool_owner_->pool()->Shutdown(); | 108 pool_owner_->pool()->Shutdown(); |
| 106 } | 109 } |
| 107 | 110 |
| 108 protected: | 111 protected: |
| 109 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 112 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
| 110 base::WaitableEvent loaded_event_; | 113 base::WaitableEvent loaded_event_; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 133 // Test the performance of load | 136 // Test the performance of load |
| 134 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { | 137 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { |
| 135 base::PerfTimeLogger timer("Load all cookies"); | 138 base::PerfTimeLogger timer("Load all cookies"); |
| 136 Load(); | 139 Load(); |
| 137 timer.Done(); | 140 timer.Done(); |
| 138 | 141 |
| 139 ASSERT_EQ(15000U, cookies_.size()); | 142 ASSERT_EQ(15000U, cookies_.size()); |
| 140 } | 143 } |
| 141 | 144 |
| 142 } // namespace content | 145 } // namespace content |
| OLD | NEW |