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

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

Issue 1701063002: CookieStore: Remove reference counting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@threadsafe
Patch Set: merge Created 4 years, 9 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/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
11 #include "base/test/perf_time_logger.h" 13 #include "base/test/perf_time_logger.h"
12 #include "net/cookies/canonical_cookie.h" 14 #include "net/cookies/canonical_cookie.h"
13 #include "net/cookies/cookie_monster.h" 15 #include "net/cookies/cookie_monster.h"
14 #include "net/cookies/cookie_monster_store_test.h" 16 #include "net/cookies/cookie_monster_store_test.h"
15 #include "net/cookies/parsed_cookie.h" 17 #include "net/cookies/parsed_cookie.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 cookie += kCookieLine; 114 cookie += kCookieLine;
113 base::PerfTimeLogger timer("Parsed_cookie_parse_big_cookies"); 115 base::PerfTimeLogger timer("Parsed_cookie_parse_big_cookies");
114 for (int i = 0; i < kNumCookies; ++i) { 116 for (int i = 0; i < kNumCookies; ++i) {
115 ParsedCookie pc(cookie); 117 ParsedCookie pc(cookie);
116 EXPECT_TRUE(pc.IsValid()); 118 EXPECT_TRUE(pc.IsValid());
117 } 119 }
118 timer.Done(); 120 timer.Done();
119 } 121 }
120 122
121 TEST_F(CookieMonsterTest, TestAddCookiesOnSingleHost) { 123 TEST_F(CookieMonsterTest, TestAddCookiesOnSingleHost) {
122 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 124 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
123 std::vector<std::string> cookies; 125 std::vector<std::string> cookies;
124 for (int i = 0; i < kNumCookies; i++) { 126 for (int i = 0; i < kNumCookies; i++) {
125 cookies.push_back(base::StringPrintf("a%03d=b", i)); 127 cookies.push_back(base::StringPrintf("a%03d=b", i));
126 } 128 }
127 129
128 SetCookieCallback setCookieCallback; 130 SetCookieCallback setCookieCallback;
129 131
130 // Add a bunch of cookies on a single host 132 // Add a bunch of cookies on a single host
131 base::PerfTimeLogger timer("Cookie_monster_add_single_host"); 133 base::PerfTimeLogger timer("Cookie_monster_add_single_host");
132 134
(...skipping 12 matching lines...) Expand all
145 } 147 }
146 timer2.Done(); 148 timer2.Done();
147 149
148 base::PerfTimeLogger timer3("Cookie_monster_deleteall_single_host"); 150 base::PerfTimeLogger timer3("Cookie_monster_deleteall_single_host");
149 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); 151 cm->DeleteAllAsync(CookieMonster::DeleteCallback());
150 base::MessageLoop::current()->RunUntilIdle(); 152 base::MessageLoop::current()->RunUntilIdle();
151 timer3.Done(); 153 timer3.Done();
152 } 154 }
153 155
154 TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) { 156 TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) {
155 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 157 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
156 std::string cookie(kCookieLine); 158 std::string cookie(kCookieLine);
157 std::vector<GURL> gurls; // just wanna have ffffuunnn 159 std::vector<GURL> gurls; // just wanna have ffffuunnn
158 for (int i = 0; i < kNumCookies; ++i) { 160 for (int i = 0; i < kNumCookies; ++i) {
159 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i))); 161 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i)));
160 } 162 }
161 163
162 SetCookieCallback setCookieCallback; 164 SetCookieCallback setCookieCallback;
163 165
164 // Add a cookie on a bunch of host 166 // Add a cookie on a bunch of host
165 base::PerfTimeLogger timer("Cookie_monster_add_many_hosts"); 167 base::PerfTimeLogger timer("Cookie_monster_add_many_hosts");
(...skipping 12 matching lines...) Expand all
178 } 180 }
179 timer2.Done(); 181 timer2.Done();
180 182
181 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); 183 base::PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts");
182 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); 184 cm->DeleteAllAsync(CookieMonster::DeleteCallback());
183 base::MessageLoop::current()->RunUntilIdle(); 185 base::MessageLoop::current()->RunUntilIdle();
184 timer3.Done(); 186 timer3.Done();
185 } 187 }
186 188
187 TEST_F(CookieMonsterTest, TestDomainTree) { 189 TEST_F(CookieMonsterTest, TestDomainTree) {
188 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 190 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
189 GetCookiesCallback getCookiesCallback; 191 GetCookiesCallback getCookiesCallback;
190 SetCookieCallback setCookieCallback; 192 SetCookieCallback setCookieCallback;
191 const char domain_cookie_format_tree[] = "a=b; domain=%s"; 193 const char domain_cookie_format_tree[] = "a=b; domain=%s";
192 const std::string domain_base("top.com"); 194 const std::string domain_base("top.com");
193 195
194 std::vector<std::string> domain_list; 196 std::vector<std::string> domain_list;
195 197
196 // Create a balanced binary tree of domains on which the cookie is set. 198 // Create a balanced binary tree of domains on which the cookie is set.
197 domain_list.push_back(domain_base); 199 domain_list.push_back(domain_base);
198 for (int i1 = 0; i1 < 2; i1++) { 200 for (int i1 = 0; i1 < 2; i1++) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 EXPECT_EQ(5, CountInString(cookie_line, '=')) 233 EXPECT_EQ(5, CountInString(cookie_line, '='))
232 << "Cookie line: " << cookie_line; 234 << "Cookie line: " << cookie_line;
233 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree"); 235 base::PerfTimeLogger timer("Cookie_monster_query_domain_tree");
234 for (int i = 0; i < kNumCookies; i++) { 236 for (int i = 0; i < kNumCookies; i++) {
235 getCookiesCallback.GetCookies(cm.get(), probe_gurl); 237 getCookiesCallback.GetCookies(cm.get(), probe_gurl);
236 } 238 }
237 timer.Done(); 239 timer.Done();
238 } 240 }
239 241
240 TEST_F(CookieMonsterTest, TestDomainLine) { 242 TEST_F(CookieMonsterTest, TestDomainLine) {
241 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 243 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
242 SetCookieCallback setCookieCallback; 244 SetCookieCallback setCookieCallback;
243 GetCookiesCallback getCookiesCallback; 245 GetCookiesCallback getCookiesCallback;
244 std::vector<std::string> domain_list; 246 std::vector<std::string> domain_list;
245 GURL probe_gurl("https://b.a.b.a.top.com/"); 247 GURL probe_gurl("https://b.a.b.a.top.com/");
246 std::string cookie_line; 248 std::string cookie_line;
247 249
248 // Create a line of 32 domain cookies such that all cookies stored 250 // Create a line of 32 domain cookies such that all cookies stored
249 // by effective TLD+1 will apply to probe GURL. 251 // by effective TLD+1 will apply to probe GURL.
250 // (TLD + 1 is the level above .com/org/net/etc, e.g. "top.com" 252 // (TLD + 1 is the level above .com/org/net/etc, e.g. "top.com"
251 // or "google.com". "Effective" is added to include sites like 253 // or "google.com". "Effective" is added to include sites like
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 std::string cookie_line( 295 std::string cookie_line(
294 base::StringPrintf("Cookie_%d=1; Path=/", cookie_num)); 296 base::StringPrintf("Cookie_%d=1; Path=/", cookie_num));
295 AddCookieToList(gurl, cookie_line, 297 AddCookieToList(gurl, cookie_line,
296 base::Time::FromInternalValue(time_tick++), 298 base::Time::FromInternalValue(time_tick++),
297 &initial_cookies); 299 &initial_cookies);
298 } 300 }
299 } 301 }
300 302
301 store->SetLoadExpectation(true, initial_cookies); 303 store->SetLoadExpectation(true, initial_cookies);
302 304
303 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 305 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr));
304 306
305 // Import will happen on first access. 307 // Import will happen on first access.
306 GURL gurl("www.google.com"); 308 GURL gurl("www.google.com");
307 CookieOptions options; 309 CookieOptions options;
308 base::PerfTimeLogger timer("Cookie_monster_import_from_store"); 310 base::PerfTimeLogger timer("Cookie_monster_import_from_store");
309 getCookiesCallback.GetCookies(cm.get(), gurl); 311 getCookiesCallback.GetCookies(cm.get(), gurl);
310 timer.Done(); 312 timer.Done();
311 313
312 // Just confirm keys were set as expected. 314 // Just confirm keys were set as expected.
313 EXPECT_EQ("domain_1.com", cm->GetKey("www.Domain_1.com")); 315 EXPECT_EQ("domain_1.com", cm->GetKey("www.Domain_1.com"));
314 } 316 }
315 317
316 TEST_F(CookieMonsterTest, TestGetKey) { 318 TEST_F(CookieMonsterTest, TestGetKey) {
317 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 319 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr));
318 base::PerfTimeLogger timer("Cookie_monster_get_key"); 320 base::PerfTimeLogger timer("Cookie_monster_get_key");
319 for (int i = 0; i < kNumCookies; i++) 321 for (int i = 0; i < kNumCookies; i++)
320 cm->GetKey("www.google.com"); 322 cm->GetKey("www.google.com");
321 timer.Done(); 323 timer.Done();
322 } 324 }
323 325
324 // This test is probing for whether garbage collection happens when it 326 // This test is probing for whether garbage collection happens when it
325 // shouldn't. This will not in general be visible functionally, since 327 // shouldn't. This will not in general be visible functionally, since
326 // if GC runs twice in a row without any change to the store, the second 328 // if GC runs twice in a row without any change to the store, the second
327 // GC run will not do anything the first one didn't. That's why this is 329 // GC run will not do anything the first one didn't. That's why this is
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 }, 365 },
364 { 366 {
365 "less_than_gc_thresh", 367 "less_than_gc_thresh",
366 // Few enough cookies that gc shouldn't happen at all. 368 // Few enough cookies that gc shouldn't happen at all.
367 CookieMonster::kMaxCookies - 5, 369 CookieMonster::kMaxCookies - 5,
368 0, 370 0,
369 }, 371 },
370 }; 372 };
371 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { 373 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) {
372 const TestCase& test_case(test_cases[ci]); 374 const TestCase& test_case(test_cases[ci]);
373 scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC( 375 scoped_ptr<CookieMonster> cm = CreateMonsterFromStoreForGC(
374 test_case.num_cookies, test_case.num_old_cookies, 0, 0, 376 test_case.num_cookies, test_case.num_old_cookies, 0, 0,
375 CookieMonster::kSafeFromGlobalPurgeDays * 2)); 377 CookieMonster::kSafeFromGlobalPurgeDays * 2);
376 378
377 GURL gurl("http://google.com"); 379 GURL gurl("http://google.com");
378 std::string cookie_line("z=3"); 380 std::string cookie_line("z=3");
379 // Trigger the Garbage collection we're allowed. 381 // Trigger the Garbage collection we're allowed.
380 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); 382 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
381 383
382 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); 384 base::PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str());
383 for (int i = 0; i < kNumCookies; i++) 385 for (int i = 0; i < kNumCookies; i++)
384 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line); 386 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
385 timer.Done(); 387 timer.Done();
386 } 388 }
387 } 389 }
388 390
389 } // namespace net 391 } // 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