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

Side by Side Diff: chrome/browser/nacl_host/nacl_browser.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
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 "chrome/browser/nacl_host/nacl_browser.h" 5 #include "chrome/browser/nacl_host/nacl_browser.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 } 344 }
345 345
346 void NaClBrowser::CheckWaiting() { 346 void NaClBrowser::CheckWaiting() {
347 if (!IsOk() || IsReady()) { 347 if (!IsOk() || IsReady()) {
348 // Queue the waiting tasks into the message loop. This helps avoid 348 // Queue the waiting tasks into the message loop. This helps avoid
349 // re-entrancy problems that could occur if the closure was invoked 349 // re-entrancy problems that could occur if the closure was invoked
350 // directly. For example, this could result in use-after-free of the 350 // directly. For example, this could result in use-after-free of the
351 // process host. 351 // process host.
352 for (std::vector<base::Closure>::iterator iter = waiting_.begin(); 352 for (std::vector<base::Closure>::iterator iter = waiting_.begin();
353 iter != waiting_.end(); ++iter) { 353 iter != waiting_.end(); ++iter) {
354 MessageLoop::current()->PostTask(FROM_HERE, *iter); 354 base::MessageLoop::current()->PostTask(FROM_HERE, *iter);
355 } 355 }
356 waiting_.clear(); 356 waiting_.clear();
357 } 357 }
358 } 358 }
359 359
360 void NaClBrowser::MarkAsFailed() { 360 void NaClBrowser::MarkAsFailed() {
361 ok_ = false; 361 ok_ = false;
362 CheckWaiting(); 362 CheckWaiting();
363 } 363 }
364 364
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 if (validation_cache_state_ != NaClResourceReady) { 435 if (validation_cache_state_ != NaClResourceReady) {
436 validation_cache_state_ = NaClResourceReady; 436 validation_cache_state_ = NaClResourceReady;
437 CheckWaiting(); 437 CheckWaiting();
438 } 438 }
439 } 439 }
440 440
441 void NaClBrowser::MarkValidationCacheAsModified() { 441 void NaClBrowser::MarkValidationCacheAsModified() {
442 if (!validation_cache_is_modified_) { 442 if (!validation_cache_is_modified_) {
443 // Wait before persisting to disk. This can coalesce multiple cache 443 // Wait before persisting to disk. This can coalesce multiple cache
444 // modifications info a single disk write. 444 // modifications info a single disk write.
445 MessageLoop::current()->PostDelayedTask( 445 base::MessageLoop::current()->PostDelayedTask(
446 FROM_HERE, 446 FROM_HERE,
447 base::Bind(&NaClBrowser::PersistValidationCache, 447 base::Bind(&NaClBrowser::PersistValidationCache,
448 weak_factory_.GetWeakPtr()), 448 weak_factory_.GetWeakPtr()),
449 base::TimeDelta::FromMilliseconds(kValidationCacheCoalescingTimeMS)); 449 base::TimeDelta::FromMilliseconds(kValidationCacheCoalescingTimeMS));
450 validation_cache_is_modified_ = true; 450 validation_cache_is_modified_ = true;
451 } 451 }
452 } 452 }
453 453
454 void NaClBrowser::PersistValidationCache() { 454 void NaClBrowser::PersistValidationCache() {
455 // validation_cache_is_modified_ may be false if the cache was cleared while 455 // validation_cache_is_modified_ may be false if the cache was cleared while
456 // this delayed task was pending. 456 // this delayed task was pending.
457 // validation_cache_file_path_ may be empty if something went wrong during 457 // validation_cache_file_path_ may be empty if something went wrong during
458 // initialization. 458 // initialization.
459 if (validation_cache_is_modified_ && !validation_cache_file_path_.empty()) { 459 if (validation_cache_is_modified_ && !validation_cache_file_path_.empty()) {
460 Pickle* pickle = new Pickle(); 460 Pickle* pickle = new Pickle();
461 validation_cache_.Serialize(pickle); 461 validation_cache_.Serialize(pickle);
462 462
463 // Pass the serialized data to another thread to write to disk. File IO is 463 // Pass the serialized data to another thread to write to disk. File IO is
464 // not allowed on the IO thread (which is the thread this method runs on) 464 // not allowed on the IO thread (which is the thread this method runs on)
465 // because it can degrade the responsiveness of the browser. 465 // because it can degrade the responsiveness of the browser.
466 // The task is sequenced so that multiple writes happen in order. 466 // The task is sequenced so that multiple writes happen in order.
467 content::BrowserThread::PostBlockingPoolSequencedTask( 467 content::BrowserThread::PostBlockingPoolSequencedTask(
468 kValidationCacheSequenceName, 468 kValidationCacheSequenceName,
469 FROM_HERE, 469 FROM_HERE,
470 base::Bind(WriteCache, validation_cache_file_path_, 470 base::Bind(WriteCache, validation_cache_file_path_,
471 base::Owned(pickle))); 471 base::Owned(pickle)));
472 } 472 }
473 validation_cache_is_modified_ = false; 473 validation_cache_is_modified_ = false;
474 } 474 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations/variations_service_unittest.cc ('k') | chrome/browser/nacl_host/nacl_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698