summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 20:18:29 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-12 20:18:29 +0000
commit0f5a74e672b831621d524f41dc58891b3867584d (patch)
tree80e200c70fb127140cf7d1a9c4465697c5b40ebf /content
parentf352e796c7634f9ac6482150845896ddb6ffb262 (diff)
downloadchromium_src-0f5a74e672b831621d524f41dc58891b3867584d.zip
chromium_src-0f5a74e672b831621d524f41dc58891b3867584d.tar.gz
chromium_src-0f5a74e672b831621d524f41dc58891b3867584d.tar.bz2
Simplify ppapi hung-plugin calculations.
BUG=144077 Review URL: https://chromiumcodereview.appspot.com/10909175 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/renderer/pepper/pepper_hung_plugin_filter.cc93
-rw-r--r--content/renderer/pepper/pepper_hung_plugin_filter.h8
2 files changed, 42 insertions, 59 deletions
diff --git a/content/renderer/pepper/pepper_hung_plugin_filter.cc b/content/renderer/pepper/pepper_hung_plugin_filter.cc
index 50b3339..7d0574d 100644
--- a/content/renderer/pepper/pepper_hung_plugin_filter.cc
+++ b/content/renderer/pepper/pepper_hung_plugin_filter.cc
@@ -38,8 +38,9 @@ PepperHungPluginFilter::PepperHungPluginFilter(const FilePath& plugin_path,
void PepperHungPluginFilter::BeginBlockOnSyncMessage() {
base::AutoLock lock(lock_);
+ last_message_received_ = base::TimeTicks::Now();
if (pending_sync_message_count_ == 0)
- began_blocking_time_ = base::TimeTicks::Now();
+ began_blocking_time_ = last_message_received_;
pending_sync_message_count_++;
EnsureTimerScheduled();
@@ -88,78 +89,58 @@ void PepperHungPluginFilter::EnsureTimerScheduled() {
}
void PepperHungPluginFilter::MayHaveBecomeUnhung() {
- if (!hung_plugin_showing_ || IsHung(base::TimeTicks::Now()))
+ lock_.AssertAcquired();
+ if (!hung_plugin_showing_ || IsHung())
return;
SendHungMessage(false);
hung_plugin_showing_ = false;
}
-bool PepperHungPluginFilter::IsHung(base::TimeTicks now) const {
+base::TimeTicks PepperHungPluginFilter::GetHungTime() const {
+ lock_.AssertAcquired();
+
+ DCHECK(pending_sync_message_count_);
+ DCHECK(!began_blocking_time_.is_null());
+ DCHECK(!last_message_received_.is_null());
+
+ // Always considered hung at the hard threshold.
+ base::TimeTicks hard_time = began_blocking_time_ +
+ base::TimeDelta::FromSeconds(kBlockedHardThresholdSec);
+
+ // Hung after a soft threshold from last message of any sort.
+ base::TimeTicks soft_time = last_message_received_ +
+ base::TimeDelta::FromSeconds(kHungThresholdSec);
+
+ return std::min(soft_time, hard_time);
+}
+
+bool PepperHungPluginFilter::IsHung() const {
lock_.AssertAcquired();
if (!pending_sync_message_count_)
return false; // Not blocked on a sync message.
- DCHECK(!began_blocking_time_.is_null());
- if (now - began_blocking_time_ >=
- base::TimeDelta::FromSeconds(kBlockedHardThresholdSec))
- return true; // Been blocked too long regardless of what the plugin is
- // sending us.
-
- base::TimeDelta hung_threshold =
- base::TimeDelta::FromSeconds(kHungThresholdSec);
- if (now - began_blocking_time_ >= hung_threshold &&
- (last_message_received_.is_null() ||
- now - last_message_received_ >= hung_threshold))
- return true; // Blocked and haven't received a message in too long.
-
- return false;
+ return base::TimeTicks::Now() > GetHungTime();
}
void PepperHungPluginFilter::OnHangTimer() {
base::AutoLock lock(lock_);
timer_task_pending_ = false;
- // Save this up front so all deltas computed below will agree on "now."
- base::TimeTicks now = base::TimeTicks::Now();
-
- if (!IsHung(now)) {
- if (pending_sync_message_count_ > 0) {
- // Got a timer message while we're waiting on a sync message. We need
- // to schedule another timer message because the latest sync message
- // would not have scheduled one (we only have one out-standing timer at
- // a time).
- DCHECK(!began_blocking_time_.is_null());
- base::TimeDelta time_blocked = now - began_blocking_time_;
-
- // This is the delay we're considered hung since we first started
- // blocking.
- base::TimeDelta delay =
- base::TimeDelta::FromSeconds(kHungThresholdSec) - time_blocked;
-
- // If another message was received from the plugin since we first started
- // blocking, but we haven't hit the "hard" threshold yet, we won't be
- // considered hung even though we're beyond the "regular" hung threshold.
- // In this case, schedule a timer at the hard threshold.
- if (delay <= base::TimeDelta()) {
- delay = base::TimeDelta::FromSeconds(kBlockedHardThresholdSec) -
- time_blocked;
- }
-
- // If the delay is negative or zero, another timer task will be
- // immediately posted, and if the condition persists we could end up
- // spinning on hang timers and not getting any work done, causing our
- // own "kind of" hang (although the message loop is running little work
- // will be getting done) in the renderer! If the timings or logic are
- // off, we'd prefer to get a crash dump and know about it.
- CHECK(delay > base::TimeDelta());
-
- timer_task_pending_ = false;
- io_loop_->PostDelayedTask(FROM_HERE,
- base::Bind(&PepperHungPluginFilter::OnHangTimer, this),
- delay);
- }
+ if (!pending_sync_message_count_)
+ return; // Not blocked any longer.
+
+ base::TimeDelta delay = GetHungTime() - base::TimeTicks::Now();
+ if (delay > base::TimeDelta()) {
+ // Got a timer message while we're waiting on a sync message. We need
+ // to schedule another timer message because the latest sync message
+ // would not have scheduled one (we only have one out-standing timer at
+ // a time).
+ timer_task_pending_ = true;
+ io_loop_->PostDelayedTask(FROM_HERE,
+ base::Bind(&PepperHungPluginFilter::OnHangTimer, this),
+ delay);
return;
}
diff --git a/content/renderer/pepper/pepper_hung_plugin_filter.h b/content/renderer/pepper/pepper_hung_plugin_filter.h
index 08dcbf4..35fc45e 100644
--- a/content/renderer/pepper/pepper_hung_plugin_filter.h
+++ b/content/renderer/pepper/pepper_hung_plugin_filter.h
@@ -59,10 +59,12 @@ class PepperHungPluginFilter
// notifies the browser if so.
void MayHaveBecomeUnhung();
+ // Calculate the point at which the plugin could next be considered hung.
+ base::TimeTicks GetHungTime() const;
+
// Checks if the plugin is considered hung based on whether it has been
- // blocked for long enough. The current time is passed in so that the deltas
- // can be synchronized with the caller's computations.
- bool IsHung(base::TimeTicks now) const;
+ // blocked for long enough.
+ bool IsHung() const;
// Timer handler that checks for a hang after a timeout.
void OnHangTimer();