summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/render_thread.cc
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-25 22:01:20 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-25 22:01:20 +0000
commitc855b201a7fbf4b3956079244784450e1adde5d6 (patch)
tree61e86efbcd6c001fc7a4cef9cdeefa39270432a2 /chrome/renderer/render_thread.cc
parent284547ba566633338d9d6249511fd5f34da178b6 (diff)
downloadchromium_src-c855b201a7fbf4b3956079244784450e1adde5d6.zip
chromium_src-c855b201a7fbf4b3956079244784450e1adde5d6.tar.gz
chromium_src-c855b201a7fbf4b3956079244784450e1adde5d6.tar.bz2
Revert 24314 - Modify the RenderThread to track the number of widgets
and "hidden widgets" which are running through that thread. By knowing the if the widgets are all hidden, the thread can accurately inform V8 when it is idle so that V8 can better cleanup unused memory when idle. This time if V8 has been killed for some reason, don't call into it. BUG=none TEST=none Review URL: http://codereview.chromium.org/173379 TBR=mbelshe@google.com Review URL: http://codereview.chromium.org/174458 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24339 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/render_thread.cc')
-rw-r--r--chrome/renderer/render_thread.cc68
1 files changed, 4 insertions, 64 deletions
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index f517c9c..c6e5b17 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -9,7 +9,6 @@
#include "base/command_line.h"
#include "base/lazy_instance.h"
-#include "base/logging.h"
#include "base/shared_memory.h"
#include "base/stats_table.h"
#include "base/thread_local.h"
@@ -59,8 +58,6 @@ using WebKit::WebString;
namespace {
static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
-static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */;
-
static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls(
base::LINKER_INITIALIZED);
@@ -108,11 +105,8 @@ void RenderThread::Init() {
#endif
plugin_refresh_allowed_ = true;
- cache_stats_task_pending_ = false;
- widget_count_ = 0;
- hidden_widget_count_ = 0;
- idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS;
- task_factory_.reset(new ScopedRunnableMethodFactory<RenderThread>(this));
+ cache_stats_factory_.reset(
+ new ScopedRunnableMethodFactory<RenderThread>(this));
visited_link_slave_.reset(new VisitedLinkSlave());
user_script_slave_.reset(new UserScriptSlave());
@@ -162,30 +156,6 @@ void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) {
channel()->RemoveFilter(filter);
}
-void RenderThread::WidgetHidden() {
- DCHECK(hidden_widget_count_ < widget_count_);
- hidden_widget_count_++ ;
- if (widget_count_ && hidden_widget_count_ == widget_count_) {
- // Reset the delay.
- idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS;
-
- // Schedule the IdleHandler to wakeup in a bit.
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- task_factory_->NewRunnableMethod(&RenderThread::IdleHandler),
- static_cast<int64>(floor(idle_notification_delay_in_s_)) * 1000);
- }
-}
-
-void RenderThread::WidgetRestored() {
- DCHECK(hidden_widget_count_ > 0);
- hidden_widget_count_--;
-
- // Note: we may have a timer pending to call the IdleHandler (see the
- // WidgetHidden() code). But we don't bother to cancel it as it is
- // benign and won't do anything if the tab is un-hidden when it is
- // called.
-}
-
void RenderThread::Resolve(const char* name, size_t length) {
return dns_master_->Resolve(name, length);
}
@@ -346,17 +316,15 @@ void RenderThread::InformHostOfCacheStats() {
WebCache::UsageStats stats;
WebCache::getUsageStats(&stats);
Send(new ViewHostMsg_UpdatedCacheStats(stats));
- cache_stats_task_pending_ = false;
}
void RenderThread::InformHostOfCacheStatsLater() {
// Rate limit informing the host of our cache stats.
- if (cache_stats_task_pending_)
+ if (!cache_stats_factory_->empty())
return;
- cache_stats_task_pending_ = true;
MessageLoop::current()->PostDelayedTask(FROM_HERE,
- task_factory_->NewRunnableMethod(
+ cache_stats_factory_->NewRunnableMethod(
&RenderThread::InformHostOfCacheStats),
kCacheStatsDelayMS);
}
@@ -456,34 +424,6 @@ void RenderThread::EnsureWebKitInitialized() {
}
}
-void RenderThread::IdleHandler() {
- // It is possible that the timer was set while the widgets were idle,
- // but that they are no longer idle. If so, just return.
- if (!widget_count_ || hidden_widget_count_ < widget_count_)
- return;
-
- if (v8::V8::IsDead())
- return;
-
- LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this;
-
- // When V8::IdleNotification returns true, it means that it has cleaned up
- // as much as it can. There is no point in continuing to call it.
- if (!v8::V8::IdleNotification(false)) {
- // Dampen the delay using the algorithm:
- // delay = delay + 1 / (delay + 2)
- // Using floor(delay) has a dampening effect such as:
- // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
- idle_notification_delay_in_s_ +=
- 1.0 / (idle_notification_delay_in_s_ + 2.0);
-
- // Schedule the next timer.
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- task_factory_->NewRunnableMethod(&RenderThread::IdleHandler),
- static_cast<int64>(floor(idle_notification_delay_in_s_)) * 1000);
- }
-}
-
void RenderThread::OnExtensionMessageInvoke(const std::string& function_name,
const ListValue& args) {
RendererExtensionBindings::Invoke(function_name, args, NULL);