diff options
author | bbudge@google.com <bbudge@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 22:00:47 +0000 |
---|---|---|
committer | bbudge@google.com <bbudge@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-23 22:00:47 +0000 |
commit | 477631200d25c51b1ab7920d0609bee8afd63cee (patch) | |
tree | 93e7d3c54f4f4391fc779569bd0436eb6fe15d15 /ppapi/native_client/src/trusted/plugin | |
parent | 60da8fea83fe4517bc87636d2dab5da6daaa5c5b (diff) | |
download | chromium_src-477631200d25c51b1ab7920d0609bee8afd63cee.zip chromium_src-477631200d25c51b1ab7920d0609bee8afd63cee.tar.gz chromium_src-477631200d25c51b1ab7920d0609bee8afd63cee.tar.bz2 |
Make the rate limiting of Native Client Plugin progress events
more robust by using time rather than bytes downloaded to determine when to fire another event.
BUG=none
TEST=manual, working on an example.
Review URL: http://codereview.chromium.org/8548018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111421 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/native_client/src/trusted/plugin')
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/plugin.cc | 25 | ||||
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/plugin.h | 2 |
2 files changed, 16 insertions, 11 deletions
diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 4fb8a0c..5409907 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -985,7 +985,7 @@ Plugin::Plugin(PP_Instance pp_instance) init_time_(0), ready_time_(0), nexe_size_(0), - last_event_bytes_received_(0) { + time_of_last_progress_event_(0) { PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" NACL_PRId32")\n", static_cast<void*>(this), pp_instance)); NaClSrpcModuleInit(); @@ -1843,23 +1843,28 @@ void Plugin::UpdateDownloadProgress( 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) { - LengthComputable length_computable = (total_bytes_to_be_received >= 0) ? - LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE; - // Get the URL for the URL loader that sent this notification. + // Rate limit progress events to a maximum of 100 per second. + int64_t time = NaClGetTimeOfDayMicroseconds(); + int64_t elapsed = time - plugin->time_of_last_progress_event_; + const int64_t kTenMilliseconds = 10000; + if (elapsed > kTenMilliseconds) { + plugin->time_of_last_progress_event_ = time; + + // Find the URL loader that sent this notification. const FileDownloader* file_downloader = plugin->FindFileDownloader(pp_resource); - nacl::string url = (file_downloader != NULL) ? - file_downloader->url_to_open() : NACL_NO_URL; + // If not a streamed file, it must be the .nexe loader. + if (file_downloader == NULL) + file_downloader = &plugin->nexe_downloader_; + nacl::string url = file_downloader->url_to_open(); + LengthComputable length_computable = (total_bytes_to_be_received >= 0) ? + LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE; plugin->EnqueueProgressEvent(kProgressEventProgress, url, length_computable, bytes_received, total_bytes_to_be_received); - plugin->last_event_bytes_received_ = bytes_received; } } } diff --git a/ppapi/native_client/src/trusted/plugin/plugin.h b/ppapi/native_client/src/trusted/plugin/plugin.h index 966933b..090b4bf 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.h +++ b/ppapi/native_client/src/trusted/plugin/plugin.h @@ -560,7 +560,7 @@ class Plugin : public pp::InstancePrivate { // downloaded. const FileDownloader* FindFileDownloader(PP_Resource url_loader) const; - int64_t last_event_bytes_received_; + int64_t time_of_last_progress_event_; }; } // namespace plugin |