diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 03:06:47 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-02 03:06:47 +0000 |
commit | 92ad3f713f47d403058c14ae81e3a496f31cb864 (patch) | |
tree | 961fdcd0825705992000782b7bd357f20c812fc5 /ppapi | |
parent | 59726558ff4ccc590da249349bb49910ac7afd0d (diff) | |
download | chromium_src-92ad3f713f47d403058c14ae81e3a496f31cb864.zip chromium_src-92ad3f713f47d403058c14ae81e3a496f31cb864.tar.gz chromium_src-92ad3f713f47d403058c14ae81e3a496f31cb864.tar.bz2 |
Modify the Native Client plugin to report progress events. This CL modifies
the FileDownloader::Open method to accept an optional 'progress_callback'
parameter which is passed to the URL loader using the trusted interface. The
Plugin defines a static 'UpdateNexeDownloadProgress' method which it passes
to the file downloader when loading nexes. A 5% progress change threshold
is used to avoid spamming the Javascript side with progress updates.
Review URL: http://codereview.chromium.org/7792018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99303 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
4 files changed, 75 insertions, 28 deletions
diff --git a/ppapi/native_client/src/trusted/plugin/file_downloader.cc b/ppapi/native_client/src/trusted/plugin/file_downloader.cc index 4c8f476..1c00d26 100644 --- a/ppapi/native_client/src/trusted/plugin/file_downloader.cc +++ b/ppapi/native_client/src/trusted/plugin/file_downloader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Native Client Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,7 +14,6 @@ #include "native_client/src/trusted/plugin/utility.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_file_io.h" -#include "ppapi/c/trusted/ppb_url_loader_trusted.h" #include "ppapi/cpp/file_io.h" #include "ppapi/cpp/file_ref.h" #include "ppapi/cpp/url_request_info.h" @@ -36,12 +35,16 @@ void FileDownloader::Initialize(Plugin* instance) { callback_factory_.Initialize(this); file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); + url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( + pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); } -bool FileDownloader::Open(const nacl::string& url, - DownloadFlags flags, - const pp::CompletionCallback& callback) { +bool FileDownloader::Open( + const nacl::string& url, + DownloadFlags flags, + const pp::CompletionCallback& callback, + PP_URLLoaderTrusted_StatusCallback progress_callback) { PLUGIN_PRINTF(("FileDownloader::Open (url=%s)\n", url.c_str())); if (callback.pp_completion_callback().func == NULL || instance_ == NULL || @@ -90,12 +93,16 @@ bool FileDownloader::Open(const nacl::string& url, } } - if (grant_universal_access) { - const PPB_URLLoaderTrusted* url_loaded_trusted = - static_cast<const PPB_URLLoaderTrusted*>( - module->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); - if (url_loaded_trusted != NULL) - url_loaded_trusted->GrantUniversalAccess(url_loader_.pp_resource()); + if (url_loader_trusted_interface_ != NULL) { + if (grant_universal_access) { + url_loader_trusted_interface_->GrantUniversalAccess( + url_loader_.pp_resource()); + } + if (progress_callback != NULL) { + url_request.SetRecordDownloadProgress(true); + url_loader_trusted_interface_->RegisterStatusCallback( + url_loader_.pp_resource(), progress_callback); + } } // Prepare the url request. diff --git a/ppapi/native_client/src/trusted/plugin/file_downloader.h b/ppapi/native_client/src/trusted/plugin/file_downloader.h index f94d7fe8..1e9066f 100644 --- a/ppapi/native_client/src/trusted/plugin/file_downloader.h +++ b/ppapi/native_client/src/trusted/plugin/file_downloader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Native Client Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,6 +10,7 @@ #include "native_client/src/include/nacl_macros.h" #include "native_client/src/include/nacl_string.h" #include "ppapi/c/trusted/ppb_file_io_trusted.h" +#include "ppapi/c/trusted/ppb_url_loader_trusted.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/file_io.h" #include "ppapi/cpp/url_loader.h" @@ -40,6 +41,7 @@ class FileDownloader { : instance_(NULL), file_open_notify_callback_(pp::BlockUntilComplete()), file_io_trusted_interface_(NULL), + url_loader_trusted_interface_(NULL), open_time_(-1) {} ~FileDownloader() {} @@ -51,9 +53,12 @@ class FileDownloader { // 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. + // If |progress_callback| is not NULL, it will be invoked for every progress + // update received by the loader. bool Open(const nacl::string& url, DownloadFlags flags, - const pp::CompletionCallback& callback); + const pp::CompletionCallback& callback, + PP_URLLoaderTrusted_StatusCallback progress_callback); // If downloading and opening succeeded, this returns a valid read-only // POSIX file descriptor. On failure, the return value is an invalid @@ -105,6 +110,7 @@ class FileDownloader { pp::CompletionCallback file_open_notify_callback_; pp::FileIO file_reader_; const PPB_FileIOTrusted* file_io_trusted_interface_; + const PPB_URLLoaderTrusted* url_loader_trusted_interface_; pp::URLLoader url_loader_; pp::CompletionCallbackFactory<FileDownloader> callback_factory_; int64_t open_time_; diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index b262874..8e7e6aa 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -1,8 +1,6 @@ -/* - * Copyright (c) 2011 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #ifdef _MSC_VER // Do not warn about use of std::copy with raw pointers. @@ -905,6 +903,7 @@ Plugin::Plugin(PP_Instance pp_instance) enable_dev_interface_(false), replayDidChangeView(false), replayHandleDocumentLoad(false), + last_event_bytes_received_(0), init_time_(0), ready_time_(0), nexe_size_(0) { @@ -1509,7 +1508,10 @@ void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { callback_factory_.NewRequiredCallback(&Plugin::NexeFileDidOpen); // Will always call the callback on success or failure. CHECK( - nexe_downloader_.Open(program_url, DOWNLOAD_TO_FILE, open_callback)); + nexe_downloader_.Open(program_url, + DOWNLOAD_TO_FILE, + open_callback, + &UpdateNexeDownloadProgress)); return; } } @@ -1552,14 +1554,16 @@ void Plugin::RequestNaClManifest(const nacl::string& url) { // Will always call the callback on success or failure. CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), DOWNLOAD_TO_BUFFER, - open_callback)); + open_callback, + NULL)); } else { pp::CompletionCallback open_callback = callback_factory_.NewRequiredCallback(&Plugin::NaClManifestFileDidOpen); // Will always call the callback on success or failure. CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), DOWNLOAD_TO_FILE, - open_callback)); + open_callback, + NULL)); } } @@ -1660,7 +1664,7 @@ bool Plugin::StreamAsFile(const nacl::string& url, return false; } // If true, will always call the callback on success or failure. - return downloader->Open(url, DOWNLOAD_TO_FILE, open_callback); + return downloader->Open(url, DOWNLOAD_TO_FILE, open_callback, NULL); } #ifndef HACK_FOR_MACOS_HANG_REMOVED @@ -1746,6 +1750,28 @@ void Plugin::ReportLoadAbort() { HistogramEnumerateLoadStatus(ERROR_LOAD_ABORTED); } +void Plugin::UpdateNexeDownloadProgress( + PP_Instance pp_instance, + PP_Resource pp_resource, + int64_t bytes_sent, + int64_t total_bytes_to_be_sent, + int64_t bytes_received, + int64_t total_bytes_to_be_received) +{ + Instance* instance = pp::Module::Get()->InstanceForPPInstance(pp_instance); + if (instance != NULL) { + Plugin* plugin = static_cast<Plugin*>(instance); + int64_t progress = bytes_received - plugin->last_event_bytes_received_; + const int64_t kProgressThreshold = 1 << 17; // 128K bytes per event + if (progress > kProgressThreshold) { + plugin->EnqueueProgressEvent("progress", + LENGTH_IS_COMPUTABLE, + bytes_received, + total_bytes_to_be_received); + plugin->last_event_bytes_received_ = bytes_received; + } + } +} void Plugin::EnqueueProgressEvent(const char* event_type, LengthComputable length_computable, diff --git a/ppapi/native_client/src/trusted/plugin/plugin.h b/ppapi/native_client/src/trusted/plugin/plugin.h index 2df0827..b4e76cf 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.h +++ b/ppapi/native_client/src/trusted/plugin/plugin.h @@ -1,8 +1,6 @@ -/* - * Copyright (c) 2011 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. // The portable representation of an instance and root scriptable object. // The PPAPI version of the plugin instantiates a subclass of this class. @@ -501,12 +499,22 @@ class Plugin : public pp::InstancePrivate { nacl::scoped_ptr<pp::WidgetClient_Dev> widget_client_adapter_; nacl::scoped_ptr<pp::Zoom_Dev> zoom_adapter_; - // used for NexeFileDidOpenContinuation + // Used for NexeFileDidOpenContinuation int64_t load_start_; int64_t init_time_; int64_t ready_time_; size_t nexe_size_; + + static void UpdateNexeDownloadProgress( + PP_Instance pp_instance, + PP_Resource pp_resource, + int64_t bytes_sent, + int64_t total_bytes_to_be_sent, + int64_t bytes_received, + int64_t total_bytes_to_be_received); + + int64_t last_event_bytes_received_; }; } // namespace plugin |