| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 class SQLitePersistentCookieStorePerfTest : public testing::Test { | 33 class SQLitePersistentCookieStorePerfTest : public testing::Test { |
| 34 public: | 34 public: |
| 35 SQLitePersistentCookieStorePerfTest() | 35 SQLitePersistentCookieStorePerfTest() |
| 36 : pool_owner_(new base::SequencedWorkerPoolOwner(2, "SetupPool")), | 36 : pool_owner_(new base::SequencedWorkerPoolOwner(2, "SetupPool")), |
| 37 loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 37 loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 38 base::WaitableEvent::InitialState::NOT_SIGNALED), | 38 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 39 key_loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 39 key_loaded_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 40 base::WaitableEvent::InitialState::NOT_SIGNALED) {} | 40 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
| 41 | 41 |
| 42 void OnLoaded(const std::vector<CanonicalCookie*>& cookies) { | 42 void OnLoaded(std::vector<std::unique_ptr<CanonicalCookie>> cookies) { |
| 43 cookies_ = cookies; | 43 cookies_.swap(cookies); |
| 44 loaded_event_.Signal(); | 44 loaded_event_.Signal(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void OnKeyLoaded(const std::vector<CanonicalCookie*>& cookies) { | 47 void OnKeyLoaded(std::vector<std::unique_ptr<CanonicalCookie>> cookies) { |
| 48 cookies_ = cookies; | 48 cookies_.swap(cookies); |
| 49 key_loaded_event_.Signal(); | 49 key_loaded_event_.Signal(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void Load() { | 52 void Load() { |
| 53 store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded, | 53 store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded, |
| 54 base::Unretained(this))); | 54 base::Unretained(this))); |
| 55 loaded_event_.Wait(); | 55 loaded_event_.Wait(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 scoped_refptr<base::SequencedTaskRunner> background_task_runner() { | 58 scoped_refptr<base::SequencedTaskRunner> background_task_runner() { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_; |
| 110 base::WaitableEvent loaded_event_; | 110 base::WaitableEvent loaded_event_; |
| 111 base::WaitableEvent key_loaded_event_; | 111 base::WaitableEvent key_loaded_event_; |
| 112 std::vector<CanonicalCookie*> cookies_; | 112 std::vector<std::unique_ptr<CanonicalCookie>> cookies_; |
| 113 base::ScopedTempDir temp_dir_; | 113 base::ScopedTempDir temp_dir_; |
| 114 scoped_refptr<SQLitePersistentCookieStore> store_; | 114 scoped_refptr<SQLitePersistentCookieStore> store_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 // Test the performance of priority load of cookies for a specfic domain key | 117 // Test the performance of priority load of cookies for a specific domain key |
| 118 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { | 118 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { |
| 119 for (int domain_num = 0; domain_num < 3; ++domain_num) { | 119 for (int domain_num = 0; domain_num < 3; ++domain_num) { |
| 120 std::string domain_name(base::StringPrintf("domain_%d.com", domain_num)); | 120 std::string domain_name(base::StringPrintf("domain_%d.com", domain_num)); |
| 121 base::PerfTimeLogger timer( | 121 base::PerfTimeLogger timer( |
| 122 ("Load cookies for the eTLD+1 " + domain_name).c_str()); | 122 ("Load cookies for the eTLD+1 " + domain_name).c_str()); |
| 123 store_->LoadCookiesForKey( | 123 store_->LoadCookiesForKey( |
| 124 domain_name, | 124 domain_name, |
| 125 base::Bind(&SQLitePersistentCookieStorePerfTest::OnKeyLoaded, | 125 base::Bind(&SQLitePersistentCookieStorePerfTest::OnKeyLoaded, |
| 126 base::Unretained(this))); | 126 base::Unretained(this))); |
| 127 key_loaded_event_.Wait(); | 127 key_loaded_event_.Wait(); |
| 128 timer.Done(); | 128 timer.Done(); |
| 129 | 129 |
| 130 ASSERT_EQ(50U, cookies_.size()); | 130 ASSERT_EQ(50U, cookies_.size()); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 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 |