OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifdef _MSC_VER | 5 #ifdef _MSC_VER |
6 // Do not warn about use of std::copy with raw pointers. | 6 // Do not warn about use of std::copy with raw pointers. |
7 #pragma warning(disable : 4996) | 7 #pragma warning(disable : 4996) |
8 #endif | 8 #endif |
9 | 9 |
10 #include "native_client/src/trusted/plugin/plugin.h" | 10 #include "native_client/src/trusted/plugin/plugin.h" |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 nexe_error_reported_(false), | 978 nexe_error_reported_(false), |
979 wrapper_factory_(NULL), | 979 wrapper_factory_(NULL), |
980 last_error_string_(""), | 980 last_error_string_(""), |
981 ppapi_proxy_(NULL), | 981 ppapi_proxy_(NULL), |
982 enable_dev_interfaces_(false), | 982 enable_dev_interfaces_(false), |
983 replayDidChangeView(false), | 983 replayDidChangeView(false), |
984 replayHandleDocumentLoad(false), | 984 replayHandleDocumentLoad(false), |
985 init_time_(0), | 985 init_time_(0), |
986 ready_time_(0), | 986 ready_time_(0), |
987 nexe_size_(0), | 987 nexe_size_(0), |
988 last_event_bytes_received_(0) { | 988 time_of_last_progress_event_(0) { |
989 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" | 989 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" |
990 NACL_PRId32")\n", static_cast<void*>(this), pp_instance)); | 990 NACL_PRId32")\n", static_cast<void*>(this), pp_instance)); |
991 NaClSrpcModuleInit(); | 991 NaClSrpcModuleInit(); |
992 nexe_downloader_.Initialize(this); | 992 nexe_downloader_.Initialize(this); |
993 pnacl_.Initialize(this); | 993 pnacl_.Initialize(this); |
994 callback_factory_.Initialize(this); | 994 callback_factory_.Initialize(this); |
995 } | 995 } |
996 | 996 |
997 | 997 |
998 Plugin::~Plugin() { | 998 Plugin::~Plugin() { |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1836 void Plugin::UpdateDownloadProgress( | 1836 void Plugin::UpdateDownloadProgress( |
1837 PP_Instance pp_instance, | 1837 PP_Instance pp_instance, |
1838 PP_Resource pp_resource, | 1838 PP_Resource pp_resource, |
1839 int64_t /*bytes_sent*/, | 1839 int64_t /*bytes_sent*/, |
1840 int64_t /*total_bytes_to_be_sent*/, | 1840 int64_t /*total_bytes_to_be_sent*/, |
1841 int64_t bytes_received, | 1841 int64_t bytes_received, |
1842 int64_t total_bytes_to_be_received) { | 1842 int64_t total_bytes_to_be_received) { |
1843 Instance* instance = pp::Module::Get()->InstanceForPPInstance(pp_instance); | 1843 Instance* instance = pp::Module::Get()->InstanceForPPInstance(pp_instance); |
1844 if (instance != NULL) { | 1844 if (instance != NULL) { |
1845 Plugin* plugin = static_cast<Plugin*>(instance); | 1845 Plugin* plugin = static_cast<Plugin*>(instance); |
1846 int64_t progress = bytes_received - plugin->last_event_bytes_received_; | 1846 // Rate limit progress events to a maximum of 100 per second. |
1847 const int64_t kProgressThreshold = 1 << 17; // 128K bytes per event | 1847 int64_t time = NaClGetTimeOfDayMicroseconds(); |
1848 if (progress > kProgressThreshold) { | 1848 int64_t elapsed = time - plugin->time_of_last_progress_event_; |
1849 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
| |
1850 if (elapsed > kTenMilliseconds) { | |
1851 plugin->time_of_last_progress_event_ = time; | |
1852 | |
1853 // Find the URL loader that sent this notification. | |
1854 const FileDownloader* file_downloader = | |
1855 plugin->FindFileDownloader(pp_resource); | |
1856 // If not a streamed file, it must be the .nexe loader. | |
1857 if (file_downloader == NULL) | |
1858 file_downloader = &plugin->nexe_downloader_; | |
1859 nacl::string url = file_downloader->url_to_open(); | |
1849 LengthComputable length_computable = (total_bytes_to_be_received >= 0) ? | 1860 LengthComputable length_computable = (total_bytes_to_be_received >= 0) ? |
1850 LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE; | 1861 LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE; |
1851 // Get the URL for the URL loader that sent this notification. | |
1852 const FileDownloader* file_downloader = | |
1853 plugin->FindFileDownloader(pp_resource); | |
1854 nacl::string url = (file_downloader != NULL) ? | |
1855 file_downloader->url_to_open() : NACL_NO_URL; | |
1856 | 1862 |
1857 plugin->EnqueueProgressEvent(kProgressEventProgress, | 1863 plugin->EnqueueProgressEvent(kProgressEventProgress, |
1858 url, | 1864 url, |
1859 length_computable, | 1865 length_computable, |
1860 bytes_received, | 1866 bytes_received, |
1861 total_bytes_to_be_received); | 1867 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
| |
1862 plugin->last_event_bytes_received_ = bytes_received; | |
1863 } | 1868 } |
1864 } | 1869 } |
1865 } | 1870 } |
1866 | 1871 |
1867 const FileDownloader* Plugin::FindFileDownloader( | 1872 const FileDownloader* Plugin::FindFileDownloader( |
1868 PP_Resource url_loader) const { | 1873 PP_Resource url_loader) const { |
1869 const FileDownloader* file_downloader = NULL; | 1874 const FileDownloader* file_downloader = NULL; |
1870 if (url_loader == nexe_downloader_.url_loader()) { | 1875 if (url_loader == nexe_downloader_.url_loader()) { |
1871 file_downloader = &nexe_downloader_; | 1876 file_downloader = &nexe_downloader_; |
1872 } else { | 1877 } else { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2014 std::string scheme = canonicalized.AsString().substr(comps.scheme.begin, | 2019 std::string scheme = canonicalized.AsString().substr(comps.scheme.begin, |
2015 comps.scheme.len); | 2020 comps.scheme.len); |
2016 if (scheme == kChromeExtensionUriScheme) | 2021 if (scheme == kChromeExtensionUriScheme) |
2017 return SCHEME_CHROME_EXTENSION; | 2022 return SCHEME_CHROME_EXTENSION; |
2018 if (scheme == kDataUriScheme) | 2023 if (scheme == kDataUriScheme) |
2019 return SCHEME_DATA; | 2024 return SCHEME_DATA; |
2020 return SCHEME_OTHER; | 2025 return SCHEME_OTHER; |
2021 } | 2026 } |
2022 | 2027 |
2023 } // namespace plugin | 2028 } // namespace plugin |
OLD | NEW |