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

Side by Side Diff: components/nacl/browser/nacl_browser.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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 | « components/nacl/browser/nacl_browser.h ('k') | components/nacl/browser/nacl_file_host.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 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 <stddef.h>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/files/file_proxy.h" 10 #include "base/files/file_proxy.h"
9 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
10 #include "base/location.h" 12 #include "base/location.h"
11 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
12 #include "base/path_service.h" 14 #include "base/path_service.h"
13 #include "base/pickle.h" 15 #include "base/pickle.h"
14 #include "base/rand_util.h" 16 #include "base/rand_util.h"
15 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
16 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 106 }
105 107
106 void LogCacheSet(nacl::NaClBrowser::ValidationCacheStatus status) { 108 void LogCacheSet(nacl::NaClBrowser::ValidationCacheStatus status) {
107 // Bucket zero is reserved for future use. 109 // Bucket zero is reserved for future use.
108 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status, 110 UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status,
109 nacl::NaClBrowser::CACHE_MAX); 111 nacl::NaClBrowser::CACHE_MAX);
110 } 112 }
111 113
112 // Crash throttling parameters. 114 // Crash throttling parameters.
113 const size_t kMaxCrashesPerInterval = 3; 115 const size_t kMaxCrashesPerInterval = 3;
114 const int64 kCrashesIntervalInSeconds = 120; 116 const int64_t kCrashesIntervalInSeconds = 120;
115 117
116 } // namespace 118 } // namespace
117 119
118 namespace nacl { 120 namespace nacl {
119 121
120 base::File OpenNaClReadExecImpl(const base::FilePath& file_path, 122 base::File OpenNaClReadExecImpl(const base::FilePath& file_path,
121 bool is_executable) { 123 bool is_executable) {
122 // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to 124 // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to
123 // memory map the executable. 125 // memory map the executable.
124 // IMPORTANT: This file descriptor must not have write access - that could 126 // IMPORTANT: This file descriptor must not have write access - that could
125 // allow a NaCl inner sandbox escape. 127 // allow a NaCl inner sandbox escape.
126 uint32 flags = base::File::FLAG_OPEN | base::File::FLAG_READ; 128 uint32_t flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
127 if (is_executable) 129 if (is_executable)
128 flags |= base::File::FLAG_EXECUTE; // Windows only flag. 130 flags |= base::File::FLAG_EXECUTE; // Windows only flag.
129 base::File file(file_path, flags); 131 base::File file(file_path, flags);
130 if (!file.IsValid()) 132 if (!file.IsValid())
131 return file.Pass(); 133 return file.Pass();
132 134
133 // Check that the file does not reference a directory. Returning a descriptor 135 // Check that the file does not reference a directory. Returning a descriptor
134 // to an extension directory could allow an outer sandbox escape. openat(...) 136 // to an extension directory could allow an outer sandbox escape. openat(...)
135 // could be used to traverse into the file system. 137 // could be used to traverse into the file system.
136 base::File::Info file_info; 138 base::File::Info file_info;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 void NaClBrowser::WaitForResources(const base::Closure& reply) { 399 void NaClBrowser::WaitForResources(const base::Closure& reply) {
398 waiting_.push_back(reply); 400 waiting_.push_back(reply);
399 EnsureAllResourcesAvailable(); 401 EnsureAllResourcesAvailable();
400 CheckWaiting(); 402 CheckWaiting();
401 } 403 }
402 404
403 const base::FilePath& NaClBrowser::GetIrtFilePath() { 405 const base::FilePath& NaClBrowser::GetIrtFilePath() {
404 return irt_filepath_; 406 return irt_filepath_;
405 } 407 }
406 408
407 void NaClBrowser::PutFilePath(const base::FilePath& path, uint64* file_token_lo, 409 void NaClBrowser::PutFilePath(const base::FilePath& path,
408 uint64* file_token_hi) { 410 uint64_t* file_token_lo,
411 uint64_t* file_token_hi) {
409 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 412 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
410 while (true) { 413 while (true) {
411 uint64 file_token[2] = {base::RandUint64(), base::RandUint64()}; 414 uint64_t file_token[2] = {base::RandUint64(), base::RandUint64()};
412 // A zero file_token indicates there is no file_token, if we get zero, ask 415 // A zero file_token indicates there is no file_token, if we get zero, ask
413 // for another number. 416 // for another number.
414 if (file_token[0] != 0 || file_token[1] != 0) { 417 if (file_token[0] != 0 || file_token[1] != 0) {
415 // If the file_token is in use, ask for another number. 418 // If the file_token is in use, ask for another number.
416 std::string key(reinterpret_cast<char*>(file_token), sizeof(file_token)); 419 std::string key(reinterpret_cast<char*>(file_token), sizeof(file_token));
417 PathCacheType::iterator iter = path_cache_.Peek(key); 420 PathCacheType::iterator iter = path_cache_.Peek(key);
418 if (iter == path_cache_.end()) { 421 if (iter == path_cache_.end()) {
419 path_cache_.Put(key, path); 422 path_cache_.Put(key, path);
420 *file_token_lo = file_token[0]; 423 *file_token_lo = file_token[0];
421 *file_token_hi = file_token[1]; 424 *file_token_hi = file_token[1];
422 break; 425 break;
423 } 426 }
424 } 427 }
425 } 428 }
426 } 429 }
427 430
428 bool NaClBrowser::GetFilePath(uint64 file_token_lo, uint64 file_token_hi, 431 bool NaClBrowser::GetFilePath(uint64_t file_token_lo,
432 uint64_t file_token_hi,
429 base::FilePath* path) { 433 base::FilePath* path) {
430 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 434 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
431 uint64 file_token[2] = {file_token_lo, file_token_hi}; 435 uint64_t file_token[2] = {file_token_lo, file_token_hi};
432 std::string key(reinterpret_cast<char*>(file_token), sizeof(file_token)); 436 std::string key(reinterpret_cast<char*>(file_token), sizeof(file_token));
433 PathCacheType::iterator iter = path_cache_.Peek(key); 437 PathCacheType::iterator iter = path_cache_.Peek(key);
434 if (iter == path_cache_.end()) { 438 if (iter == path_cache_.end()) {
435 *path = base::FilePath(FILE_PATH_LITERAL("")); 439 *path = base::FilePath(FILE_PATH_LITERAL(""));
436 return false; 440 return false;
437 } 441 }
438 *path = iter->second; 442 *path = iter->second;
439 path_cache_.Erase(iter); 443 path_cache_.Erase(iter);
440 return true; 444 return true;
441 } 445 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 bool NaClBrowser::IsThrottled() { 565 bool NaClBrowser::IsThrottled() {
562 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 566 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
563 if (crash_times_.size() != kMaxCrashesPerInterval) { 567 if (crash_times_.size() != kMaxCrashesPerInterval) {
564 return false; 568 return false;
565 } 569 }
566 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); 570 base::TimeDelta delta = base::Time::Now() - crash_times_.front();
567 return delta.InSeconds() <= kCrashesIntervalInSeconds; 571 return delta.InSeconds() <= kCrashesIntervalInSeconds;
568 } 572 }
569 573
570 } // namespace nacl 574 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/browser/nacl_browser.h ('k') | components/nacl/browser/nacl_file_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698