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

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

Powered by Google App Engine
This is Rietveld 408576698