Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1605)

Unified Diff: ppapi/native_client/src/trusted/plugin/plugin.cc

Issue 8548018: Make the rate limiting of Native Client Plugin progress events more robust. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
}
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698