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

Side by Side Diff: net/tools/stress_cache/stress_cache.cc

Issue 2410243002: Remove MessageLoop::current() from stress_cache.cc. (Closed)
Patch Set: Created 4 years, 2 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 | « no previous file | no next file » | 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 // This is a simple application that stress-tests the crash recovery of the disk 5 // This is a simple application that stress-tests the crash recovery of the disk
6 // cache. The main application starts a copy of itself on a loop, checking the 6 // cache. The main application starts a copy of itself on a loop, checking the
7 // exit code of the child process. When the child dies in an unexpected way, 7 // exit code of the child process. When the child dies in an unexpected way,
8 // the main application quits. 8 // the main application quits.
9 9
10 // The child application has two threads: one to exercise the cache in an 10 // The child application has two threads: one to exercise the cache in an
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 334 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
335 base::Bind(&LoopTask)); 335 base::Bind(&LoopTask));
336 base::RunLoop().Run(); 336 base::RunLoop().Run();
337 } 337 }
338 338
339 // We want to prevent the timer thread from killing the process while we are 339 // We want to prevent the timer thread from killing the process while we are
340 // waiting for the debugger to attach. 340 // waiting for the debugger to attach.
341 bool g_crashing = false; 341 bool g_crashing = false;
342 342
343 // RunSoon() and CrashCallback() reference each other, unfortunately. 343 // RunSoon() and CrashCallback() reference each other, unfortunately.
344 void RunSoon(base::MessageLoop* target_loop); 344 void RunSoon(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
345 345
346 void CrashCallback() { 346 void CrashCallback() {
347 // Keep trying to run. 347 // Keep trying to run.
348 RunSoon(base::MessageLoop::current()); 348 RunSoon(base::ThreadTaskRunnerHandle::Get());
349 349
350 if (g_crashing) 350 if (g_crashing)
351 return; 351 return;
352 352
353 if (rand() % 100 > 30) { 353 if (rand() % 100 > 30) {
354 printf("sweet death...\n"); 354 printf("sweet death...\n");
355 #if defined(OS_WIN) 355 #if defined(OS_WIN)
356 // Windows does more work on _exit() than we would like. 356 // Windows does more work on _exit() than we would like.
357 base::Process::Current().Terminate(kExpectedCrash, false); 357 base::Process::Current().Terminate(kExpectedCrash, false);
358 #elif defined(OS_POSIX) 358 #elif defined(OS_POSIX)
359 // On POSIX, _exit() will terminate the process with minimal cleanup, 359 // On POSIX, _exit() will terminate the process with minimal cleanup,
360 // and it is cleaner than killing. 360 // and it is cleaner than killing.
361 _exit(kExpectedCrash); 361 _exit(kExpectedCrash);
362 #endif 362 #endif
363 } 363 }
364 } 364 }
365 365
366 void RunSoon(base::MessageLoop* target_loop) { 366 void RunSoon(scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
367 const base::TimeDelta kTaskDelay = base::TimeDelta::FromSeconds(10); 367 const base::TimeDelta kTaskDelay = base::TimeDelta::FromSeconds(10);
368 target_loop->task_runner()->PostDelayedTask( 368 task_runner->PostDelayedTask(FROM_HERE, base::Bind(&CrashCallback),
369 FROM_HERE, base::Bind(&CrashCallback), kTaskDelay); 369 kTaskDelay);
370 } 370 }
371 371
372 // We leak everything here :) 372 // We leak everything here :)
373 bool StartCrashThread() { 373 bool StartCrashThread() {
374 base::Thread* thread = new base::Thread("party_crasher"); 374 base::Thread* thread = new base::Thread("party_crasher");
375 if (!thread->Start()) 375 if (!thread->Start())
376 return false; 376 return false;
377 377
378 RunSoon(thread->message_loop()); 378 RunSoon(thread->task_runner());
379 return true; 379 return true;
380 } 380 }
381 381
382 void CrashHandler(const std::string& str) { 382 void CrashHandler(const std::string& str) {
383 g_crashing = true; 383 g_crashing = true;
384 base::debug::BreakDebugger(); 384 base::debug::BreakDebugger();
385 } 385 }
386 386
387 bool MessageHandler(int severity, const char* file, int line, 387 bool MessageHandler(int severity, const char* file, int line,
388 size_t message_start, const std::string& str) { 388 size_t message_start, const std::string& str) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 long int iteration = strtol(argv[1], &end, 0); 434 long int iteration = strtol(argv[1], &end, 0);
435 435
436 if (!StartCrashThread()) { 436 if (!StartCrashThread()) {
437 printf("failed to start thread\n"); 437 printf("failed to start thread\n");
438 return kError; 438 return kError;
439 } 439 }
440 440
441 StressTheCache(iteration); 441 StressTheCache(iteration);
442 return 0; 442 return 0;
443 } 443 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698