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

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

Issue 165663002: Remove some PlatformFile uses from NaCl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add empty line Created 6 years, 10 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
« 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 "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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 113
114 // Crash throttling parameters. 114 // Crash throttling parameters.
115 const size_t kMaxCrashesPerInterval = 3; 115 const size_t kMaxCrashesPerInterval = 3;
116 const int64 kCrashesIntervalInSeconds = 120; 116 const int64 kCrashesIntervalInSeconds = 120;
117 117
118 } // namespace 118 } // namespace
119 119
120 namespace nacl { 120 namespace nacl {
121 121
122 base::PlatformFile OpenNaClExecutableImpl(const base::FilePath& file_path) { 122 base::File OpenNaClExecutableImpl(const base::FilePath& file_path) {
123 // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to 123 // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to
124 // memory map the executable. 124 // memory map the executable.
125 // IMPORTANT: This file descriptor must not have write access - that could 125 // IMPORTANT: This file descriptor must not have write access - that could
126 // allow a NaCl inner sandbox escape. 126 // allow a NaCl inner sandbox escape.
127 base::PlatformFile file; 127 base::File file(file_path,
128 base::PlatformFileError error_code; 128 (base::File::FLAG_OPEN |
129 file = base::CreatePlatformFile( 129 base::File::FLAG_READ |
130 file_path, 130 base::File::FLAG_EXECUTE)); // Windows only flag.
131 (base::PLATFORM_FILE_OPEN | 131 if (!file.IsValid())
132 base::PLATFORM_FILE_READ | 132 return file.Pass();
133 base::PLATFORM_FILE_EXECUTE), // Windows only flag.
134 NULL,
135 &error_code);
136 if (error_code != base::PLATFORM_FILE_OK)
137 return base::kInvalidPlatformFileValue;
138 133
139 // Check that the file does not reference a directory. Returning a descriptor 134 // Check that the file does not reference a directory. Returning a descriptor
140 // to an extension directory could allow an outer sandbox escape. openat(...) 135 // to an extension directory could allow an outer sandbox escape. openat(...)
141 // could be used to traverse into the file system. 136 // could be used to traverse into the file system.
142 base::PlatformFileInfo file_info; 137 base::File::Info file_info;
143 if (!base::GetPlatformFileInfo(file, &file_info) || file_info.is_directory) { 138 if (!file.GetInfo(&file_info) || file_info.is_directory)
144 base::ClosePlatformFile(file); 139 return base::File();
145 return base::kInvalidPlatformFileValue; 140
146 } 141 return file.Pass();
147 return file;
148 } 142 }
149 143
150 NaClBrowser::NaClBrowser() 144 NaClBrowser::NaClBrowser()
151 : weak_factory_(this), 145 : weak_factory_(this),
152 irt_platform_file_(base::kInvalidPlatformFileValue), 146 irt_platform_file_(base::kInvalidPlatformFileValue),
153 irt_filepath_(), 147 irt_filepath_(),
154 irt_state_(NaClResourceUninitialized), 148 irt_state_(NaClResourceUninitialized),
155 validation_cache_file_path_(), 149 validation_cache_file_path_(),
156 validation_cache_is_enabled_( 150 validation_cache_is_enabled_(
157 CheckEnvVar("NACL_VALIDATION_CACHE", 151 CheckEnvVar("NACL_VALIDATION_CACHE",
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 bool NaClBrowser::IsThrottled() { 552 bool NaClBrowser::IsThrottled() {
559 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 553 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
560 if (crash_times_.size() != kMaxCrashesPerInterval) { 554 if (crash_times_.size() != kMaxCrashesPerInterval) {
561 return false; 555 return false;
562 } 556 }
563 base::TimeDelta delta = base::Time::Now() - crash_times_.front(); 557 base::TimeDelta delta = base::Time::Now() - crash_times_.front();
564 return delta.InSeconds() <= kCrashesIntervalInSeconds; 558 return delta.InSeconds() <= kCrashesIntervalInSeconds;
565 } 559 }
566 560
567 } // namespace nacl 561 } // 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