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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // Ctor initializes |instance_| to NULL, be sure to call Initialize() before | 79 // Ctor initializes |instance_| to NULL, be sure to call Initialize() before |
80 // calling Open(), or Open() will fail. | 80 // calling Open(), or Open() will fail. |
81 FileDownloader() | 81 FileDownloader() |
82 : instance_(NULL), | 82 : instance_(NULL), |
83 file_open_notify_callback_(pp::BlockUntilComplete()), | 83 file_open_notify_callback_(pp::BlockUntilComplete()), |
84 stream_finish_callback_(pp::BlockUntilComplete()), | 84 stream_finish_callback_(pp::BlockUntilComplete()), |
85 file_io_private_interface_(NULL), | 85 file_io_private_interface_(NULL), |
86 url_loader_trusted_interface_(NULL), | 86 url_loader_trusted_interface_(NULL), |
87 open_time_(-1), | 87 open_time_(-1), |
88 mode_(DOWNLOAD_NONE), | 88 mode_(DOWNLOAD_NONE), |
89 open_and_stream_(true), | |
90 url_scheme_(SCHEME_OTHER), | 89 url_scheme_(SCHEME_OTHER), |
91 data_stream_callback_source_(NULL) {} | 90 data_stream_callback_source_(NULL) {} |
92 ~FileDownloader() {} | 91 ~FileDownloader() {} |
93 | 92 |
94 // Initialize() can only be called once during the lifetime of this instance. | 93 // Initialize() can only be called once during the lifetime of this instance. |
95 void Initialize(Plugin* instance); | 94 void Initialize(Plugin* instance); |
96 | 95 |
97 // Issues a GET on |url| to start downloading the response into a file, | 96 // Issues a GET on |url| to start downloading the response into a file, |
98 // and finish streaming it. |callback| will be run after streaming is | 97 // and finish streaming it. |callback| will be run after streaming is |
99 // done or if an error prevents streaming from completing. | 98 // done or if an error prevents streaming from completing. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // in which case |total_bytes_to_be_received| will be set to -1. | 165 // in which case |total_bytes_to_be_received| will be set to -1. |
167 bool GetDownloadProgress(int64_t* bytes_received, | 166 bool GetDownloadProgress(int64_t* bytes_received, |
168 int64_t* total_bytes_to_be_received) const; | 167 int64_t* total_bytes_to_be_received) const; |
169 | 168 |
170 // Returns the buffer used for DOWNLOAD_TO_BUFFER mode. | 169 // Returns the buffer used for DOWNLOAD_TO_BUFFER mode. |
171 const std::deque<char>& buffer() const { return buffer_; } | 170 const std::deque<char>& buffer() const { return buffer_; } |
172 | 171 |
173 bool streaming_to_file() const; | 172 bool streaming_to_file() const; |
174 bool streaming_to_buffer() const; | 173 bool streaming_to_buffer() const; |
175 bool streaming_to_user() const; | 174 bool streaming_to_user() const; |
176 bool not_streaming() const; | |
177 | 175 |
178 int status_code() const { return status_code_; } | 176 int status_code() const { return status_code_; } |
179 nacl::string GetResponseHeaders() const; | 177 nacl::string GetResponseHeaders() const; |
180 | 178 |
181 void set_request_headers(const nacl::string& extra_request_headers) { | 179 void set_request_headers(const nacl::string& extra_request_headers) { |
182 extra_request_headers_ = extra_request_headers; | 180 extra_request_headers_ = extra_request_headers; |
183 } | 181 } |
184 | 182 |
185 | 183 |
186 private: | 184 private: |
(...skipping 28 matching lines...) Expand all Loading... |
215 pp::CompletionCallback file_open_notify_callback_; | 213 pp::CompletionCallback file_open_notify_callback_; |
216 pp::CompletionCallback stream_finish_callback_; | 214 pp::CompletionCallback stream_finish_callback_; |
217 pp::FileIO file_reader_; | 215 pp::FileIO file_reader_; |
218 const PPB_FileIO_Private* file_io_private_interface_; | 216 const PPB_FileIO_Private* file_io_private_interface_; |
219 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; | 217 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; |
220 pp::URLLoader url_loader_; | 218 pp::URLLoader url_loader_; |
221 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; | 219 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; |
222 int64_t open_time_; | 220 int64_t open_time_; |
223 int32_t status_code_; | 221 int32_t status_code_; |
224 DownloadMode mode_; | 222 DownloadMode mode_; |
225 bool open_and_stream_; | |
226 static const uint32_t kTempBufferSize = 2048; | 223 static const uint32_t kTempBufferSize = 2048; |
227 std::vector<char> temp_buffer_; | 224 std::vector<char> temp_buffer_; |
228 std::deque<char> buffer_; | 225 std::deque<char> buffer_; |
229 UrlSchemeType url_scheme_; | 226 UrlSchemeType url_scheme_; |
230 StreamCallbackSource* data_stream_callback_source_; | 227 StreamCallbackSource* data_stream_callback_source_; |
231 NaClFileInfoAutoCloser file_info_; | 228 NaClFileInfoAutoCloser file_info_; |
232 }; | 229 }; |
233 } // namespace plugin; | 230 } // namespace plugin; |
234 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 231 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ |
OLD | NEW |