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

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

Issue 11275088: Remove implicit scoped_refptr operator T* Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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/base/upload_bytes_element_reader_unittest.cc ('k') | net/curvecp/curvecp_server_socket.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 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/perftimer.h" 9 #include "base/perftimer.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 cookies.push_back(base::StringPrintf("a%03d=b", i)); 142 cookies.push_back(base::StringPrintf("a%03d=b", i));
143 } 143 }
144 144
145 SetCookieCallback setCookieCallback; 145 SetCookieCallback setCookieCallback;
146 146
147 // Add a bunch of cookies on a single host 147 // Add a bunch of cookies on a single host
148 PerfTimeLogger timer("Cookie_monster_add_single_host"); 148 PerfTimeLogger timer("Cookie_monster_add_single_host");
149 149
150 for (std::vector<std::string>::const_iterator it = cookies.begin(); 150 for (std::vector<std::string>::const_iterator it = cookies.begin();
151 it != cookies.end(); ++it) { 151 it != cookies.end(); ++it) {
152 setCookieCallback.SetCookie(cm, kUrlGoogle, *it); 152 setCookieCallback.SetCookie(cm.get(), kUrlGoogle, *it);
153 } 153 }
154 timer.Done(); 154 timer.Done();
155 155
156 GetCookiesCallback getCookiesCallback; 156 GetCookiesCallback getCookiesCallback;
157 157
158 PerfTimeLogger timer2("Cookie_monster_query_single_host"); 158 PerfTimeLogger timer2("Cookie_monster_query_single_host");
159 for (std::vector<std::string>::const_iterator it = cookies.begin(); 159 for (std::vector<std::string>::const_iterator it = cookies.begin();
160 it != cookies.end(); ++it) { 160 it != cookies.end(); ++it) {
161 getCookiesCallback.GetCookies(cm, kUrlGoogle); 161 getCookiesCallback.GetCookies(cm.get(), kUrlGoogle);
162 } 162 }
163 timer2.Done(); 163 timer2.Done();
164 164
165 PerfTimeLogger timer3("Cookie_monster_deleteall_single_host"); 165 PerfTimeLogger timer3("Cookie_monster_deleteall_single_host");
166 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); 166 cm->DeleteAllAsync(CookieMonster::DeleteCallback());
167 MessageLoop::current()->RunAllPending(); 167 MessageLoop::current()->RunAllPending();
168 timer3.Done(); 168 timer3.Done();
169 } 169 }
170 170
171 TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) { 171 TEST_F(CookieMonsterTest, TestAddCookieOnManyHosts) {
172 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 172 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
173 std::string cookie(kCookieLine); 173 std::string cookie(kCookieLine);
174 std::vector<GURL> gurls; // just wanna have ffffuunnn 174 std::vector<GURL> gurls; // just wanna have ffffuunnn
175 for (int i = 0; i < kNumCookies; ++i) { 175 for (int i = 0; i < kNumCookies; ++i) {
176 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i))); 176 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i)));
177 } 177 }
178 178
179 SetCookieCallback setCookieCallback; 179 SetCookieCallback setCookieCallback;
180 180
181 // Add a cookie on a bunch of host 181 // Add a cookie on a bunch of host
182 PerfTimeLogger timer("Cookie_monster_add_many_hosts"); 182 PerfTimeLogger timer("Cookie_monster_add_many_hosts");
183 for (std::vector<GURL>::const_iterator it = gurls.begin(); 183 for (std::vector<GURL>::const_iterator it = gurls.begin();
184 it != gurls.end(); ++it) { 184 it != gurls.end(); ++it) {
185 setCookieCallback.SetCookie(cm, *it, cookie); 185 setCookieCallback.SetCookie(cm.get(), *it, cookie);
186 } 186 }
187 timer.Done(); 187 timer.Done();
188 188
189 GetCookiesCallback getCookiesCallback; 189 GetCookiesCallback getCookiesCallback;
190 190
191 PerfTimeLogger timer2("Cookie_monster_query_many_hosts"); 191 PerfTimeLogger timer2("Cookie_monster_query_many_hosts");
192 for (std::vector<GURL>::const_iterator it = gurls.begin(); 192 for (std::vector<GURL>::const_iterator it = gurls.begin();
193 it != gurls.end(); ++it) { 193 it != gurls.end(); ++it) {
194 getCookiesCallback.GetCookies(cm, *it); 194 getCookiesCallback.GetCookies(cm.get(), *it);
195 } 195 }
196 timer2.Done(); 196 timer2.Done();
197 197
198 PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts"); 198 PerfTimeLogger timer3("Cookie_monster_deleteall_many_hosts");
199 cm->DeleteAllAsync(CookieMonster::DeleteCallback()); 199 cm->DeleteAllAsync(CookieMonster::DeleteCallback());
200 MessageLoop::current()->RunAllPending(); 200 MessageLoop::current()->RunAllPending();
201 timer3.Done(); 201 timer3.Done();
202 } 202 }
203 203
204 TEST_F(CookieMonsterTest, TestGetCookiesWithInfo) { 204 TEST_F(CookieMonsterTest, TestGetCookiesWithInfo) {
205 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 205 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
206 206
207 std::vector<GURL> gurls; 207 std::vector<GURL> gurls;
208 for (int i = 0; i < kNumCookies; ++i) 208 for (int i = 0; i < kNumCookies; ++i)
209 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i))); 209 gurls.push_back(GURL(base::StringPrintf("https://a%04d.izzle", i)));
210 210
211 SetCookieCallback setCookieCallback; 211 SetCookieCallback setCookieCallback;
212 212
213 for (std::vector<GURL>::const_iterator it = gurls.begin(); 213 for (std::vector<GURL>::const_iterator it = gurls.begin();
214 it != gurls.end(); ++it) { 214 it != gurls.end(); ++it) {
215 setCookieCallback.SetCookie(cm, *it, kCookieLine); 215 setCookieCallback.SetCookie(cm.get(), *it, kCookieLine);
216 } 216 }
217 217
218 GetCookiesWithInfoCallback getCookiesCallback; 218 GetCookiesWithInfoCallback getCookiesCallback;
219 219
220 PerfTimeLogger timer("Cookie_monster_get_cookie_info"); 220 PerfTimeLogger timer("Cookie_monster_get_cookie_info");
221 for (std::vector<GURL>::const_iterator it = gurls.begin(); 221 for (std::vector<GURL>::const_iterator it = gurls.begin();
222 it != gurls.end(); ++it) { 222 it != gurls.end(); ++it) {
223 getCookiesCallback.GetCookiesWithInfo(cm, *it); 223 getCookiesCallback.GetCookiesWithInfo(cm.get(), *it);
224 } 224 }
225 timer.Done(); 225 timer.Done();
226 } 226 }
227 227
228 static int CountInString(const std::string& str, char c) { 228 static int CountInString(const std::string& str, char c) {
229 return std::count(str.begin(), str.end(), c); 229 return std::count(str.begin(), str.end(), c);
230 } 230 }
231 231
232 TEST_F(CookieMonsterTest, TestDomainTree) { 232 TEST_F(CookieMonsterTest, TestDomainTree) {
233 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 233 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
(...skipping 27 matching lines...) Expand all
261 } 261 }
262 } 262 }
263 263
264 264
265 EXPECT_EQ(31u, domain_list.size()); 265 EXPECT_EQ(31u, domain_list.size());
266 for (std::vector<std::string>::const_iterator it = domain_list.begin(); 266 for (std::vector<std::string>::const_iterator it = domain_list.begin();
267 it != domain_list.end(); it++) { 267 it != domain_list.end(); it++) {
268 GURL gurl("https://" + *it + "/"); 268 GURL gurl("https://" + *it + "/");
269 const std::string cookie = base::StringPrintf(domain_cookie_format_tree, 269 const std::string cookie = base::StringPrintf(domain_cookie_format_tree,
270 it->c_str()); 270 it->c_str());
271 setCookieCallback.SetCookie(cm, gurl, cookie); 271 setCookieCallback.SetCookie(cm.get(), gurl, cookie);
272 } 272 }
273 EXPECT_EQ(31u, cm->GetAllCookies().size()); 273 EXPECT_EQ(31u, cm->GetAllCookies().size());
274 274
275 GURL probe_gurl("https://b.a.b.a.top.com/"); 275 GURL probe_gurl("https://b.a.b.a.top.com/");
276 std::string cookie_line = getCookiesCallback.GetCookies(cm, probe_gurl); 276 std::string cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl);
277 EXPECT_EQ(5, CountInString(cookie_line, '=')) << "Cookie line: " << 277 EXPECT_EQ(5, CountInString(cookie_line, '=')) << "Cookie line: " <<
278 cookie_line; 278 cookie_line;
279 PerfTimeLogger timer("Cookie_monster_query_domain_tree"); 279 PerfTimeLogger timer("Cookie_monster_query_domain_tree");
280 for (int i = 0; i < kNumCookies; i++) { 280 for (int i = 0; i < kNumCookies; i++) {
281 getCookiesCallback.GetCookies(cm, probe_gurl); 281 getCookiesCallback.GetCookies(cm.get(), probe_gurl);
282 } 282 }
283 timer.Done(); 283 timer.Done();
284 } 284 }
285 285
286 TEST_F(CookieMonsterTest, TestDomainLine) { 286 TEST_F(CookieMonsterTest, TestDomainLine) {
287 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 287 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
288 SetCookieCallback setCookieCallback; 288 SetCookieCallback setCookieCallback;
289 GetCookiesCallback getCookiesCallback; 289 GetCookiesCallback getCookiesCallback;
290 std::vector<std::string> domain_list; 290 std::vector<std::string> domain_list;
291 GURL probe_gurl("https://b.a.b.a.top.com/"); 291 GURL probe_gurl("https://b.a.b.a.top.com/");
(...skipping 11 matching lines...) Expand all
303 domain_list.push_back("b.a.b.a.top.com"); 303 domain_list.push_back("b.a.b.a.top.com");
304 EXPECT_EQ(4u, domain_list.size()); 304 EXPECT_EQ(4u, domain_list.size());
305 305
306 const char* domain_cookie_format_line = "a%03d=b; domain=%s"; 306 const char* domain_cookie_format_line = "a%03d=b; domain=%s";
307 for (int i = 0; i < 8; i++) { 307 for (int i = 0; i < 8; i++) {
308 for (std::vector<std::string>::const_iterator it = domain_list.begin(); 308 for (std::vector<std::string>::const_iterator it = domain_list.begin();
309 it != domain_list.end(); it++) { 309 it != domain_list.end(); it++) {
310 GURL gurl("https://" + *it + "/"); 310 GURL gurl("https://" + *it + "/");
311 const std::string cookie = base::StringPrintf(domain_cookie_format_line, 311 const std::string cookie = base::StringPrintf(domain_cookie_format_line,
312 i, it->c_str()); 312 i, it->c_str());
313 setCookieCallback.SetCookie(cm, gurl, cookie); 313 setCookieCallback.SetCookie(cm.get(), gurl, cookie);
314 } 314 }
315 } 315 }
316 316
317 cookie_line = getCookiesCallback.GetCookies(cm, probe_gurl); 317 cookie_line = getCookiesCallback.GetCookies(cm.get(), probe_gurl);
318 EXPECT_EQ(32, CountInString(cookie_line, '=')); 318 EXPECT_EQ(32, CountInString(cookie_line, '='));
319 PerfTimeLogger timer2("Cookie_monster_query_domain_line"); 319 PerfTimeLogger timer2("Cookie_monster_query_domain_line");
320 for (int i = 0; i < kNumCookies; i++) { 320 for (int i = 0; i < kNumCookies; i++) {
321 getCookiesCallback.GetCookies(cm, probe_gurl); 321 getCookiesCallback.GetCookies(cm.get(), probe_gurl);
322 } 322 }
323 timer2.Done(); 323 timer2.Done();
324 } 324 }
325 325
326 TEST_F(CookieMonsterTest, TestImport) { 326 TEST_F(CookieMonsterTest, TestImport) {
327 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 327 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
328 std::vector<CanonicalCookie*> initial_cookies; 328 std::vector<CanonicalCookie*> initial_cookies;
329 GetCookiesCallback getCookiesCallback; 329 GetCookiesCallback getCookiesCallback;
330 330
331 // We want to setup a fairly large backing store, with 300 domains of 50 331 // We want to setup a fairly large backing store, with 300 domains of 50
332 // cookies each. Creation times must be unique. 332 // cookies each. Creation times must be unique.
333 int64 time_tick(base::Time::Now().ToInternalValue()); 333 int64 time_tick(base::Time::Now().ToInternalValue());
334 334
335 for (int domain_num = 0; domain_num < 300; domain_num++) { 335 for (int domain_num = 0; domain_num < 300; domain_num++) {
336 std::string domain_name(base::StringPrintf(".Domain_%d.com", domain_num)); 336 std::string domain_name(base::StringPrintf(".Domain_%d.com", domain_num));
337 std::string gurl("www" + domain_name); 337 std::string gurl("www" + domain_name);
338 for (int cookie_num = 0; cookie_num < 50; cookie_num++) { 338 for (int cookie_num = 0; cookie_num < 50; cookie_num++) {
339 std::string cookie_line(base::StringPrintf("Cookie_%d=1; Path=/", 339 std::string cookie_line(base::StringPrintf("Cookie_%d=1; Path=/",
340 cookie_num)); 340 cookie_num));
341 AddCookieToList(gurl, cookie_line, 341 AddCookieToList(gurl, cookie_line,
342 base::Time::FromInternalValue(time_tick++), 342 base::Time::FromInternalValue(time_tick++),
343 &initial_cookies); 343 &initial_cookies);
344 } 344 }
345 } 345 }
346 346
347 store->SetLoadExpectation(true, initial_cookies); 347 store->SetLoadExpectation(true, initial_cookies);
348 348
349 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); 349 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
350 350
351 // Import will happen on first access. 351 // Import will happen on first access.
352 GURL gurl("www.google.com"); 352 GURL gurl("www.google.com");
353 CookieOptions options; 353 CookieOptions options;
354 PerfTimeLogger timer("Cookie_monster_import_from_store"); 354 PerfTimeLogger timer("Cookie_monster_import_from_store");
355 getCookiesCallback.GetCookies(cm, gurl); 355 getCookiesCallback.GetCookies(cm.get(), gurl);
356 timer.Done(); 356 timer.Done();
357 357
358 // Just confirm keys were set as expected. 358 // Just confirm keys were set as expected.
359 EXPECT_EQ("domain_1.com", cm->GetKey("www.Domain_1.com")); 359 EXPECT_EQ("domain_1.com", cm->GetKey("www.Domain_1.com"));
360 } 360 }
361 361
362 TEST_F(CookieMonsterTest, TestGetKey) { 362 TEST_F(CookieMonsterTest, TestGetKey) {
363 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 363 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
364 PerfTimeLogger timer("Cookie_monster_get_key"); 364 PerfTimeLogger timer("Cookie_monster_get_key");
365 for (int i = 0; i < kNumCookies; i++) 365 for (int i = 0; i < kNumCookies; i++)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) { 413 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) {
414 const TestCase& test_case(test_cases[ci]); 414 const TestCase& test_case(test_cases[ci]);
415 scoped_refptr<CookieMonster> cm( 415 scoped_refptr<CookieMonster> cm(
416 CreateMonsterFromStoreForGC( 416 CreateMonsterFromStoreForGC(
417 test_case.num_cookies, test_case.num_old_cookies, 417 test_case.num_cookies, test_case.num_old_cookies,
418 CookieMonster::kSafeFromGlobalPurgeDays * 2)); 418 CookieMonster::kSafeFromGlobalPurgeDays * 2));
419 419
420 GURL gurl("http://google.com"); 420 GURL gurl("http://google.com");
421 std::string cookie_line("z=3"); 421 std::string cookie_line("z=3");
422 // Trigger the Garbage collection we're allowed. 422 // Trigger the Garbage collection we're allowed.
423 setCookieCallback.SetCookie(cm, gurl, cookie_line); 423 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
424 424
425 PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str()); 425 PerfTimeLogger timer((std::string("GC_") + test_case.name).c_str());
426 for (int i = 0; i < kNumCookies; i++) 426 for (int i = 0; i < kNumCookies; i++)
427 setCookieCallback.SetCookie(cm, gurl, cookie_line); 427 setCookieCallback.SetCookie(cm.get(), gurl, cookie_line);
428 timer.Done(); 428 timer.Done();
429 } 429 }
430 } 430 }
431 431
432 } // namespace 432 } // namespace
OLDNEW
« no previous file with comments | « net/base/upload_bytes_element_reader_unittest.cc ('k') | net/curvecp/curvecp_server_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698