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 explicit NaClFileInfoAutoCloser(NaClFileInfo pass_ownership); | |
| 
 
bbudge
2014/01/29 21:43:31
It would be nice if pass_ownership's desc field wa
 
bsy
2014/01/30 00:29:40
I'll set the whole thing to NoFileInfo(), since th
 
 | |
| 50 | |
| 51 ~NaClFileInfoAutoCloser() { | |
| 52 FreeResources(); | |
| 53 } | |
| 54 | |
| 55 // Frees owned resources | |
| 56 void FreeResources(); | |
| 57 | |
| 58 void TakeOwnership(NaClFileInfo pass_ownership); | |
| 59 | |
| 60 // Return NaClFileInfo for temporary use, retaining ownership. | |
| 61 NaClFileInfo get() { return info_; } | |
| 
 
bbudge
2014/01/29 21:43:31
Could this return a const & instead?
 
bsy
2014/01/30 00:29:40
Done.
 
 | |
| 62 | |
| 63 // Returns POSIX descriptor for temporary use, retaining ownership. | |
| 64 int get_desc() { return info_.desc; } | |
| 65 | |
| 66 // Returns ownership to caller | |
| 67 NaClFileInfo Release(); | |
| 68 | |
| 69 private: | |
| 70 NACL_DISALLOW_COPY_AND_ASSIGN(NaClFileInfoAutoCloser); | |
| 71 | |
| 72 NaClFileInfo info_; | |
| 73 }; | |
| 74 | |
| 44 // A class that wraps PPAPI URLLoader and FileIO functionality for downloading | 75 // A class that wraps PPAPI URLLoader and FileIO functionality for downloading | 
| 45 // the url into a file and providing an open file descriptor. | 76 // the url into a file and providing an open file descriptor. | 
| 46 class FileDownloader { | 77 class FileDownloader { | 
| 47 public: | 78 public: | 
| 48 // Ctor initializes |instance_| to NULL, be sure to call Initialize() before | 79 // Ctor initializes |instance_| to NULL, be sure to call Initialize() before | 
| 49 // calling Open(), or Open() will fail. | 80 // calling Open(), or Open() will fail. | 
| 50 FileDownloader() | 81 FileDownloader() | 
| 51 : instance_(NULL), | 82 : instance_(NULL), | 
| 52 file_open_notify_callback_(pp::BlockUntilComplete()), | 83 file_open_notify_callback_(pp::BlockUntilComplete()), | 
| 53 stream_finish_callback_(pp::BlockUntilComplete()), | 84 stream_finish_callback_(pp::BlockUntilComplete()), | 
| 54 file_handle_(PP_kInvalidFileHandle), | |
| 55 file_io_private_interface_(NULL), | 85 file_io_private_interface_(NULL), | 
| 56 url_loader_trusted_interface_(NULL), | 86 url_loader_trusted_interface_(NULL), | 
| 57 open_time_(-1), | 87 open_time_(-1), | 
| 58 mode_(DOWNLOAD_NONE), | 88 mode_(DOWNLOAD_NONE), | 
| 59 open_and_stream_(true), | 89 open_and_stream_(true), | 
| 60 url_scheme_(SCHEME_OTHER), | 90 url_scheme_(SCHEME_OTHER), | 
| 61 data_stream_callback_source_(NULL) {} | 91 data_stream_callback_source_(NULL) {} | 
| 62 ~FileDownloader() {} | 92 ~FileDownloader() {} | 
| 63 | 93 | 
| 64 // Initialize() can only be called once during the lifetime of this instance. | 94 // 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); | 208 void GotFileHandleNotify(int32_t pp_error, PP_FileHandle handle); | 
| 179 | 209 | 
| 180 Plugin* instance_; | 210 Plugin* instance_; | 
| 181 nacl::string url_to_open_; | 211 nacl::string url_to_open_; | 
| 182 nacl::string url_; | 212 nacl::string url_; | 
| 183 nacl::string extra_request_headers_; | 213 nacl::string extra_request_headers_; | 
| 184 pp::URLResponseInfo url_response_; | 214 pp::URLResponseInfo url_response_; | 
| 185 pp::CompletionCallback file_open_notify_callback_; | 215 pp::CompletionCallback file_open_notify_callback_; | 
| 186 pp::CompletionCallback stream_finish_callback_; | 216 pp::CompletionCallback stream_finish_callback_; | 
| 187 pp::FileIO file_reader_; | 217 pp::FileIO file_reader_; | 
| 188 PP_FileHandle file_handle_; | |
| 189 struct NaClFileToken file_token_; | |
| 190 const PPB_FileIO_Private* file_io_private_interface_; | 218 const PPB_FileIO_Private* file_io_private_interface_; | 
| 191 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; | 219 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; | 
| 192 pp::URLLoader url_loader_; | 220 pp::URLLoader url_loader_; | 
| 193 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; | 221 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; | 
| 194 int64_t open_time_; | 222 int64_t open_time_; | 
| 195 int32_t status_code_; | 223 int32_t status_code_; | 
| 196 DownloadMode mode_; | 224 DownloadMode mode_; | 
| 197 bool open_and_stream_; | 225 bool open_and_stream_; | 
| 198 static const uint32_t kTempBufferSize = 2048; | 226 static const uint32_t kTempBufferSize = 2048; | 
| 199 std::vector<char> temp_buffer_; | 227 std::vector<char> temp_buffer_; | 
| 200 std::deque<char> buffer_; | 228 std::deque<char> buffer_; | 
| 201 UrlSchemeType url_scheme_; | 229 UrlSchemeType url_scheme_; | 
| 202 StreamCallbackSource* data_stream_callback_source_; | 230 StreamCallbackSource* data_stream_callback_source_; | 
| 203 NaClFileInfo cached_file_info_; | 231 NaClFileInfoAutoCloser file_info_; | 
| 204 }; | 232 }; | 
| 205 } // namespace plugin; | 233 } // namespace plugin; | 
| 206 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 234 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 
| OLD | NEW |