summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-15 23:53:11 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-15 23:53:11 +0000
commit002b1f0426c55f9a147763a8e6b69ec999b4a1a1 (patch)
tree11a10c8815f5e69462c9d6466fe356305103cd46
parent201443355e29ad3d5fcd77967f686de45273073b (diff)
downloadchromium_src-002b1f0426c55f9a147763a8e6b69ec999b4a1a1.zip
chromium_src-002b1f0426c55f9a147763a8e6b69ec999b4a1a1.tar.gz
chromium_src-002b1f0426c55f9a147763a8e6b69ec999b4a1a1.tar.bz2
Revert 217860 "Implement per-browser crash throttling for NaCl p..." which broke nacl_integration on mac.
> Implement per-browser crash throttling for NaCl processes. > > This CL replicates the crash logic used to throttle plugins. > > BUG= https://code.google.com/p/nativeclient/issues/detail?id=359 > R=bbudge@chromium.org, jvoung@chromium.org, mseaborn@chromium.org > > Review URL: https://codereview.chromium.org/23135005 TBR=sehr@google.com Review URL: https://codereview.chromium.org/22893020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217867 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/nacl_host/nacl_browser.cc23
-rw-r--r--chrome/browser/nacl_host/nacl_browser.h14
-rw-r--r--chrome/browser/nacl_host/nacl_process_host.cc13
-rw-r--r--chrome/browser/nacl_host/nacl_process_host.h2
-rw-r--r--ppapi/native_client/src/trusted/plugin/module_ppapi.cc22
-rw-r--r--ppapi/native_client/src/trusted/plugin/module_ppapi.h11
-rw-r--r--ppapi/native_client/src/trusted/plugin/plugin.cc31
-rw-r--r--ppapi/native_client/src/trusted/plugin/plugin_error.h1
8 files changed, 56 insertions, 61 deletions
diff --git a/chrome/browser/nacl_host/nacl_browser.cc b/chrome/browser/nacl_host/nacl_browser.cc
index 180de94..8460124 100644
--- a/chrome/browser/nacl_host/nacl_browser.cc
+++ b/chrome/browser/nacl_host/nacl_browser.cc
@@ -12,7 +12,6 @@
#include "base/pickle.h"
#include "base/rand_util.h"
#include "base/strings/string_split.h"
-#include "base/time/time.h"
#include "base/win/windows_version.h"
#include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
@@ -113,10 +112,6 @@ void LogCacheSet(ValidationCacheStatus status) {
UMA_HISTOGRAM_ENUMERATION("NaCl.ValidationCache.Set", status, CACHE_MAX);
}
-// Crash throttling parameters.
-const size_t kMaxCrashesPerInterval = 3;
-const int64 kCrashesIntervalInSeconds = 120;
-
} // namespace
namespace nacl {
@@ -581,21 +576,3 @@ void NaClBrowser::PersistValidationCache() {
}
validation_cache_is_modified_ = false;
}
-
-void NaClBrowser::NotifyOfCrash() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- if (crash_times_.size() == kMaxCrashesPerInterval) {
- crash_times_.pop_front();
- }
- base::Time time = base::Time::Now();
- crash_times_.push_back(time);
-}
-
-bool NaClBrowser::TooManyCrashes() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
- if (crash_times_.size() != kMaxCrashesPerInterval) {
- return false;
- }
- base::TimeDelta delta = base::Time::Now() - crash_times_.front();
- return delta.InSeconds() <= kCrashesIntervalInSeconds;
-}
diff --git a/chrome/browser/nacl_host/nacl_browser.h b/chrome/browser/nacl_host/nacl_browser.h
index 80e7968..f9c6d9c 100644
--- a/chrome/browser/nacl_host/nacl_browser.h
+++ b/chrome/browser/nacl_host/nacl_browser.h
@@ -5,15 +5,12 @@
#ifndef CHROME_BROWSER_NACL_HOST_NACL_BROWSER_H_
#define CHROME_BROWSER_NACL_HOST_NACL_BROWSER_H_
-#include <deque>
-
#include "base/bind.h"
#include "base/containers/mru_cache.h"
#include "base/files/file_util_proxy.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
-#include "base/time/time.h"
#include "chrome/browser/nacl_host/nacl_validation_cache.h"
#include "components/nacl/common/nacl_browser_delegate.h"
@@ -122,14 +119,6 @@ class NaClBrowser {
void EarlyStartup();
static void SetDelegate(NaClBrowserDelegate* delegate);
static NaClBrowserDelegate* GetDelegate();
-
- // Support for NaCl crash throttling.
- // Each time a NaCl module crashes, the browser is notified.
- void NotifyOfCrash();
- // If "too many" crashes occur within a given time period, NaCl is throttled
- // until the rate again drops below the threshold.
- bool TooManyCrashes();
-
private:
friend struct DefaultSingletonTraits<NaClBrowser>;
@@ -188,9 +177,6 @@ class NaClBrowser {
std::vector<base::Closure> waiting_;
scoped_ptr<NaClBrowserDelegate> browser_delegate_;
-
- std::deque<base::Time> crash_times_;
-
DISALLOW_COPY_AND_ASSIGN(NaClBrowser);
};
diff --git a/chrome/browser/nacl_host/nacl_process_host.cc b/chrome/browser/nacl_host/nacl_process_host.cc
index cc97d9e..c915a5f 100644
--- a/chrome/browser/nacl_host/nacl_process_host.cc
+++ b/chrome/browser/nacl_host/nacl_process_host.cc
@@ -252,10 +252,6 @@ NaClProcessHost::~NaClProcessHost() {
#endif
}
-void NaClProcessHost::OnProcessCrashed(int exit_status) {
- NaClBrowser::GetInstance()->NotifyOfCrash();
-}
-
// This is called at browser startup.
// static
void NaClProcessHost::EarlyStartup(NaClBrowserDelegate* delegate) {
@@ -288,15 +284,6 @@ void NaClProcessHost::Launch(
reply_msg_ = reply_msg;
manifest_path_ = manifest_path;
- // Do not launch the requested NaCl module if NaCl is marked "unstable" due
- // to too many crashes within a given time period.
- if (NaClBrowser::GetInstance()->TooManyCrashes()) {
- SendErrorToRenderer("Process creation was throttled due to excessive"
- " crashes");
- delete this;
- return;
- }
-
const CommandLine* cmd = CommandLine::ForCurrentProcess();
#if defined(OS_WIN)
if (cmd->HasSwitch(switches::kEnableNaClDebug) &&
diff --git a/chrome/browser/nacl_host/nacl_process_host.h b/chrome/browser/nacl_host/nacl_process_host.h
index f32d92b..f2133a1 100644
--- a/chrome/browser/nacl_host/nacl_process_host.h
+++ b/chrome/browser/nacl_host/nacl_process_host.h
@@ -59,8 +59,6 @@ class NaClProcessHost : public content::BrowserChildProcessHostDelegate {
const base::FilePath& profile_directory);
virtual ~NaClProcessHost();
- virtual void OnProcessCrashed(int exit_status) OVERRIDE;
-
// Do any minimal work that must be done at browser startup.
static void EarlyStartup(NaClBrowserDelegate* delegate);
diff --git a/ppapi/native_client/src/trusted/plugin/module_ppapi.cc b/ppapi/native_client/src/trusted/plugin/module_ppapi.cc
index f78bbf3..4204ed4 100644
--- a/ppapi/native_client/src/trusted/plugin/module_ppapi.cc
+++ b/ppapi/native_client/src/trusted/plugin/module_ppapi.cc
@@ -76,6 +76,28 @@ pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) {
return plugin;
}
+const uint64_t kMaxCrashesPerInterval = 3;
+const uint64_t kCrashesIntervalInSeconds = 120;
+
+void ModulePpapi::RegisterPluginCrash() {
+ PLUGIN_PRINTF(("ModulePpapi::RegisterPluginCrash ()\n"));
+ if (crash_times_.size() == kMaxCrashesPerInterval) {
+ crash_times_.pop_front();
+ }
+ int64_t time = NaClGetTimeOfDayMicroseconds();
+ crash_times_.push_back(time);
+}
+
+bool ModulePpapi::IsPluginUnstable() {
+ PLUGIN_PRINTF(("ModulePpapi::IsPluginUnstable ()\n"));
+ if (crash_times_.size() != kMaxCrashesPerInterval) {
+ return false;
+ }
+ int64_t now = NaClGetTimeOfDayMicroseconds();
+ int64_t delta = now - crash_times_.front();
+ return delta / (1000.0 * 1000.0) <= kCrashesIntervalInSeconds;
+}
+
} // namespace plugin
diff --git a/ppapi/native_client/src/trusted/plugin/module_ppapi.h b/ppapi/native_client/src/trusted/plugin/module_ppapi.h
index ee7bd19..b2e7564 100644
--- a/ppapi/native_client/src/trusted/plugin/module_ppapi.h
+++ b/ppapi/native_client/src/trusted/plugin/module_ppapi.h
@@ -4,6 +4,8 @@
* found in the LICENSE file.
*/
+#include <deque>
+
#include "ppapi/c/private/ppb_nacl_private.h"
#include "ppapi/cpp/module.h"
@@ -19,9 +21,18 @@ class ModulePpapi : public pp::Module {
virtual pp::Instance* CreateInstance(PP_Instance pp_instance);
+ // NaCl crash throttling. If RegisterPluginCrash is called too many times
+ // within a time period, IsPluginUnstable reports true. As long as
+ // IsPluginUnstable returns true, NaCl modules will fail to load.
+ void RegisterPluginCrash();
+ bool IsPluginUnstable();
+
private:
bool init_was_successful_;
const PPB_NaCl_Private* private_interface_;
+
+ // Crash throttling support.
+ std::deque<int64_t> crash_times_;
};
} // namespace plugin
diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc
index 57bb648..fe27aa2 100644
--- a/ppapi/native_client/src/trusted/plugin/plugin.cc
+++ b/ppapi/native_client/src/trusted/plugin/plugin.cc
@@ -55,6 +55,7 @@
#include "ppapi/native_client/src/trusted/plugin/file_utils.h"
#include "ppapi/native_client/src/trusted/plugin/json_manifest.h"
+#include "ppapi/native_client/src/trusted/plugin/module_ppapi.h"
#include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
#include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h"
#include "ppapi/native_client/src/trusted/plugin/nexe_arch.h"
@@ -1009,6 +1010,10 @@ void Plugin::NexeDidCrash(int32_t pp_error) {
// invocation will just be a no-op, since all the crash log will
// have been received and we'll just get an EOF indication.
CopyCrashLogToJsConsole();
+
+ // Remember the nexe crash time, which helps determine the need to throttle.
+ ModulePpapi* module_ppapi = static_cast<ModulePpapi*>(pp::Module::Get());
+ module_ppapi->RegisterPluginCrash();
}
void Plugin::BitcodeDidTranslate(int32_t pp_error) {
@@ -1206,15 +1211,23 @@ void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) {
if (this->nacl_interface()->IsPnaclEnabled()) {
// Check whether PNaCl has been crashing "frequently". If so, report
// a load error.
- pp::CompletionCallback translate_callback =
- callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate);
- // Will always call the callback on success or failure.
- pnacl_coordinator_.reset(
- PnaclCoordinator::BitcodeToNative(this,
- program_url,
- pnacl_options,
- translate_callback));
- return;
+ ModulePpapi* module_ppapi =
+ static_cast<ModulePpapi*>(pp::Module::Get());
+ if (module_ppapi->IsPluginUnstable()) {
+ error_info.SetReport(ERROR_PNACL_CRASH_THROTTLED,
+ "PNaCl has been temporarily disabled because too"
+ " many crashes have been observed.");
+ } else {
+ pp::CompletionCallback translate_callback =
+ callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate);
+ // Will always call the callback on success or failure.
+ pnacl_coordinator_.reset(
+ PnaclCoordinator::BitcodeToNative(this,
+ program_url,
+ pnacl_options,
+ translate_callback));
+ return;
+ }
} else {
error_info.SetReport(ERROR_PNACL_NOT_ENABLED,
"PNaCl has not been enabled (e.g., by setting "
diff --git a/ppapi/native_client/src/trusted/plugin/plugin_error.h b/ppapi/native_client/src/trusted/plugin/plugin_error.h
index 9da77ca..cba1701 100644
--- a/ppapi/native_client/src/trusted/plugin/plugin_error.h
+++ b/ppapi/native_client/src/trusted/plugin/plugin_error.h
@@ -98,6 +98,7 @@ enum PluginErrorCode {
ERROR_PNACL_NOT_ENABLED = 68,
ERROR_MANIFEST_NOACCESS_URL = 69,
ERROR_NEXE_NOACCESS_URL = 70,
+ ERROR_PNACL_CRASH_THROTTLED = 71,
// If you add a code, read the enum comment above on how to update histograms.
ERROR_MAX
};