Apply a rate limit on a per-plug-in basis to plug-in crashes.
BUG=115758
Review URL: https://chromiumcodereview.appspot.com/9460038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124139 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc
index f11603d6..7b2f2c6 100644
--- a/content/browser/plugin_service_impl.cc
+++ b/content/browser/plugin_service_impl.cc
@@ -626,6 +626,41 @@
plugin->ForceShutdown();
}
+static const unsigned int kMaxCrashesPerInterval = 3;
+static const unsigned int kCrashesInterval = 120;
+
+void PluginServiceImpl::RegisterPluginCrash(const FilePath& path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ std::map<FilePath, std::vector<base::Time> >::iterator i =
+ crash_times_.find(path);
+ if (i == crash_times_.end()) {
+ crash_times_[path] = std::vector<base::Time>();
+ i = crash_times_.find(path);
+ }
+ if (i->second.size() == kMaxCrashesPerInterval) {
+ i->second.erase(i->second.begin());
+ }
+ base::Time time = base::Time::Now();
+ i->second.push_back(time);
+}
+
+bool PluginServiceImpl::IsPluginUnstable(const FilePath& path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ std::map<FilePath, std::vector<base::Time> >::const_iterator i =
+ crash_times_.find(path);
+ if (i == crash_times_.end()) {
+ return false;
+ }
+ if (i->second.size() != kMaxCrashesPerInterval) {
+ return false;
+ }
+ base::TimeDelta delta = base::Time::Now() - i->second[0];
+ if (delta.InSeconds() <= kCrashesInterval) {
+ return true;
+ }
+ return false;
+}
+
void PluginServiceImpl::RefreshPlugins() {
plugin_list_->RefreshPlugins();
}