summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorulan@chromium.org <ulan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-14 12:09:44 +0000
committerulan@chromium.org <ulan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-14 12:09:44 +0000
commit6593ae118a974099b6079974c3b8f7d83fc5678f (patch)
tree88cca3151d104693d025140f55ce175b90d373f9
parent39565dde20bea906db318f29850e685fa0bf7920 (diff)
downloadchromium_src-6593ae118a974099b6079974c3b8f7d83fc5678f.zip
chromium_src-6593ae118a974099b6079974c3b8f7d83fc5678f.tar.gz
chromium_src-6593ae118a974099b6079974c3b8f7d83fc5678f.tar.bz2
Convert render thread idle delays from seconds to milliseconds.
This CL eliminates double to integer conversions when scheduling the idle timer and allows subsecond delays. The existing code simply rounds the delay down to an integer when scheduling the idle timer, which means that any subsecond delay schedules a timer with zero delay. BUG= TEST= Review URL: http://codereview.chromium.org/8463019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109866 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/extensions/extension_dispatcher.cc22
-rw-r--r--content/public/renderer/render_thread.h8
-rw-r--r--content/renderer/render_thread_impl.cc36
-rw-r--r--content/renderer/render_thread_impl.h10
-rw-r--r--content/test/mock_render_thread.cc10
-rw-r--r--content/test/mock_render_thread.h8
6 files changed, 49 insertions, 45 deletions
diff --git a/chrome/renderer/extensions/extension_dispatcher.cc b/chrome/renderer/extensions/extension_dispatcher.cc
index d88fefa..32d6731 100644
--- a/chrome/renderer/extensions/extension_dispatcher.cc
+++ b/chrome/renderer/extensions/extension_dispatcher.cc
@@ -32,8 +32,8 @@
#include "v8/include/v8.h"
namespace {
-static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */;
-static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */;
+static const int64 kInitialExtensionIdleHandlerDelayMs = 5*1000;
+static const int64 kMaxExtensionIdleHandlerDelayMs = 5*60*1000;
}
using extensions::MiscellaneousBindings;
@@ -55,8 +55,8 @@ ExtensionDispatcher::ExtensionDispatcher()
command_line.HasSwitch(switches::kSingleProcess);
if (is_extension_process_) {
- RenderThread::Get()->SetIdleNotificationDelayInS(
- kInitialExtensionIdleHandlerDelayS);
+ RenderThread::Get()->SetIdleNotificationDelayInMs(
+ kInitialExtensionIdleHandlerDelayMs);
}
user_script_slave_.reset(new UserScriptSlave(&extensions_));
@@ -92,7 +92,7 @@ void ExtensionDispatcher::WebKitInitialized() {
// even if the extension keeps up activity.
if (is_extension_process_) {
forced_idle_timer_.Start(FROM_HERE,
- base::TimeDelta::FromSeconds(kMaxExtensionIdleHandlerDelayS),
+ base::TimeDelta::FromMilliseconds(kMaxExtensionIdleHandlerDelayMs),
RenderThread::Get(), &RenderThread::IdleHandler);
}
@@ -125,12 +125,12 @@ void ExtensionDispatcher::IdleNotification() {
if (is_extension_process_) {
// Dampen the forced delay as well if the extension stays idle for long
// periods of time.
- int64 forced_delay_s = std::max(static_cast<int64>(
- RenderThread::Get()->GetIdleNotificationDelayInS()),
- kMaxExtensionIdleHandlerDelayS);
+ int64 forced_delay_ms = std::max(
+ RenderThread::Get()->GetIdleNotificationDelayInMs(),
+ kMaxExtensionIdleHandlerDelayMs);
forced_idle_timer_.Stop();
forced_idle_timer_.Start(FROM_HERE,
- base::TimeDelta::FromSeconds(forced_delay_s),
+ base::TimeDelta::FromMilliseconds(forced_delay_ms),
RenderThread::Get(), &RenderThread::IdleHandler);
}
}
@@ -153,7 +153,7 @@ void ExtensionDispatcher::OnMessageInvoke(const std::string& extension_id,
// dispatch, for which Invoke is the chokepoint.
if (is_extension_process_) {
RenderThread::Get()->ScheduleIdleHandler(
- kInitialExtensionIdleHandlerDelayS);
+ kInitialExtensionIdleHandlerDelayMs);
}
// Tell the browser process that the event is dispatched and we're idle.
@@ -301,7 +301,7 @@ void ExtensionDispatcher::OnActivateExtension(
// This is called when starting a new extension page, so start the idle
// handler ticking.
- RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayS);
+ RenderThread::Get()->ScheduleIdleHandler(kInitialExtensionIdleHandlerDelayMs);
UpdateActiveExtensions();
diff --git a/content/public/renderer/render_thread.h b/content/public/renderer/render_thread.h
index 3566c64..2140e70 100644
--- a/content/public/renderer/render_thread.h
+++ b/content/public/renderer/render_thread.h
@@ -86,15 +86,15 @@ class CONTENT_EXPORT RenderThread : public IPC::Message::Sender {
const std::string& v8_extension_name) const = 0;
// Schedule a call to IdleHandler with the given initial delay.
- virtual void ScheduleIdleHandler(double initial_delay_s) = 0;
+ virtual void ScheduleIdleHandler(int64 initial_delay_ms) = 0;
// A task we invoke periodically to assist with idle cleanup.
virtual void IdleHandler() = 0;
// Get/Set the delay for how often the idle handler is called.
- virtual double GetIdleNotificationDelayInS() const = 0;
- virtual void SetIdleNotificationDelayInS(
- double idle_notification_delay_in_s) = 0;
+ virtual int64 GetIdleNotificationDelayInMs() const = 0;
+ virtual void SetIdleNotificationDelayInMs(
+ int64 idle_notification_delay_in_ms) = 0;
#if defined(OS_WIN)
// Request that the given font be loaded by the browser so it's cached by the
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index 134ef75..ea8f8ff 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -100,7 +100,7 @@ using WebKit::WebView;
using content::RenderProcessObserver;
namespace {
-static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */;
+static const int64 kInitialIdleHandlerDelayMs = 1000;
#if defined(TOUCH_UI)
static const int kPopupListBoxMinimumRowHeight = 60;
@@ -192,7 +192,7 @@ void RenderThreadImpl::Init() {
plugin_refresh_allowed_ = true;
widget_count_ = 0;
hidden_widget_count_ = 0;
- idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS;
+ idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
task_factory_.reset(new ScopedRunnableMethodFactory<RenderThreadImpl>(this));
appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
@@ -404,7 +404,7 @@ void RenderThreadImpl::WidgetHidden() {
}
if (widget_count_ && hidden_widget_count_ == widget_count_)
- ScheduleIdleHandler(kInitialIdleHandlerDelayS);
+ ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
}
void RenderThreadImpl::WidgetRestored() {
@@ -548,11 +548,11 @@ bool RenderThreadImpl::IsRegisteredExtension(
return v8_extensions_.find(v8_extension_name) != v8_extensions_.end();
}
-void RenderThreadImpl::ScheduleIdleHandler(double initial_delay_s) {
- idle_notification_delay_in_s_ = initial_delay_s;
+void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
+ idle_notification_delay_in_ms_ = initial_delay_ms;
idle_timer_.Stop();
idle_timer_.Start(FROM_HERE,
- base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)),
+ base::TimeDelta::FromMilliseconds(initial_delay_ms),
this, &RenderThreadImpl::IdleHandler);
}
@@ -564,25 +564,29 @@ void RenderThreadImpl::IdleHandler() {
v8::V8::IdleNotification();
// Schedule next invocation.
- // Dampen the delay using the algorithm:
+ // Dampen the delay using the algorithm (if delay is in seconds):
// delay = delay + 1 / (delay + 2)
// Using floor(delay) has a dampening effect such as:
// 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
- // Note that idle_notification_delay_in_s_ would be reset to
- // kInitialIdleHandlerDelayS in RenderThreadImpl::WidgetHidden.
- ScheduleIdleHandler(idle_notification_delay_in_s_ +
- 1.0 / (idle_notification_delay_in_s_ + 2.0));
+ // If the delay is in milliseconds, the above formula is equivalent to:
+ // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
+ // which is equivalent to
+ // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
+ // Note that idle_notification_delay_in_ms_ would be reset to
+ // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
+ ScheduleIdleHandler(idle_notification_delay_in_ms_ +
+ 1000000 / (idle_notification_delay_in_ms_ + 2000));
FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
}
-double RenderThreadImpl::GetIdleNotificationDelayInS() const {
- return idle_notification_delay_in_s_;
+int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
+ return idle_notification_delay_in_ms_;
}
-void RenderThreadImpl::SetIdleNotificationDelayInS(
- double idle_notification_delay_in_s) {
- idle_notification_delay_in_s_ = idle_notification_delay_in_s;
+void RenderThreadImpl::SetIdleNotificationDelayInMs(
+ int64 idle_notification_delay_in_ms) {
+ idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
}
#if defined(OS_WIN)
diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h
index 32e92df..e3fdac3 100644
--- a/content/renderer/render_thread_impl.h
+++ b/content/renderer/render_thread_impl.h
@@ -108,11 +108,11 @@ class CONTENT_EXPORT RenderThreadImpl : public content::RenderThread,
virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
virtual bool IsRegisteredExtension(
const std::string& v8_extension_name) const OVERRIDE;
- virtual void ScheduleIdleHandler(double initial_delay_s) OVERRIDE;
+ virtual void ScheduleIdleHandler(int64 initial_delay_ms) OVERRIDE;
virtual void IdleHandler() OVERRIDE;
- virtual double GetIdleNotificationDelayInS() const OVERRIDE;
- virtual void SetIdleNotificationDelayInS(
- double idle_notification_delay_in_s) OVERRIDE;
+ virtual int64 GetIdleNotificationDelayInMs() const OVERRIDE;
+ virtual void SetIdleNotificationDelayInMs(
+ int64 idle_notification_delay_in_ms) OVERRIDE;
#if defined(OS_WIN)
virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
virtual void ReleaseCachedFonts() OVERRIDE;
@@ -216,7 +216,7 @@ class CONTENT_EXPORT RenderThreadImpl : public content::RenderThread,
int hidden_widget_count_;
// The current value of the idle notification timer delay.
- double idle_notification_delay_in_s_;
+ int64 idle_notification_delay_in_ms_;
bool suspend_webkit_shared_timer_;
bool notify_webkit_of_modal_loop_;
diff --git a/content/test/mock_render_thread.cc b/content/test/mock_render_thread.cc
index 3d9e395..eca409e 100644
--- a/content/test/mock_render_thread.cc
+++ b/content/test/mock_render_thread.cc
@@ -127,18 +127,18 @@ bool MockRenderThread::IsRegisteredExtension(
return false;
}
-void MockRenderThread::ScheduleIdleHandler(double initial_delay_s) {
+void MockRenderThread::ScheduleIdleHandler(int64 initial_delay_ms) {
}
void MockRenderThread::IdleHandler() {
}
-double MockRenderThread::GetIdleNotificationDelayInS() const {
- return 0.0;
+int64 MockRenderThread::GetIdleNotificationDelayInMs() const {
+ return 0;
}
-void MockRenderThread::SetIdleNotificationDelayInS(
- double idle_notification_delay_in_s) {
+void MockRenderThread::SetIdleNotificationDelayInMs(
+ int64 idle_notification_delay_in_ms) {
}
#if defined(OS_WIN)
diff --git a/content/test/mock_render_thread.h b/content/test/mock_render_thread.h
index bfae6c0..4223ab2 100644
--- a/content/test/mock_render_thread.h
+++ b/content/test/mock_render_thread.h
@@ -56,11 +56,11 @@ class MockRenderThread : public content::RenderThread {
virtual void RegisterExtension(v8::Extension* extension) OVERRIDE;
virtual bool IsRegisteredExtension(
const std::string& v8_extension_name) const OVERRIDE;
- virtual void ScheduleIdleHandler(double initial_delay_s) OVERRIDE;
+ virtual void ScheduleIdleHandler(int64 initial_delay_ms) OVERRIDE;
virtual void IdleHandler() OVERRIDE;
- virtual double GetIdleNotificationDelayInS() const OVERRIDE;
- virtual void SetIdleNotificationDelayInS(
- double idle_notification_delay_in_s) OVERRIDE;
+ virtual int64 GetIdleNotificationDelayInMs() const OVERRIDE;
+ virtual void SetIdleNotificationDelayInMs(
+ int64 idle_notification_delay_in_ms) OVERRIDE;
#if defined(OS_WIN)
virtual void PreCacheFont(const LOGFONT& log_font) OVERRIDE;
virtual void ReleaseCachedFonts() OVERRIDE;