Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 
| 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 
| 7 | 7 | 
| 8 #include <deque> | 8 #include <deque> | 
| 9 | 9 | 
| 10 #include "native_client/src/include/nacl_macros.h" | 10 #include "native_client/src/include/nacl_macros.h" | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 typedef enum { | 34 typedef enum { | 
| 35 SCHEME_CHROME_EXTENSION, | 35 SCHEME_CHROME_EXTENSION, | 
| 36 SCHEME_DATA, | 36 SCHEME_DATA, | 
| 37 SCHEME_OTHER | 37 SCHEME_OTHER | 
| 38 } UrlSchemeType; | 38 } UrlSchemeType; | 
| 39 | 39 | 
| 40 typedef std::vector<char>* FileStreamData; | 40 typedef std::vector<char>* FileStreamData; | 
| 41 typedef CallbackSource<FileStreamData> StreamCallbackSource; | 41 typedef CallbackSource<FileStreamData> StreamCallbackSource; | 
| 42 typedef pp::CompletionCallbackWithOutput<FileStreamData> StreamCallback; | 42 typedef pp::CompletionCallbackWithOutput<FileStreamData> StreamCallback; | 
| 43 | 43 | 
| 44 // RAII-style wrapper class | |
| 45 class NaClFileInfoAutoCloser { | |
| 46 public: | |
| 47 NaClFileInfoAutoCloser(); | |
| 48 | |
| 49 NaClFileInfoAutoCloser(NaClFileInfo pass_ownership); | |
| 
 
dmichael (off chromium)
2014/01/29 18:22:28
nit: explicit
 
bsy
2014/01/29 20:51:28
Done.  Thanks, this was careless of me.
 
 | |
| 50 | |
| 51 ~NaClFileInfoAutoCloser() { | |
| 52 FreeResources(); | |
| 53 } | |
| 54 | |
| 55 void FreeResources(); // Frees owned resources | |
| 
 
dmichael (off chromium)
2014/01/29 18:22:28
nit: comment should go above the method. Ditto rel
 
bsy
2014/01/29 20:51:28
Done.
 
 | |
| 56 | |
| 57 void set(NaClFileInfo pass_ownership); | |
| 58 | |
| 59 // Return NaClFileInfo for temporary use, retaining ownership. | |
| 60 NaClFileInfo get() { return info_; } | |
| 61 | |
| 62 // Returns POSIX descriptor for temporary use, retaining ownership. | |
| 63 int get_desc() { return info_.desc; } | |
| 64 | |
| 65 NaClFileInfo release(); // Returns ownership to caller | |
| 
 
dmichael (off chromium)
2014/01/29 18:22:28
nit: Probably should be capitalized, since it's se
 
bsy
2014/01/29 20:51:28
Done.
 
 | |
| 66 | |
| 67 private: | |
| 68 NACL_DISALLOW_COPY_AND_ASSIGN(NaClFileInfoAutoCloser); | |
| 69 | |
| 70 NaClFileInfo info_; | |
| 71 }; | |
| 72 | |
| 44 // A class that wraps PPAPI URLLoader and FileIO functionality for downloading | 73 // A class that wraps PPAPI URLLoader and FileIO functionality for downloading | 
| 45 // the url into a file and providing an open file descriptor. | 74 // the url into a file and providing an open file descriptor. | 
| 46 class FileDownloader { | 75 class FileDownloader { | 
| 47 public: | 76 public: | 
| 48 // Ctor initializes |instance_| to NULL, be sure to call Initialize() before | 77 // Ctor initializes |instance_| to NULL, be sure to call Initialize() before | 
| 49 // calling Open(), or Open() will fail. | 78 // calling Open(), or Open() will fail. | 
| 50 FileDownloader() | 79 FileDownloader() | 
| 51 : instance_(NULL), | 80 : instance_(NULL), | 
| 52 file_open_notify_callback_(pp::BlockUntilComplete()), | 81 file_open_notify_callback_(pp::BlockUntilComplete()), | 
| 53 stream_finish_callback_(pp::BlockUntilComplete()), | 82 stream_finish_callback_(pp::BlockUntilComplete()), | 
| 54 file_handle_(PP_kInvalidFileHandle), | |
| 55 file_io_private_interface_(NULL), | 83 file_io_private_interface_(NULL), | 
| 56 url_loader_trusted_interface_(NULL), | 84 url_loader_trusted_interface_(NULL), | 
| 57 open_time_(-1), | 85 open_time_(-1), | 
| 58 mode_(DOWNLOAD_NONE), | 86 mode_(DOWNLOAD_NONE), | 
| 59 open_and_stream_(true), | 87 open_and_stream_(true), | 
| 60 url_scheme_(SCHEME_OTHER), | 88 url_scheme_(SCHEME_OTHER), | 
| 61 data_stream_callback_source_(NULL) {} | 89 data_stream_callback_source_(NULL) {} | 
| 62 ~FileDownloader() {} | 90 ~FileDownloader() {} | 
| 63 | 91 | 
| 64 // Initialize() can only be called once during the lifetime of this instance. | 92 // Initialize() can only be called once during the lifetime of this instance. | 
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 void GotFileHandleNotify(int32_t pp_error, PP_FileHandle handle); | 206 void GotFileHandleNotify(int32_t pp_error, PP_FileHandle handle); | 
| 179 | 207 | 
| 180 Plugin* instance_; | 208 Plugin* instance_; | 
| 181 nacl::string url_to_open_; | 209 nacl::string url_to_open_; | 
| 182 nacl::string url_; | 210 nacl::string url_; | 
| 183 nacl::string extra_request_headers_; | 211 nacl::string extra_request_headers_; | 
| 184 pp::URLResponseInfo url_response_; | 212 pp::URLResponseInfo url_response_; | 
| 185 pp::CompletionCallback file_open_notify_callback_; | 213 pp::CompletionCallback file_open_notify_callback_; | 
| 186 pp::CompletionCallback stream_finish_callback_; | 214 pp::CompletionCallback stream_finish_callback_; | 
| 187 pp::FileIO file_reader_; | 215 pp::FileIO file_reader_; | 
| 188 PP_FileHandle file_handle_; | |
| 189 struct NaClFileToken file_token_; | |
| 190 const PPB_FileIO_Private* file_io_private_interface_; | 216 const PPB_FileIO_Private* file_io_private_interface_; | 
| 191 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; | 217 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; | 
| 192 pp::URLLoader url_loader_; | 218 pp::URLLoader url_loader_; | 
| 193 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; | 219 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; | 
| 194 int64_t open_time_; | 220 int64_t open_time_; | 
| 195 int32_t status_code_; | 221 int32_t status_code_; | 
| 196 DownloadMode mode_; | 222 DownloadMode mode_; | 
| 197 bool open_and_stream_; | 223 bool open_and_stream_; | 
| 198 static const uint32_t kTempBufferSize = 2048; | 224 static const uint32_t kTempBufferSize = 2048; | 
| 199 std::vector<char> temp_buffer_; | 225 std::vector<char> temp_buffer_; | 
| 200 std::deque<char> buffer_; | 226 std::deque<char> buffer_; | 
| 201 UrlSchemeType url_scheme_; | 227 UrlSchemeType url_scheme_; | 
| 202 StreamCallbackSource* data_stream_callback_source_; | 228 StreamCallbackSource* data_stream_callback_source_; | 
| 203 NaClFileInfo cached_file_info_; | 229 NaClFileInfoAutoCloser file_info_; | 
| 204 }; | 230 }; | 
| 205 } // namespace plugin; | 231 } // namespace plugin; | 
| 206 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 232 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 
| OLD | NEW |