Index: ppapi/native_client/src/trusted/plugin/plugin.cc |
=================================================================== |
--- ppapi/native_client/src/trusted/plugin/plugin.cc (revision 110385) |
+++ ppapi/native_client/src/trusted/plugin/plugin.cc (working copy) |
@@ -985,7 +985,7 @@ |
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 @@ |
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) { |
+ // 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; |
polina
2011/11/23 08:23:59
perhaps put this at the top of the file?
bbudge
2011/11/23 14:09:37
Since it's only used once, I kind of like it right
|
+ 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); |
+ // 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; |
- // Get the URL for 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; |
plugin->EnqueueProgressEvent(kProgressEventProgress, |
url, |
length_computable, |
bytes_received, |
total_bytes_to_be_received); |
polina
2011/11/23 08:23:59
do the users know that they only get some of these
bbudge
2011/11/23 14:09:37
They will always get a 'loadend' event with the re
|
- plugin->last_event_bytes_received_ = bytes_received; |
} |
} |
} |