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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/perftimer.h" | 7 #include "base/perftimer.h" |
| 8 #include "base/sequenced_task_runner.h" | |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 11 #include "base/test/thread_test_helper.h" | 11 #include "base/test/sequenced_worker_pool_owner.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | |
| 12 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 13 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
| 13 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 14 #include "content/public/test/test_browser_thread.h" | |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/cookies/canonical_cookie.h" | 16 #include "net/cookies/canonical_cookie.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 using content::BrowserThread; | |
| 20 | |
| 21 class SQLitePersistentCookieStorePerfTest : public testing::Test { | 19 class SQLitePersistentCookieStorePerfTest : public testing::Test { |
| 22 public: | 20 public: |
| 23 SQLitePersistentCookieStorePerfTest() | 21 SQLitePersistentCookieStorePerfTest() |
| 24 : db_thread_(BrowserThread::DB), | 22 : pool_owner_(new base::SequencedWorkerPoolOwner(1, "Background Pool")), |
| 25 io_thread_(BrowserThread::IO), | |
| 26 loaded_event_(false, false), | 23 loaded_event_(false, false), |
| 27 key_loaded_event_(false, false) { | 24 key_loaded_event_(false, false) { |
| 28 } | 25 } |
| 29 | 26 |
| 30 void OnLoaded(const std::vector<net::CanonicalCookie*>& cookies) { | 27 void OnLoaded(const std::vector<net::CanonicalCookie*>& cookies) { |
| 31 cookies_ = cookies; | 28 cookies_ = cookies; |
| 32 loaded_event_.Signal(); | 29 loaded_event_.Signal(); |
| 33 } | 30 } |
| 34 | 31 |
| 35 void OnKeyLoaded(const std::vector<net::CanonicalCookie*>& cookies) { | 32 void OnKeyLoaded(const std::vector<net::CanonicalCookie*>& cookies) { |
| 36 cookies_ = cookies; | 33 cookies_ = cookies; |
| 37 key_loaded_event_.Signal(); | 34 key_loaded_event_.Signal(); |
| 38 } | 35 } |
| 39 | 36 |
| 40 void Load() { | 37 void Load() { |
| 41 store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded, | 38 store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded, |
| 42 base::Unretained(this))); | 39 base::Unretained(this))); |
| 43 loaded_event_.Wait(); | 40 loaded_event_.Wait(); |
| 44 } | 41 } |
| 45 | 42 |
| 43 scoped_refptr<base::SequencedTaskRunner> background_task_runner() { | |
| 44 return pool_owner_->pool()->GetSequencedTaskRunner( | |
| 45 pool_owner_->pool()->GetNamedSequenceToken("background")); | |
| 46 } | |
| 47 | |
| 48 scoped_refptr<base::SequencedTaskRunner> client_task_runner() { | |
| 49 return pool_owner_->pool()->GetSequencedTaskRunner( | |
| 50 pool_owner_->pool()->GetNamedSequenceToken("client")); | |
| 51 } | |
| 52 | |
| 46 virtual void SetUp() { | 53 virtual void SetUp() { |
|
mmenke
2013/02/20 20:58:30
While you're here, this should be OVERRIDE
| |
| 47 db_thread_.Start(); | |
| 48 io_thread_.Start(); | |
| 49 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 54 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 50 store_ = new SQLitePersistentCookieStore( | 55 store_ = new SQLitePersistentCookieStore( |
| 51 temp_dir_.path().Append(chrome::kCookieFilename), | 56 temp_dir_.path().Append(chrome::kCookieFilename), |
| 57 client_task_runner(), | |
| 58 background_task_runner(), | |
| 52 false, NULL); | 59 false, NULL); |
| 53 std::vector<net::CanonicalCookie*> cookies; | 60 std::vector<net::CanonicalCookie*> cookies; |
| 54 Load(); | 61 Load(); |
| 55 ASSERT_EQ(0u, cookies_.size()); | 62 ASSERT_EQ(0u, cookies_.size()); |
| 56 // Creates 15000 cookies from 300 eTLD+1s. | 63 // Creates 15000 cookies from 300 eTLD+1s. |
| 57 base::Time t = base::Time::Now(); | 64 base::Time t = base::Time::Now(); |
| 58 for (int domain_num = 0; domain_num < 300; domain_num++) { | 65 for (int domain_num = 0; domain_num < 300; domain_num++) { |
| 59 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); | 66 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); |
| 60 GURL gurl("www" + domain_name); | 67 GURL gurl("www" + domain_name); |
| 61 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { | 68 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { |
| 62 t += base::TimeDelta::FromInternalValue(10); | 69 t += base::TimeDelta::FromInternalValue(10); |
| 63 store_->AddCookie( | 70 store_->AddCookie( |
| 64 net::CanonicalCookie(gurl, | 71 net::CanonicalCookie(gurl, |
| 65 base::StringPrintf("Cookie_%d", cookie_num), "1", | 72 base::StringPrintf("Cookie_%d", cookie_num), "1", |
| 66 domain_name, "/", std::string(), std::string(), | 73 domain_name, "/", std::string(), std::string(), |
| 67 t, t, t, false, false)); | 74 t, t, t, false, false)); |
| 68 } | 75 } |
| 69 } | 76 } |
| 70 // Replace the store effectively destroying the current one and forcing it | 77 // Replace the store effectively destroying the current one and forcing it |
| 71 // to write its data to disk. | 78 // to write its data to disk. |
| 72 store_ = NULL; | 79 store_ = NULL; |
| 73 scoped_refptr<base::ThreadTestHelper> helper( | 80 |
| 74 new base::ThreadTestHelper( | 81 // Shut down the pool, causing deferred (no-op) commits to be discarded. |
| 75 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | 82 pool_owner_->pool()->Shutdown(); |
| 76 // Make sure we wait until the destructor has run. | 83 // ~SequencedWorkerPoolOwner blocks on pool shutdown. |
| 77 ASSERT_TRUE(helper->Run()); | 84 pool_owner_.reset(new base::SequencedWorkerPoolOwner(1, "pool")); |
| 78 | 85 |
| 79 store_ = new SQLitePersistentCookieStore( | 86 store_ = new SQLitePersistentCookieStore( |
| 80 temp_dir_.path().Append(chrome::kCookieFilename), false, NULL); | 87 temp_dir_.path().Append(chrome::kCookieFilename), |
| 88 client_task_runner(), | |
| 89 background_task_runner(), | |
| 90 false, NULL); | |
| 91 } | |
| 92 | |
| 93 virtual void TearDown() { | |
|
mmenke
2013/02/20 20:58:30
OVERRIDE
| |
| 94 store_ = NULL; | |
| 95 pool_owner_->pool()->Shutdown(); | |
| 81 } | 96 } |
| 82 | 97 |
| 83 protected: | 98 protected: |
| 84 content::TestBrowserThread db_thread_; | 99 scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; |
| 85 content::TestBrowserThread io_thread_; | |
| 86 base::WaitableEvent loaded_event_; | 100 base::WaitableEvent loaded_event_; |
| 87 base::WaitableEvent key_loaded_event_; | 101 base::WaitableEvent key_loaded_event_; |
| 88 std::vector<net::CanonicalCookie*> cookies_; | 102 std::vector<net::CanonicalCookie*> cookies_; |
| 89 base::ScopedTempDir temp_dir_; | 103 base::ScopedTempDir temp_dir_; |
| 90 scoped_refptr<SQLitePersistentCookieStore> store_; | 104 scoped_refptr<SQLitePersistentCookieStore> store_; |
| 91 }; | 105 }; |
| 92 | 106 |
| 93 // Test the performance of priority load of cookies for a specfic domain key | 107 // Test the performance of priority load of cookies for a specfic domain key |
| 94 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { | 108 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { |
| 95 for (int domain_num = 0; domain_num < 3; ++domain_num) { | 109 for (int domain_num = 0; domain_num < 3; ++domain_num) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 107 } | 121 } |
| 108 | 122 |
| 109 // Test the performance of load | 123 // Test the performance of load |
| 110 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { | 124 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { |
| 111 PerfTimeLogger timer("Load all cookies"); | 125 PerfTimeLogger timer("Load all cookies"); |
| 112 Load(); | 126 Load(); |
| 113 timer.Done(); | 127 timer.Done(); |
| 114 | 128 |
| 115 ASSERT_EQ(15000U, cookies_.size()); | 129 ASSERT_EQ(15000U, cookies_.size()); |
| 116 } | 130 } |
| OLD | NEW |