diff options
3 files changed, 21 insertions, 38 deletions
diff --git a/ppapi/native_client/src/trusted/plugin/file_downloader.cc b/ppapi/native_client/src/trusted/plugin/file_downloader.cc index 7c6c045..ccddfe8 100644 --- a/ppapi/native_client/src/trusted/plugin/file_downloader.cc +++ b/ppapi/native_client/src/trusted/plugin/file_downloader.cc @@ -20,12 +20,12 @@ namespace plugin { -void FileDownloader::Initialize(Plugin* instance) { - PLUGIN_PRINTF(("FileDownloader::FileDownloader (this=%p)\n", - static_cast<void*>(this))); - CHECK(instance != NULL); - CHECK(instance_ == NULL); // Can only initialize once. - instance_ = instance; +FileDownloader::FileDownloader(Plugin* instance) + : instance_(instance), + file_open_notify_callback_(pp::BlockUntilComplete()), + stream_finish_callback_(pp::BlockUntilComplete()), + mode_(DOWNLOAD_NONE), + data_stream_callback_source_(NULL) { callback_factory_.Initialize(this); temp_buffer_.resize(kTempBufferSize); } @@ -40,7 +40,6 @@ bool FileDownloader::OpenStream( return false; status_code_ = -1; - url_ = url; file_open_notify_callback_ = callback; mode_ = DOWNLOAD_TO_BUFFER_AND_STREAM; pp::URLRequestInfo url_request(instance_); @@ -63,7 +62,7 @@ bool FileDownloader::OpenStream( url_request.SetRecordDownloadProgress(true); // Prepare the url request. - url_request.SetURL(url_); + url_request.SetURL(url); // Request asynchronous download of the url providing an on-load callback. // As long as this step is guaranteed to be asynchronous, we can call @@ -117,7 +116,7 @@ void FileDownloader::URLLoadStartNotify(int32_t pp_error) { file_open_notify_callback_.RunAndClear(PP_OK); } -void FileDownloader::FinishStreaming( +void FileDownloader::BeginStreaming( const pp::CompletionCallback& callback) { stream_finish_callback_ = callback; diff --git a/ppapi/native_client/src/trusted/plugin/file_downloader.h b/ppapi/native_client/src/trusted/plugin/file_downloader.h index 80b34cd..4a1a71a 100644 --- a/ppapi/native_client/src/trusted/plugin/file_downloader.h +++ b/ppapi/native_client/src/trusted/plugin/file_downloader.h @@ -35,25 +35,15 @@ typedef pp::CompletionCallbackWithOutput<FileStreamData> StreamCallback; // the url into a file and providing an open file descriptor. class FileDownloader { public: - // Ctor initializes |instance_| to NULL, be sure to call Initialize() before - // calling Open(), or Open() will fail. - FileDownloader() - : instance_(NULL), - file_open_notify_callback_(pp::BlockUntilComplete()), - stream_finish_callback_(pp::BlockUntilComplete()), - mode_(DOWNLOAD_NONE), - data_stream_callback_source_(NULL) {} + explicit FileDownloader(Plugin* instance); ~FileDownloader() {} - // Initialize() can only be called once during the lifetime of this instance. - void Initialize(Plugin* instance); - // Issues a GET on |url| to start downloading the response into a file, // and finish streaming it. |callback| will be run after streaming is // done or if an error prevents streaming from completing. // Returns true when callback is scheduled to be called on success or failure. - // Returns false if callback is NULL, Initialize() has not been called or if - // the PPB_FileIO_Trusted interface is not available. + // Returns false if callback is NULL, or if the PPB_FileIO_Trusted interface + // is not available. // If |record_progress| is true, then download progress will be recorded, // and can be polled through GetDownloadProgress(). // If |progress_callback| is not NULL and |record_progress| is true, @@ -64,17 +54,14 @@ class FileDownloader { // caller without writing to a temporary file. The callbacks provided by // |stream_callback_source| are expected to copy the data before returning. // |callback| is called once the response headers are received, - // and streaming must be completed separately via FinishStreaming(). + // and streaming must be completed separately via BeginStreaming(). bool OpenStream(const nacl::string& url, const pp::CompletionCallback& callback, StreamCallbackSource* stream_callback_source); // Finish streaming the response body for a URL request started by either // OpenStream(). Runs the given |callback| when streaming is done. - void FinishStreaming(const pp::CompletionCallback& callback); - - // Returns the url passed to Open(). - const nacl::string& url() const { return url_; } + void BeginStreaming(const pp::CompletionCallback& callback); // Once the GET request has finished, and the contents of the file // represented by |url_| are available, |full_url_| is the full URL including @@ -82,9 +69,6 @@ class FileDownloader { // Returns an empty string before the GET request has finished. const nacl::string& full_url() const { return full_url_; } - // Returns the PP_Resource of the active URL loader, or kInvalidResource. - PP_Resource url_loader() const { return url_loader_.pp_resource(); } - // GetDownloadProgress() returns the current download progress, which is // meaningful after Open() has been called. Progress only refers to the // response body and does not include the headers. @@ -105,23 +89,22 @@ class FileDownloader { extra_request_headers_ = extra_request_headers; } - private: NACL_DISALLOW_COPY_AND_ASSIGN(FileDownloader); + // For DOWNLOAD_TO_BUFFER_AND_STREAM, the process is very similar: // 1) Ask the browser to start streaming |url_| to an internal buffer. // 2) Ask the browser to finish streaming to |temp_buffer_| on success. // 3) Wait for streaming to finish, passing the data directly to the user. // Each step is done asynchronously using callbacks. We create callbacks // through a factory to take advantage of ref-counting. - // The public Open*() functions start step 1), and the public FinishStreaming + // The public Open*() functions start step 1), and the public BeginStreaming // function proceeds to step 2) and 3). bool InitialResponseIsValid(); void URLLoadStartNotify(int32_t pp_error); void URLReadBodyNotify(int32_t pp_error); Plugin* instance_; - nacl::string url_; nacl::string full_url_; nacl::string extra_request_headers_; @@ -136,5 +119,7 @@ class FileDownloader { std::vector<char> temp_buffer_; StreamCallbackSource* data_stream_callback_source_; }; -} // namespace plugin; + +} // namespace plugin + #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_FILE_DOWNLOADER_H_ diff --git a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc index 691bc7b..92740d9 100644 --- a/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc +++ b/ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc @@ -336,8 +336,7 @@ void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) { void PnaclCoordinator::OpenBitcodeStream() { // Now open the pexe stream. - streaming_downloader_.reset(new FileDownloader()); - streaming_downloader_->Initialize(plugin_); + streaming_downloader_.reset(new FileDownloader(plugin_)); // Mark the request as requesting a PNaCl bitcode file, // so that component updater can detect this user action. streaming_downloader_->set_request_headers( @@ -474,12 +473,12 @@ void PnaclCoordinator::NexeFdDidOpen(int32_t pp_error) { invalid_desc_wrapper_.reset(plugin_->wrapper_factory()->MakeInvalid()); // Meanwhile, a miss means we know we need to stream the bitcode, so stream - // the rest of it now. (Calling FinishStreaming means that the downloader + // the rest of it now. (Calling BeginStreaming means that the downloader // will begin handing data to the coordinator, which is safe any time after // the translate_thread_ object has been initialized). pp::CompletionCallback finish_cb = callback_factory_.NewCallback( &PnaclCoordinator::BitcodeStreamDidFinish); - streaming_downloader_->FinishStreaming(finish_cb); + streaming_downloader_->BeginStreaming(finish_cb); if (num_object_files_opened_ == split_module_count_) { // Open the nexe file for connecting ld and sel_ldr. |