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

Side by Side Diff: net/cookies/cookie_monster_perftest.cc

Issue 2971323002: Switch cookie async mechanism over to using callbacks. (Closed)
Patch Set: Incorporated comments. Created 3 years, 5 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 | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_monster_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 <algorithm> 5 #include <algorithm>
6 #include <memory> 6 #include <memory>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 class CookieMonsterTest : public testing::Test { 34 class CookieMonsterTest : public testing::Test {
35 public: 35 public:
36 CookieMonsterTest() : message_loop_(new base::MessageLoopForIO()) {} 36 CookieMonsterTest() : message_loop_(new base::MessageLoopForIO()) {}
37 37
38 private: 38 private:
39 std::unique_ptr<base::MessageLoop> message_loop_; 39 std::unique_ptr<base::MessageLoop> message_loop_;
40 }; 40 };
41 41
42 class BaseCallback { 42 class CookieTestCallback {
43 public: 43 public:
44 BaseCallback() : has_run_(false) {} 44 CookieTestCallback() : has_run_(false) {}
45 45
46 protected: 46 protected:
47 void WaitForCallback() { 47 void WaitForCallback() {
48 // Note that the performance tests currently all operate on a loaded cookie 48 // Note that the performance tests currently all operate on a loaded cookie
49 // store (or, more precisely, one that has no backing persistent store). 49 // store (or, more precisely, one that has no backing persistent store).
50 // Therefore, callbacks will actually always complete synchronously. If the 50 // Therefore, callbacks will actually always complete synchronously. If the
51 // tests get more advanced we need to add other means of signaling 51 // tests get more advanced we need to add other means of signaling
52 // completion. 52 // completion.
53 base::RunLoop().RunUntilIdle(); 53 base::RunLoop().RunUntilIdle();
54 EXPECT_TRUE(has_run_); 54 EXPECT_TRUE(has_run_);
55 has_run_ = false; 55 has_run_ = false;
56 } 56 }
57 57
58 void Run() { has_run_ = true; } 58 void Run() { has_run_ = true; }
59 59
60 bool has_run_; 60 bool has_run_;
61 }; 61 };
62 62
63 class SetCookieCallback : public BaseCallback { 63 class SetCookieCallback : public CookieTestCallback {
64 public: 64 public:
65 void SetCookie(CookieMonster* cm, 65 void SetCookie(CookieMonster* cm,
66 const GURL& gurl, 66 const GURL& gurl,
67 const std::string& cookie) { 67 const std::string& cookie) {
68 cm->SetCookieWithOptionsAsync( 68 cm->SetCookieWithOptionsAsync(
69 gurl, cookie, options_, 69 gurl, cookie, options_,
70 base::Bind(&SetCookieCallback::Run, base::Unretained(this))); 70 base::Bind(&SetCookieCallback::Run, base::Unretained(this)));
71 WaitForCallback(); 71 WaitForCallback();
72 } 72 }
73 73
74 private: 74 private:
75 void Run(bool success) { 75 void Run(bool success) {
76 EXPECT_TRUE(success); 76 EXPECT_TRUE(success);
77 BaseCallback::Run(); 77 CookieTestCallback::Run();
78 } 78 }
79 CookieOptions options_; 79 CookieOptions options_;
80 }; 80 };
81 81
82 class GetCookiesCallback : public BaseCallback { 82 class GetCookiesCallback : public CookieTestCallback {
83 public: 83 public:
84 const std::string& GetCookies(CookieMonster* cm, const GURL& gurl) { 84 const std::string& GetCookies(CookieMonster* cm, const GURL& gurl) {
85 cm->GetCookiesWithOptionsAsync( 85 cm->GetCookiesWithOptionsAsync(
86 gurl, options_, 86 gurl, options_,
87 base::Bind(&GetCookiesCallback::Run, base::Unretained(this))); 87 base::Bind(&GetCookiesCallback::Run, base::Unretained(this)));
88 WaitForCallback(); 88 WaitForCallback();
89 return cookies_; 89 return cookies_;
90 } 90 }
91 91
92 private: 92 private:
93 void Run(const std::string& cookies) { 93 void Run(const std::string& cookies) {
94 cookies_ = cookies; 94 cookies_ = cookies;
95 BaseCallback::Run(); 95 CookieTestCallback::Run();
96 } 96 }
97 std::string cookies_; 97 std::string cookies_;
98 CookieOptions options_; 98 CookieOptions options_;
99 }; 99 };
100 100
101 class GetAllCookiesCallback : public CookieTestCallback {
102 public:
103 CookieList GetAllCookies(CookieMonster* cm) {
104 cm->GetAllCookiesAsync(
105 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(this)));
106 WaitForCallback();
107 return cookies_;
108 }
109
110 private:
111 void Run(const CookieList& cookies) {
112 cookies_ = cookies;
113 CookieTestCallback::Run();
114 }
115 CookieList cookies_;
116 };
117
101 } // namespace 118 } // namespace
102 119
103 TEST(ParsedCookieTest, TestParseCookies) { 120 TEST(ParsedCookieTest, TestParseCookies) {
104 std::string cookie(kCookieLine); 121 std::string cookie(kCookieLine);
105 base::PerfTimeLogger timer("Parsed_cookie_parse_cookies"); 122 base::PerfTimeLogger timer("Parsed_cookie_parse_cookies");
106 for (int i = 0; i < kNumCookies; ++i) { 123 for (int i = 0; i < kNumCookies; ++i) {
107 ParsedCookie pc(cookie); 124 ParsedCookie pc(cookie);
108 EXPECT_TRUE(pc.IsValid()); 125 EXPECT_TRUE(pc.IsValid());
109 } 126 }
110 timer.Done(); 127 timer.Done();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 237 }
221 238
222 EXPECT_EQ(31u, domain_list.size()); 239 EXPECT_EQ(31u, domain_list.size());
223 for (std::vector<std::string>::const_iterator it = domain_list.begin(); 240 for (std::vector<std::string>::const_iterator it = domain_list.begin();
224 it != domain_list.end(); it++) { 241 it != domain_list.end(); it++) {
225 GURL gurl("https://" + *it + "/"); 242 GURL gurl("https://" + *it + "/");
226 const std::string cookie = 243 const std::string cookie =
227 base::StringPrintf(domain_cookie_format_tree, it->c_str()); 244 base::StringPrintf(domain_cookie_format_tree, it->c_str());
228 setCookieCallback.SetCookie(cm.get(), gurl, cookie); 245 setCookieCallback.SetCookie(cm.get(), gurl, cookie);
229 } 246 }
230 EXPECT_EQ(31u, cm->GetAllCookies().size()); 247
248 GetAllCookiesCallback getAllCookiesCallback;
249 EXPECT_EQ(31u, getAllCookiesCallback.GetAllCookies(cm.get()).size());
231 250
232 GURL probe_gurl("https://b.a.b.a.top.com/"); 251 GURL probe_gurl("https://b.a.b.a.top.com/");
233 std::string cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl); 252 std::string cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl);
234 EXPECT_EQ(5, CountInString(cookie_line, '=')) 253 EXPECT_EQ(5, CountInString(cookie_line, '='))
235 << "Cookie line: " << cookie_line; 254 << "Cookie line: " << cookie_line;
236 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree"); 255 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree");
237 for (int i = 0; i < kNumCookies; i++) { 256 for (int i = 0; i < kNumCookies; i++) {
238 getCookiesCallback.GetCookies(cm.get(), probe_gurl); 257 getCookiesCallback.GetCookies(cm.get(), probe_gurl);
239 } 258 }
240 timer.Done(); 259 timer.Done();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); 401 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
383 402
384 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); 403 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str());
385 for (int i = 0; i < kNumCookies; i++) 404 for (int i = 0; i < kNumCookies; i++)
386 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); 405 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
387 timer.Done(); 406 timer.Done();
388 } 407 }
389 } 408 }
390 409
391 } // namespace net 410 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_monster_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698