| 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" |
| 11 #include "native_client/src/include/nacl_string.h" | 11 #include "native_client/src/include/nacl_string.h" |
| 12 #include "native_client/src/trusted/plugin/callback_source.h" | 12 #include "native_client/src/trusted/plugin/callback_source.h" |
| 13 #include "native_client/src/trusted/reverse_service/nacl_file_info.h" |
| 13 #include "ppapi/c/private/pp_file_handle.h" | 14 #include "ppapi/c/private/pp_file_handle.h" |
| 14 #include "ppapi/c/trusted/ppb_file_io_trusted.h" | 15 #include "ppapi/c/trusted/ppb_file_io_trusted.h" |
| 15 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" | 16 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
| 16 #include "ppapi/cpp/file_io.h" | 17 #include "ppapi/cpp/file_io.h" |
| 17 #include "ppapi/cpp/url_loader.h" | 18 #include "ppapi/cpp/url_loader.h" |
| 18 #include "ppapi/cpp/instance.h" | 19 #include "ppapi/cpp/instance.h" |
| 19 #include "ppapi/utility/completion_callback_factory.h" | 20 #include "ppapi/utility/completion_callback_factory.h" |
| 20 | 21 |
| 21 namespace plugin { | 22 namespace plugin { |
| 22 | 23 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 79 |
| 79 // Same as Open, but used for streaming the file data directly to the | 80 // Same as Open, but used for streaming the file data directly to the |
| 80 // caller without buffering it. The callbacks provided by | 81 // caller without buffering it. The callbacks provided by |
| 81 // |stream_callback_source| are expected to copy the data before returning. | 82 // |stream_callback_source| are expected to copy the data before returning. |
| 82 // |callback| will still be called when the stream is finished. | 83 // |callback| will still be called when the stream is finished. |
| 83 bool OpenStream(const nacl::string& url, | 84 bool OpenStream(const nacl::string& url, |
| 84 const pp::CompletionCallback& callback, | 85 const pp::CompletionCallback& callback, |
| 85 StreamCallbackSource* stream_callback_source); | 86 StreamCallbackSource* stream_callback_source); |
| 86 | 87 |
| 87 // Bypasses downloading and takes a handle to the open file. To get the fd, | 88 // Bypasses downloading and takes a handle to the open file. To get the fd, |
| 88 // call GetPOSIXFileDescriptor(). | 89 // call GetFileInfo(). |
| 89 void OpenFast(const nacl::string& url, PP_FileHandle file_handle); | 90 void OpenFast(const nacl::string& url, PP_FileHandle file_handle, |
| 91 uint64_t nonce); |
| 90 | 92 |
| 93 // Return a structure describing the file opened, including a file desc. |
| 91 // If downloading and opening succeeded, this returns a valid read-only | 94 // If downloading and opening succeeded, this returns a valid read-only |
| 92 // POSIX file descriptor. On failure, the return value is an invalid | 95 // POSIX file descriptor. On failure, the return value is an invalid |
| 93 // descriptor. The file descriptor is owned by this instance, so the | 96 // descriptor. The file descriptor is owned by this instance, so the |
| 94 // delegate does not have to close it. | 97 // delegate does not have to close it. |
| 95 int32_t GetPOSIXFileDescriptor(); | 98 struct NaClFileInfo GetFileInfo(); |
| 96 | 99 |
| 97 // Returns the time delta between the call to Open() and this function. | 100 // Returns the time delta between the call to Open() and this function. |
| 98 int64_t TimeSinceOpenMilliseconds() const; | 101 int64_t TimeSinceOpenMilliseconds() const; |
| 99 | 102 |
| 100 // The value of |url_| changes over the life of this instance. When the file | 103 // The value of |url_| changes over the life of this instance. When the file |
| 101 // is first opened, |url_| is a copy of the URL used to open the file, which | 104 // is first opened, |url_| is a copy of the URL used to open the file, which |
| 102 // can be a relative URL. Once the GET request has finished, and the contents | 105 // can be a relative URL. Once the GET request has finished, and the contents |
| 103 // of the file represented by |url_| are available, |url_| is the full URL | 106 // of the file represented by |url_| are available, |url_| is the full URL |
| 104 // including the scheme, host and full path. | 107 // including the scheme, host and full path. |
| 105 const nacl::string& url() const { return url_; } | 108 const nacl::string& url() const { return url_; } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void URLBufferStartNotify(int32_t pp_error); | 156 void URLBufferStartNotify(int32_t pp_error); |
| 154 void URLReadBodyNotify(int32_t pp_error); | 157 void URLReadBodyNotify(int32_t pp_error); |
| 155 void FileOpenNotify(int32_t pp_error); | 158 void FileOpenNotify(int32_t pp_error); |
| 156 | 159 |
| 157 Plugin* instance_; | 160 Plugin* instance_; |
| 158 nacl::string url_to_open_; | 161 nacl::string url_to_open_; |
| 159 nacl::string url_; | 162 nacl::string url_; |
| 160 pp::CompletionCallback file_open_notify_callback_; | 163 pp::CompletionCallback file_open_notify_callback_; |
| 161 pp::FileIO file_reader_; | 164 pp::FileIO file_reader_; |
| 162 PP_FileHandle file_handle_; | 165 PP_FileHandle file_handle_; |
| 166 uint64_t nonce_; |
| 163 const PPB_FileIOTrusted* file_io_trusted_interface_; | 167 const PPB_FileIOTrusted* file_io_trusted_interface_; |
| 164 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; | 168 const PPB_URLLoaderTrusted* url_loader_trusted_interface_; |
| 165 pp::URLLoader url_loader_; | 169 pp::URLLoader url_loader_; |
| 166 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; | 170 pp::CompletionCallbackFactory<FileDownloader> callback_factory_; |
| 167 int64_t open_time_; | 171 int64_t open_time_; |
| 168 int32_t status_code_; | 172 int32_t status_code_; |
| 169 DownloadMode mode_; | 173 DownloadMode mode_; |
| 170 static const uint32_t kTempBufferSize = 2048; | 174 static const uint32_t kTempBufferSize = 2048; |
| 171 std::vector<char> temp_buffer_; | 175 std::vector<char> temp_buffer_; |
| 172 std::deque<char> buffer_; | 176 std::deque<char> buffer_; |
| 173 UrlSchemeType url_scheme_; | 177 UrlSchemeType url_scheme_; |
| 174 StreamCallbackSource* data_stream_callback_source_; | 178 StreamCallbackSource* data_stream_callback_source_; |
| 175 }; | 179 }; |
| 176 } // namespace plugin; | 180 } // namespace plugin; |
| 177 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ | 181 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ |
| OLD | NEW |