| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/browser/nacl_browser.h" | 5 #include "components/nacl/browser/nacl_browser.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_proxy.h" | 8 #include "base/files/file_proxy.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/location.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/pickle.h" | 13 #include "base/pickle.h" |
| 14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" |
| 15 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 16 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
| 17 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // An arbitrary delay to coalesce multiple writes to the cache. | 25 // An arbitrary delay to coalesce multiple writes to the cache. |
| 24 const int kValidationCacheCoalescingTimeMS = 6000; | 26 const int kValidationCacheCoalescingTimeMS = 6000; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 376 |
| 375 void NaClBrowser::CheckWaiting() { | 377 void NaClBrowser::CheckWaiting() { |
| 376 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 378 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 377 if (!IsOk() || IsReady()) { | 379 if (!IsOk() || IsReady()) { |
| 378 // Queue the waiting tasks into the message loop. This helps avoid | 380 // Queue the waiting tasks into the message loop. This helps avoid |
| 379 // re-entrancy problems that could occur if the closure was invoked | 381 // re-entrancy problems that could occur if the closure was invoked |
| 380 // directly. For example, this could result in use-after-free of the | 382 // directly. For example, this could result in use-after-free of the |
| 381 // process host. | 383 // process host. |
| 382 for (std::vector<base::Closure>::iterator iter = waiting_.begin(); | 384 for (std::vector<base::Closure>::iterator iter = waiting_.begin(); |
| 383 iter != waiting_.end(); ++iter) { | 385 iter != waiting_.end(); ++iter) { |
| 384 base::MessageLoop::current()->PostTask(FROM_HERE, *iter); | 386 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, *iter); |
| 385 } | 387 } |
| 386 waiting_.clear(); | 388 waiting_.clear(); |
| 387 } | 389 } |
| 388 } | 390 } |
| 389 | 391 |
| 390 void NaClBrowser::MarkAsFailed() { | 392 void NaClBrowser::MarkAsFailed() { |
| 391 ok_ = false; | 393 ok_ = false; |
| 392 CheckWaiting(); | 394 CheckWaiting(); |
| 393 } | 395 } |
| 394 | 396 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 if (validation_cache_state_ != NaClResourceReady) { | 507 if (validation_cache_state_ != NaClResourceReady) { |
| 506 validation_cache_state_ = NaClResourceReady; | 508 validation_cache_state_ = NaClResourceReady; |
| 507 CheckWaiting(); | 509 CheckWaiting(); |
| 508 } | 510 } |
| 509 } | 511 } |
| 510 | 512 |
| 511 void NaClBrowser::MarkValidationCacheAsModified() { | 513 void NaClBrowser::MarkValidationCacheAsModified() { |
| 512 if (!validation_cache_is_modified_) { | 514 if (!validation_cache_is_modified_) { |
| 513 // Wait before persisting to disk. This can coalesce multiple cache | 515 // Wait before persisting to disk. This can coalesce multiple cache |
| 514 // modifications info a single disk write. | 516 // modifications info a single disk write. |
| 515 base::MessageLoop::current()->PostDelayedTask( | 517 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 516 FROM_HERE, | 518 FROM_HERE, base::Bind(&NaClBrowser::PersistValidationCache, |
| 517 base::Bind(&NaClBrowser::PersistValidationCache, | 519 weak_factory_.GetWeakPtr()), |
| 518 weak_factory_.GetWeakPtr()), | 520 base::TimeDelta::FromMilliseconds(kValidationCacheCoalescingTimeMS)); |
| 519 base::TimeDelta::FromMilliseconds(kValidationCacheCoalescingTimeMS)); | |
| 520 validation_cache_is_modified_ = true; | 521 validation_cache_is_modified_ = true; |
| 521 } | 522 } |
| 522 } | 523 } |
| 523 | 524 |
| 524 void NaClBrowser::PersistValidationCache() { | 525 void NaClBrowser::PersistValidationCache() { |
| 525 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 526 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 526 // validation_cache_is_modified_ may be false if the cache was cleared while | 527 // validation_cache_is_modified_ may be false if the cache was cleared while |
| 527 // this delayed task was pending. | 528 // this delayed task was pending. |
| 528 // validation_cache_file_path_ may be empty if something went wrong during | 529 // validation_cache_file_path_ may be empty if something went wrong during |
| 529 // initialization. | 530 // initialization. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 560 bool NaClBrowser::IsThrottled() { | 561 bool NaClBrowser::IsThrottled() { |
| 561 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 562 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 562 if (crash_times_.size() != kMaxCrashesPerInterval) { | 563 if (crash_times_.size() != kMaxCrashesPerInterval) { |
| 563 return false; | 564 return false; |
| 564 } | 565 } |
| 565 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); | 566 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); |
| 566 return delta.InSeconds() <= kCrashesIntervalInSeconds; | 567 return delta.InSeconds() <= kCrashesIntervalInSeconds; |
| 567 } | 568 } |
| 568 | 569 |
| 569 } // namespace nacl | 570 } // namespace nacl |
| OLD | NEW |