Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 8463019: Convert render thread idle delays from seconds to milliseconds. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address comments, fix compile error in test_support_content. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | content/test/mock_render_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/render_thread_impl.h" 5 #include "content/renderer/render_thread_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 using WebKit::WebFrame; 93 using WebKit::WebFrame;
94 using WebKit::WebNetworkStateNotifier; 94 using WebKit::WebNetworkStateNotifier;
95 using WebKit::WebRuntimeFeatures; 95 using WebKit::WebRuntimeFeatures;
96 using WebKit::WebScriptController; 96 using WebKit::WebScriptController;
97 using WebKit::WebString; 97 using WebKit::WebString;
98 using WebKit::WebStorageEventDispatcher; 98 using WebKit::WebStorageEventDispatcher;
99 using WebKit::WebView; 99 using WebKit::WebView;
100 using content::RenderProcessObserver; 100 using content::RenderProcessObserver;
101 101
102 namespace { 102 namespace {
103 static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; 103 static const int64 kInitialIdleHandlerDelayMs = 1000;
104 104
105 #if defined(TOUCH_UI) 105 #if defined(TOUCH_UI)
106 static const int kPopupListBoxMinimumRowHeight = 60; 106 static const int kPopupListBoxMinimumRowHeight = 60;
107 #endif 107 #endif
108 108
109 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access 109 // Keep the global RenderThreadImpl in a TLS slot so it is impossible to access
110 // incorrectly from the wrong thread. 110 // incorrectly from the wrong thread.
111 static base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > lazy_tls( 111 static base::LazyInstance<base::ThreadLocalPointer<RenderThreadImpl> > lazy_tls(
112 base::LINKER_INITIALIZED); 112 base::LINKER_INITIALIZED);
113 113
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (RenderProcessImpl::InProcessPlugins()) 185 if (RenderProcessImpl::InProcessPlugins())
186 initialize_com_.reset(new base::win::ScopedCOMInitializer()); 186 initialize_com_.reset(new base::win::ScopedCOMInitializer());
187 #endif 187 #endif
188 188
189 // In single process the single process is all there is. 189 // In single process the single process is all there is.
190 suspend_webkit_shared_timer_ = true; 190 suspend_webkit_shared_timer_ = true;
191 notify_webkit_of_modal_loop_ = true; 191 notify_webkit_of_modal_loop_ = true;
192 plugin_refresh_allowed_ = true; 192 plugin_refresh_allowed_ = true;
193 widget_count_ = 0; 193 widget_count_ = 0;
194 hidden_widget_count_ = 0; 194 hidden_widget_count_ = 0;
195 idle_notification_delay_in_s_ = kInitialIdleHandlerDelayS; 195 idle_notification_delay_in_ms_ = kInitialIdleHandlerDelayMs;
196 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThreadImpl>(this)); 196 task_factory_.reset(new ScopedRunnableMethodFactory<RenderThreadImpl>(this));
197 197
198 appcache_dispatcher_.reset(new AppCacheDispatcher(Get())); 198 appcache_dispatcher_.reset(new AppCacheDispatcher(Get()));
199 indexed_db_dispatcher_.reset(new IndexedDBDispatcher()); 199 indexed_db_dispatcher_.reset(new IndexedDBDispatcher());
200 200
201 db_message_filter_ = new DBMessageFilter(); 201 db_message_filter_ = new DBMessageFilter();
202 AddFilter(db_message_filter_.get()); 202 AddFilter(db_message_filter_.get());
203 203
204 vc_manager_ = new VideoCaptureImplManager(); 204 vc_manager_ = new VideoCaptureImplManager();
205 AddFilter(vc_manager_->video_capture_message_filter()); 205 AddFilter(vc_manager_->video_capture_message_filter());
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 void RenderThreadImpl::WidgetHidden() { 397 void RenderThreadImpl::WidgetHidden() {
398 DCHECK(hidden_widget_count_ < widget_count_); 398 DCHECK(hidden_widget_count_ < widget_count_);
399 hidden_widget_count_++; 399 hidden_widget_count_++;
400 400
401 if (!content::GetContentClient()->renderer()-> 401 if (!content::GetContentClient()->renderer()->
402 RunIdleHandlerWhenWidgetsHidden()) { 402 RunIdleHandlerWhenWidgetsHidden()) {
403 return; 403 return;
404 } 404 }
405 405
406 if (widget_count_ && hidden_widget_count_ == widget_count_) 406 if (widget_count_ && hidden_widget_count_ == widget_count_)
407 ScheduleIdleHandler(kInitialIdleHandlerDelayS); 407 ScheduleIdleHandler(kInitialIdleHandlerDelayMs);
408 } 408 }
409 409
410 void RenderThreadImpl::WidgetRestored() { 410 void RenderThreadImpl::WidgetRestored() {
411 DCHECK_GT(hidden_widget_count_, 0); 411 DCHECK_GT(hidden_widget_count_, 0);
412 hidden_widget_count_--; 412 hidden_widget_count_--;
413 if (!content::GetContentClient()->renderer()-> 413 if (!content::GetContentClient()->renderer()->
414 RunIdleHandlerWhenWidgetsHidden()) { 414 RunIdleHandlerWhenWidgetsHidden()) {
415 return; 415 return;
416 } 416 }
417 417
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { 542 void RenderThreadImpl::RegisterExtension(v8::Extension* extension) {
543 WebScriptController::registerExtension(extension); 543 WebScriptController::registerExtension(extension);
544 v8_extensions_.insert(extension->name()); 544 v8_extensions_.insert(extension->name());
545 } 545 }
546 546
547 bool RenderThreadImpl::IsRegisteredExtension( 547 bool RenderThreadImpl::IsRegisteredExtension(
548 const std::string& v8_extension_name) const { 548 const std::string& v8_extension_name) const {
549 return v8_extensions_.find(v8_extension_name) != v8_extensions_.end(); 549 return v8_extensions_.find(v8_extension_name) != v8_extensions_.end();
550 } 550 }
551 551
552 void RenderThreadImpl::ScheduleIdleHandler(double initial_delay_s) { 552 void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) {
553 idle_notification_delay_in_s_ = initial_delay_s; 553 idle_notification_delay_in_ms_ = initial_delay_ms;
554 idle_timer_.Stop(); 554 idle_timer_.Stop();
555 idle_timer_.Start(FROM_HERE, 555 idle_timer_.Start(FROM_HERE,
556 base::TimeDelta::FromSeconds(static_cast<int64>(initial_delay_s)), 556 base::TimeDelta::FromMilliseconds(initial_delay_ms),
557 this, &RenderThreadImpl::IdleHandler); 557 this, &RenderThreadImpl::IdleHandler);
558 } 558 }
559 559
560 void RenderThreadImpl::IdleHandler() { 560 void RenderThreadImpl::IdleHandler() {
561 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) 561 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
562 MallocExtension::instance()->ReleaseFreeMemory(); 562 MallocExtension::instance()->ReleaseFreeMemory();
563 #endif 563 #endif
564 564
565 v8::V8::IdleNotification(); 565 v8::V8::IdleNotification();
566 566
567 // Schedule next invocation. 567 // Schedule next invocation.
568 // Dampen the delay using the algorithm: 568 // Dampen the delay using the algorithm (if delay is in seconds):
569 // delay = delay + 1 / (delay + 2) 569 // delay = delay + 1 / (delay + 2)
570 // Using floor(delay) has a dampening effect such as: 570 // Using floor(delay) has a dampening effect such as:
571 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... 571 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ...
572 // Note that idle_notification_delay_in_s_ would be reset to 572 // If the delay is in milliseconds, the above formula is equivalent to:
573 // kInitialIdleHandlerDelayS in RenderThreadImpl::WidgetHidden. 573 // delay_ms / 1000 = delay_ms / 1000 + 1 / (delay_ms / 1000 + 2)
574 ScheduleIdleHandler(idle_notification_delay_in_s_ + 574 // which is equivalent to
575 1.0 / (idle_notification_delay_in_s_ + 2.0)); 575 // delay_ms = delay_ms + 1000*1000 / (delay_ms + 2000).
576 // Note that idle_notification_delay_in_ms_ would be reset to
577 // kInitialIdleHandlerDelayMs in RenderThreadImpl::WidgetHidden.
578 ScheduleIdleHandler(idle_notification_delay_in_ms_ +
579 1000000 / (idle_notification_delay_in_ms_ + 2000));
576 580
577 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); 581 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification());
578 } 582 }
579 583
580 double RenderThreadImpl::GetIdleNotificationDelayInS() const { 584 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const {
581 return idle_notification_delay_in_s_; 585 return idle_notification_delay_in_ms_;
582 } 586 }
583 587
584 void RenderThreadImpl::SetIdleNotificationDelayInS( 588 void RenderThreadImpl::SetIdleNotificationDelayInMs(
585 double idle_notification_delay_in_s) { 589 int64 idle_notification_delay_in_ms) {
586 idle_notification_delay_in_s_ = idle_notification_delay_in_s; 590 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms;
587 } 591 }
588 592
589 #if defined(OS_WIN) 593 #if defined(OS_WIN)
590 void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) { 594 void RenderThreadImpl::PreCacheFont(const LOGFONT& log_font) {
591 Send(new ChildProcessHostMsg_PreCacheFont(log_font)); 595 Send(new ChildProcessHostMsg_PreCacheFont(log_font));
592 } 596 }
593 597
594 void RenderThreadImpl::ReleaseCachedFonts() { 598 void RenderThreadImpl::ReleaseCachedFonts() {
595 Send(new ChildProcessHostMsg_ReleaseCachedFonts()); 599 Send(new ChildProcessHostMsg_ReleaseCachedFonts());
596 } 600 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 786
783 scoped_refptr<base::MessageLoopProxy> 787 scoped_refptr<base::MessageLoopProxy>
784 RenderThreadImpl::GetFileThreadMessageLoopProxy() { 788 RenderThreadImpl::GetFileThreadMessageLoopProxy() {
785 DCHECK(message_loop() == MessageLoop::current()); 789 DCHECK(message_loop() == MessageLoop::current());
786 if (!file_thread_.get()) { 790 if (!file_thread_.get()) {
787 file_thread_.reset(new base::Thread("Renderer::FILE")); 791 file_thread_.reset(new base::Thread("Renderer::FILE"));
788 file_thread_->Start(); 792 file_thread_->Start();
789 } 793 }
790 return file_thread_->message_loop_proxy(); 794 return file_thread_->message_loop_proxy();
791 } 795 }
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | content/test/mock_render_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698