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

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

Issue 929303003: clang-formatting files in //net/cookies to clear up a diff. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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_store_test.h » ('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 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // Note that the performance tests currently all operate on a loaded cookie 45 // Note that the performance tests currently all operate on a loaded cookie
46 // store (or, more precisely, one that has no backing persistent store). 46 // store (or, more precisely, one that has no backing persistent store).
47 // Therefore, callbacks will actually always complete synchronously. If the 47 // Therefore, callbacks will actually always complete synchronously. If the
48 // tests get more advanced we need to add other means of signaling 48 // tests get more advanced we need to add other means of signaling
49 // completion. 49 // completion.
50 base::MessageLoop::current()->RunUntilIdle(); 50 base::MessageLoop::current()->RunUntilIdle();
51 EXPECT_TRUE(has_run_); 51 EXPECT_TRUE(has_run_);
52 has_run_ = false; 52 has_run_ = false;
53 } 53 }
54 54
55 void Run() { 55 void Run() { has_run_ = true; }
56 has_run_ = true;
57 }
58 56
59 bool has_run_; 57 bool has_run_;
60 }; 58 };
61 59
62 class SetCookieCallback : public BaseCallback { 60 class SetCookieCallback : public BaseCallback {
63 public: 61 public:
64 void SetCookie( 62 void SetCookie(CookieMonster* cm,
65 CookieMonster* cm, const GURL& gurl, const std::string& cookie) { 63 const GURL& gurl,
66 cm->SetCookieWithOptionsAsync(gurl, cookie, options_, base::Bind( 64 const std::string& cookie) {
67 &SetCookieCallback::Run, base::Unretained(this))); 65 cm->SetCookieWithOptionsAsync(
66 gurl, cookie, options_,
67 base::Bind(&SetCookieCallback::Run, base::Unretained(this)));
68 WaitForCallback(); 68 WaitForCallback();
69 } 69 }
70
70 private: 71 private:
71 void Run(bool success) { 72 void Run(bool success) {
72 EXPECT_TRUE(success); 73 EXPECT_TRUE(success);
73 BaseCallback::Run(); 74 BaseCallback::Run();
74 } 75 }
75 net::CookieOptions options_; 76 net::CookieOptions options_;
76 }; 77 };
77 78
78 class GetCookiesCallback : public BaseCallback { 79 class GetCookiesCallback : public BaseCallback {
79 public: 80 public:
80 const std::string& GetCookies(CookieMonster* cm, const GURL& gurl) { 81 const std::string& GetCookies(CookieMonster* cm, const GURL& gurl) {
81 cm->GetCookiesWithOptionsAsync(gurl, options_, base::Bind( 82 cm->GetCookiesWithOptionsAsync(
82 &GetCookiesCallback::Run, base::Unretained(this))); 83 gurl, options_,
84 base::Bind(&GetCookiesCallback::Run, base::Unretained(this)));
83 WaitForCallback(); 85 WaitForCallback();
84 return cookies_; 86 return cookies_;
85 } 87 }
86 88
87 private: 89 private:
88 void Run(const std::string& cookies) { 90 void Run(const std::string& cookies) {
89 cookies_ = cookies; 91 cookies_ = cookies;
90 BaseCallback::Run(); 92 BaseCallback::Run();
91 } 93 }
92 std::string cookies_; 94 std::string cookies_;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 std::string cookie(kCookieLine); 156 std::string cookie(kCookieLine);
155 std::vector<GURL> gurls; // just wanna have ffffuunnn 157 std::vector<GURL> gurls; // just wanna have ffffuunnn
156 for (int i = 0; i < kNumCookies; ++i) { 158 for (int i = 0; i < kNumCookies; ++i) {
157 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i))); 159 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i)));
158 } 160 }
159 161
160 SetCookieCallback setCookieCallback; 162 SetCookieCallback setCookieCallback;
161 163
162 // Add a cookie on a bunch of host 164 // Add a cookie on a bunch of host
163 base::PerfTimeLogger timer("Cookie_monster_add_many_hosts"); 165 base::PerfTimeLogger timer("Cookie_monster_add_many_hosts");
164 for (std::vector<GURL>::const_iterator it = gurls.begin(); 166 for (std::vector<GURL>::const_iterator it = gurls.begin(); it != gurls.end();
165 it != gurls.end(); ++it) { 167 ++it) {
166 setCookieCallback.SetCookie(cm.get(), *it, cookie); 168 setCookieCallback.SetCookie(cm.get(), *it, cookie);
167 } 169 }
168 timer.Done(); 170 timer.Done();
169 171
170 GetCookiesCallback getCookiesCallback; 172 GetCookiesCallback getCookiesCallback;
171 173
172 base::PerfTimeLogger timer2("Cookie_monster_query_many_hosts"); 174 base::PerfTimeLogger timer2("Cookie_monster_query_many_hosts");
173 for (std::vector<GURL>::const_iterator it = gurls.begin(); 175 for (std::vector<GURL>::const_iterator it = gurls.begin(); it != gurls.end();
174 it != gurls.end(); ++it) { 176 ++it) {
175 getCookiesCallback.GetCookies(cm.get(), *it); 177 getCookiesCallback.GetCookies(cm.get(), *it);
176 } 178 }
177 timer2.Done(); 179 timer2.Done();
178 180
179 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); 181 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts");
180 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); 182 cm->DeleteAllAsync(CookieMonster::DeleteCallback());
181 base::MessageLoop::current()->RunUntilIdle(); 183 base::MessageLoop::current()->RunUntilIdle();
182 timer3.Done(); 184 timer3.Done();
183 } 185 }
184 186
(...skipping 22 matching lines...) Expand all
207 domain_list.push_back(domain_base_3); 209 domain_list.push_back(domain_base_3);
208 for (int i4 = 0; i4 < 2; i4++) { 210 for (int i4 = 0; i4 < 2; i4++) {
209 std::string domain_base_4((i4 ? "a." : "b.") + domain_base_3); 211 std::string domain_base_4((i4 ? "a." : "b.") + domain_base_3);
210 EXPECT_EQ("top.com", cm->GetKey(domain_base_4)); 212 EXPECT_EQ("top.com", cm->GetKey(domain_base_4));
211 domain_list.push_back(domain_base_4); 213 domain_list.push_back(domain_base_4);
212 } 214 }
213 } 215 }
214 } 216 }
215 } 217 }
216 218
217
218 EXPECT_EQ(31u, domain_list.size()); 219 EXPECT_EQ(31u, domain_list.size());
219 for (std::vector<std::string>::const_iterator it = domain_list.begin(); 220 for (std::vector<std::string>::const_iterator it = domain_list.begin();
220 it != domain_list.end(); it++) { 221 it != domain_list.end(); it++) {
221 GURL gurl("https://" + *it + "/"); 222 GURL gurl("https://" + *it + "/");
222 const std::string cookie = base::StringPrintf(domain_cookie_format_tree, 223 const std::string cookie =
223 it->c_str()); 224 base::StringPrintf(domain_cookie_format_tree, it->c_str());
224 setCookieCallback.SetCookie(cm.get(), gurl, cookie); 225 setCookieCallback.SetCookie(cm.get(), gurl, cookie);
225 } 226 }
226 EXPECT_EQ(31u, cm->GetAllCookies().size()); 227 EXPECT_EQ(31u, cm->GetAllCookies().size());
227 228
228 GURL probe_gurl("https://b.a.b.a.top.com/"); 229 GURL probe_gurl("https://b.a.b.a.top.com/");
229 std::string cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl); 230 std::string cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl);
230 EXPECT_EQ(5, CountInString(cookie_line, '=')) 231 EXPECT_EQ(5, CountInString(cookie_line, '='))
231 << "Cookie line: " << cookie_line; 232 << "Cookie line: " << cookie_line;
232 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree"); 233 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree");
233 for (int i = 0; i < kNumCookies; i++) { 234 for (int i = 0; i < kNumCookies; i++) {
(...skipping 20 matching lines...) Expand all
254 domain_list.push_back("b.a.top.com"); 255 domain_list.push_back("b.a.top.com");
255 domain_list.push_back("a.b.a.top.com"); 256 domain_list.push_back("a.b.a.top.com");
256 domain_list.push_back("b.a.b.a.top.com"); 257 domain_list.push_back("b.a.b.a.top.com");
257 EXPECT_EQ(4u, domain_list.size()); 258 EXPECT_EQ(4u, domain_list.size());
258 259
259 const char domain_cookie_format_line[] = "a%03d=b; domain=%s"; 260 const char domain_cookie_format_line[] = "a%03d=b; domain=%s";
260 for (int i = 0; i < 8; i++) { 261 for (int i = 0; i < 8; i++) {
261 for (std::vector<std::string>::const_iterator it = domain_list.begin(); 262 for (std::vector<std::string>::const_iterator it = domain_list.begin();
262 it != domain_list.end(); it++) { 263 it != domain_list.end(); it++) {
263 GURL gurl("https://" + *it + "/"); 264 GURL gurl("https://" + *it + "/");
264 const std::string cookie = base::StringPrintf(domain_cookie_format_line, 265 const std::string cookie =
265 i, it->c_str()); 266 base::StringPrintf(domain_cookie_format_line, i, it->c_str());
266 setCookieCallback.SetCookie(cm.get(), gurl, cookie); 267 setCookieCallback.SetCookie(cm.get(), gurl, cookie);
267 } 268 }
268 } 269 }
269 270
270 cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl); 271 cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl);
271 EXPECT_EQ(32, CountInString(cookie_line, '=')); 272 EXPECT_EQ(32, CountInString(cookie_line, '='));
272 base::PerfTimeLogger timer2("Cookie_monster_query_domain_line"); 273 base::PerfTimeLogger timer2("Cookie_monster_query_domain_line");
273 for (int i = 0; i < kNumCookies; i++) { 274 for (int i = 0; i < kNumCookies; i++) {
274 getCookiesCallback.GetCookies(cm.get(), probe_gurl); 275 getCookiesCallback.GetCookies(cm.get(), probe_gurl);
275 } 276 }
276 timer2.Done(); 277 timer2.Done();
277 } 278 }
278 279
279 TEST_F(CookieMonsterTest, TestImport) { 280 TEST_F(CookieMonsterTest, TestImport) {
280 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 281 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
281 std::vector<CanonicalCookie*> initial_cookies; 282 std::vector<CanonicalCookie*> initial_cookies;
282 GetCookiesCallback getCookiesCallback; 283 GetCookiesCallback getCookiesCallback;
283 284
284 // We want to setup a fairly large backing store, with 300 domains of 50 285 // We want to setup a fairly large backing store, with 300 domains of 50
285 // cookies each. Creation times must be unique. 286 // cookies each. Creation times must be unique.
286 int64 time_tick(base::Time::Now().ToInternalValue()); 287 int64 time_tick(base::Time::Now().ToInternalValue());
287 288
288 for (int domain_num = 0; domain_num < 300; domain_num++) { 289 for (int domain_num = 0; domain_num < 300; domain_num++) {
289 std::string domain_name(base::StringPrintf(".Domain_%d.com", domain_num)); 290 std::string domain_name(base::StringPrintf(".Domain_%d.com", domain_num));
290 std::string gurl("www" + domain_name); 291 std::string gurl("www" + domain_name);
291 for (int cookie_num = 0; cookie_num < 50; cookie_num++) { 292 for (int cookie_num = 0; cookie_num < 50; cookie_num++) {
292 std::string cookie_line(base::StringPrintf("Cookie_%d=1; Path=/", 293 std::string cookie_line(
293 cookie_num)); 294 base::StringPrintf("Cookie_%d=1; Path=/", cookie_num));
294 AddCookieToList(gurl, cookie_line, 295 AddCookieToList(gurl, cookie_line,
295 base::Time::FromInternalValue(time_tick++), 296 base::Time::FromInternalValue(time_tick++),
296 &initial_cookies); 297 &initial_cookies);
297 } 298 }
298 } 299 }
299 300
300 store->SetLoadExpectation(true, initial_cookies); 301 store->SetLoadExpectation(true, initial_cookies);
301 302
302 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 303 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
303 304
(...skipping 24 matching lines...) Expand all
328 // times reported are approximately the same--this indicates that no GC 329 // times reported are approximately the same--this indicates that no GC
329 // happened repeatedly for any case. 330 // happened repeatedly for any case.
330 TEST_F(CookieMonsterTest, TestGCTimes) { 331 TEST_F(CookieMonsterTest, TestGCTimes) {
331 SetCookieCallback setCookieCallback; 332 SetCookieCallback setCookieCallback;
332 333
333 const struct TestCase { 334 const struct TestCase {
334 const char* const name; 335 const char* const name;
335 size_t num_cookies; 336 size_t num_cookies;
336 size_t num_old_cookies; 337 size_t num_old_cookies;
337 } test_cases[] = { 338 } test_cases[] = {
338 { 339 {
339 // A whole lot of recent cookies; gc shouldn't happen. 340 // A whole lot of recent cookies; gc shouldn't happen.
340 "all_recent", 341 "all_recent",
341 CookieMonster::kMaxCookies * 2, 342 CookieMonster::kMaxCookies * 2,
342 0, 343 0,
343 }, { 344 },
344 // Some old cookies, but still overflowing max. 345 {
345 "mostly_recent", 346 // Some old cookies, but still overflowing max.
346 CookieMonster::kMaxCookies * 2, 347 "mostly_recent",
347 CookieMonster::kMaxCookies / 2, 348 CookieMonster::kMaxCookies * 2,
348 }, { 349 CookieMonster::kMaxCookies / 2,
349 // Old cookies enough to bring us right down to our purge line. 350 },
350 "balanced", 351 {
351 CookieMonster::kMaxCookies * 2, 352 // Old cookies enough to bring us right down to our purge line.
352 CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1, 353 "balanced",
353 }, { 354 CookieMonster::kMaxCookies * 2,
354 "mostly_old", 355 CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1,
355 // Old cookies enough to bring below our purge line (which we 356 },
356 // shouldn't do). 357 {
357 CookieMonster::kMaxCookies * 2, 358 "mostly_old",
358 CookieMonster::kMaxCookies * 3 / 4, 359 // Old cookies enough to bring below our purge line (which we
359 }, { 360 // shouldn't do).
360 "less_than_gc_thresh", 361 CookieMonster::kMaxCookies * 2,
361 // Few enough cookies that gc shouldn't happen at all. 362 CookieMonster::kMaxCookies * 3 / 4,
362 CookieMonster::kMaxCookies - 5, 363 },
363 0, 364 {
364 }, 365 "less_than_gc_thresh",
366 // Few enough cookies that gc shouldn't happen at all.
367 CookieMonster::kMaxCookies - 5,
368 0,
369 },
365 }; 370 };
366 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { 371 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) {
367 const TestCase& test_case(test_cases[ci]); 372 const TestCase& test_case(test_cases[ci]);
368 scoped_refptr<CookieMonster> cm( 373 scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC(
369 CreateMonsterFromStoreForGC( 374 test_case.num_cookies, test_case.num_old_cookies,
370 test_case.num_cookies, test_case.num_old_cookies, 375 CookieMonster::kSafeFromGlobalPurgeDays * 2));
371 CookieMonster::kSafeFromGlobalPurgeDays * 2));
372 376
373 GURL gurl("http://google.com"); 377 GURL gurl("http://google.com");
374 std::string cookie_line("z=3"); 378 std::string cookie_line("z=3");
375 // Trigger the Garbage collection we're allowed. 379 // Trigger the Garbage collection we're allowed.
376 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); 380 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
377 381
378 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); 382 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str());
379 for (int i = 0; i < kNumCookies; i++) 383 for (int i = 0; i < kNumCookies; i++)
380 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); 384 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
381 timer.Done(); 385 timer.Done();
382 } 386 }
383 } 387 }
384 388
385 } // namespace net 389 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_monster_store_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698