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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/file_downloader.cc

Issue 14750007: NaCl: enable meta-based validation for shared libraries. (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 "native_client/src/trusted/plugin/file_downloader.h" 5 #include "native_client/src/trusted/plugin/file_downloader.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string.h>
8 #include <string> 9 #include <string>
9 10
10 #include "native_client/src/include/portability_io.h" 11 #include "native_client/src/include/portability_io.h"
11 #include "native_client/src/shared/platform/nacl_check.h" 12 #include "native_client/src/shared/platform/nacl_check.h"
12 #include "native_client/src/shared/platform/nacl_time.h" 13 #include "native_client/src/shared/platform/nacl_time.h"
13 #include "native_client/src/trusted/plugin/callback_source.h" 14 #include "native_client/src/trusted/plugin/callback_source.h"
14 #include "native_client/src/trusted/plugin/plugin.h" 15 #include "native_client/src/trusted/plugin/plugin.h"
15 #include "native_client/src/trusted/plugin/utility.h" 16 #include "native_client/src/trusted/plugin/utility.h"
16 #include "ppapi/c/pp_errors.h" 17 #include "ppapi/c/pp_errors.h"
17 #include "ppapi/c/ppb_file_io.h" 18 #include "ppapi/c/ppb_file_io.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // invocation of the user callback. The user code will not be reentered. 139 // invocation of the user callback. The user code will not be reentered.
139 pp::CompletionCallback onload_callback = 140 pp::CompletionCallback onload_callback =
140 callback_factory_.NewCallback(start_notify); 141 callback_factory_.NewCallback(start_notify);
141 int32_t pp_error = url_loader_.Open(url_request, onload_callback); 142 int32_t pp_error = url_loader_.Open(url_request, onload_callback);
142 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=%"NACL_PRId32")\n", pp_error)); 143 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=%"NACL_PRId32")\n", pp_error));
143 CHECK(pp_error == PP_OK_COMPLETIONPENDING); 144 CHECK(pp_error == PP_OK_COMPLETIONPENDING);
144 return true; 145 return true;
145 } 146 }
146 147
147 void FileDownloader::OpenFast(const nacl::string& url, 148 void FileDownloader::OpenFast(const nacl::string& url,
148 PP_FileHandle file_handle) { 149 PP_FileHandle file_handle,
150 uint64_t nonce) {
149 PLUGIN_PRINTF(("FileDownloader::OpenFast (url=%s)\n", url.c_str())); 151 PLUGIN_PRINTF(("FileDownloader::OpenFast (url=%s)\n", url.c_str()));
150 CHECK(instance_ != NULL); 152 CHECK(instance_ != NULL);
151 open_time_ = NaClGetTimeOfDayMicroseconds(); 153 open_time_ = NaClGetTimeOfDayMicroseconds();
152 status_code_ = NACL_HTTP_STATUS_OK; 154 status_code_ = NACL_HTTP_STATUS_OK;
153 url_to_open_ = url; 155 url_to_open_ = url;
154 url_ = url; 156 url_ = url;
155 mode_ = DOWNLOAD_NONE; 157 mode_ = DOWNLOAD_NONE;
156 file_handle_ = file_handle; 158 file_handle_ = file_handle;
159 nonce_ = nonce;
157 } 160 }
158 161
159 int32_t FileDownloader::GetPOSIXFileDescriptor() { 162 struct NaClFileInfo FileDownloader::GetFileInfo() {
163 struct NaClFileInfo info;
164 memset(&info, 0, sizeof(info));
165 info.desc = -1;
160 int32_t file_desc = NACL_NO_FILE_DESC; 166 int32_t file_desc = NACL_NO_FILE_DESC;
161 if (not_streaming() && file_handle_ != PP_kInvalidFileHandle) { 167 if (not_streaming() && file_handle_ != PP_kInvalidFileHandle) {
162 #if NACL_WINDOWS 168 #if NACL_WINDOWS
163 // On Windows, valid handles are 32 bit unsigned integers so this is safe. 169 // On Windows, valid handles are 32 bit unsigned integers so this is safe.
164 file_desc = reinterpret_cast<uintptr_t>(file_handle_); 170 file_desc = reinterpret_cast<uintptr_t>(file_handle_);
165 #else 171 #else
166 file_desc = file_handle_; 172 file_desc = file_handle_;
167 #endif 173 #endif
174 info.nonce = nonce_;
168 } else { 175 } else {
169 if (!streaming_to_file()) { 176 if (!streaming_to_file()) {
170 return NACL_NO_FILE_DESC; 177 return info;
dmichael (off chromium) 2013/05/15 18:37:53 I find these error returns less obvious now. Not s
Nick Bray (chromium) 2013/05/16 16:38:17 The file info structure is defined in the NaCl rep
dmichael (off chromium) 2013/05/16 17:08:35 How about a simple little helper function in the u
Nick Bray (chromium) 2013/05/16 17:44:15 Didn't think of that one. Good idea. Done.
171 } 178 }
172 // Use the trusted interface to get the file descriptor. 179 // Use the trusted interface to get the file descriptor.
173 if (file_io_trusted_interface_ == NULL) { 180 if (file_io_trusted_interface_ == NULL) {
174 return NACL_NO_FILE_DESC; 181 return info;
175 } 182 }
176 file_desc = file_io_trusted_interface_->GetOSFileDescriptor( 183 file_desc = file_io_trusted_interface_->GetOSFileDescriptor(
177 file_reader_.pp_resource()); 184 file_reader_.pp_resource());
178 } 185 }
179 186
180 #if NACL_WINDOWS 187 #if NACL_WINDOWS
181 // Convert the Windows HANDLE from Pepper to a POSIX file descriptor. 188 // Convert the Windows HANDLE from Pepper to a POSIX file descriptor.
182 int32_t posix_desc = _open_osfhandle(file_desc, _O_RDWR | _O_BINARY); 189 int32_t posix_desc = _open_osfhandle(file_desc, _O_RDWR | _O_BINARY);
183 if (posix_desc == -1) { 190 if (posix_desc == -1) {
184 // Close the Windows HANDLE if it can't be converted. 191 // Close the Windows HANDLE if it can't be converted.
185 CloseHandle(reinterpret_cast<HANDLE>(file_desc)); 192 CloseHandle(reinterpret_cast<HANDLE>(file_desc));
186 return NACL_NO_FILE_DESC; 193 return info;
187 } 194 }
188 file_desc = posix_desc; 195 file_desc = posix_desc;
189 #endif 196 #endif
190 197
191 return file_desc; 198 info.desc = file_desc;
199 return info;
192 } 200 }
193 201
194 int64_t FileDownloader::TimeSinceOpenMilliseconds() const { 202 int64_t FileDownloader::TimeSinceOpenMilliseconds() const {
195 int64_t now = NaClGetTimeOfDayMicroseconds(); 203 int64_t now = NaClGetTimeOfDayMicroseconds();
196 // If Open() wasn't called or we somehow return an earlier time now, just 204 // If Open() wasn't called or we somehow return an earlier time now, just
197 // return the 0 rather than worse nonsense values. 205 // return the 0 rather than worse nonsense values.
198 if (open_time_ < 0 || now < open_time_) 206 if (open_time_ < 0 || now < open_time_)
199 return 0; 207 return 0;
200 return (now - open_time_) / NACL_MICROS_PER_MILLI; 208 return (now - open_time_) / NACL_MICROS_PER_MILLI;
201 } 209 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 406
399 bool FileDownloader::streaming_to_user() const { 407 bool FileDownloader::streaming_to_user() const {
400 return mode_ == DOWNLOAD_STREAM; 408 return mode_ == DOWNLOAD_STREAM;
401 } 409 }
402 410
403 bool FileDownloader::not_streaming() const { 411 bool FileDownloader::not_streaming() const {
404 return mode_ == DOWNLOAD_NONE; 412 return mode_ == DOWNLOAD_NONE;
405 } 413 }
406 414
407 } // namespace plugin 415 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698