| OLD | NEW |
| 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 idle_notification_delay_in_s_ = initial_delay_s; | 553 idle_notification_delay_in_s_ = initial_delay_s; |
| 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::FromSeconds(static_cast<int64>(initial_delay_s)), |
| 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 if (hidden_widget_count_ < widget_count_ && |
| 566 content::GetContentClient()->renderer()->RunIdleHandlerWhenUserIdle()) { |
| 567 if (!v8::V8::IdleNotification()) { |
| 568 ScheduleIdleHandler(kInitialIdleHandlerDelayS); |
| 569 } else { |
| 570 idle_timer_.Stop(); |
| 571 } |
| 572 } else { |
| 573 v8::V8::IdleNotification(); |
| 566 | 574 |
| 567 // Schedule next invocation. | 575 // Schedule next invocation. |
| 568 // Dampen the delay using the algorithm: | 576 // Dampen the delay using the algorithm: |
| 569 // delay = delay + 1 / (delay + 2) | 577 // delay = delay + 1 / (delay + 2) |
| 570 // Using floor(delay) has a dampening effect such as: | 578 // Using floor(delay) has a dampening effect such as: |
| 571 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... | 579 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
| 572 // Note that idle_notification_delay_in_s_ would be reset to | 580 // Note that idle_notification_delay_in_s_ would be reset to |
| 573 // kInitialIdleHandlerDelayS in RenderThreadImpl::WidgetHidden. | 581 // kInitialIdleHandlerDelayS in RenderThreadImpl::WidgetHidden. |
| 574 ScheduleIdleHandler(idle_notification_delay_in_s_ + | 582 ScheduleIdleHandler(idle_notification_delay_in_s_ + |
| 575 1.0 / (idle_notification_delay_in_s_ + 2.0)); | 583 1.0 / (idle_notification_delay_in_s_ + 2.0)); |
| 576 | 584 |
| 577 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); | 585 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); |
| 586 } |
| 578 } | 587 } |
| 579 | 588 |
| 580 double RenderThreadImpl::GetIdleNotificationDelayInS() const { | 589 double RenderThreadImpl::GetIdleNotificationDelayInS() const { |
| 581 return idle_notification_delay_in_s_; | 590 return idle_notification_delay_in_s_; |
| 582 } | 591 } |
| 583 | 592 |
| 584 void RenderThreadImpl::SetIdleNotificationDelayInS( | 593 void RenderThreadImpl::SetIdleNotificationDelayInS( |
| 585 double idle_notification_delay_in_s) { | 594 double idle_notification_delay_in_s) { |
| 586 idle_notification_delay_in_s_ = idle_notification_delay_in_s; | 595 idle_notification_delay_in_s_ = idle_notification_delay_in_s; |
| 587 } | 596 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 | 791 |
| 783 scoped_refptr<base::MessageLoopProxy> | 792 scoped_refptr<base::MessageLoopProxy> |
| 784 RenderThreadImpl::GetFileThreadMessageLoopProxy() { | 793 RenderThreadImpl::GetFileThreadMessageLoopProxy() { |
| 785 DCHECK(message_loop() == MessageLoop::current()); | 794 DCHECK(message_loop() == MessageLoop::current()); |
| 786 if (!file_thread_.get()) { | 795 if (!file_thread_.get()) { |
| 787 file_thread_.reset(new base::Thread("Renderer::FILE")); | 796 file_thread_.reset(new base::Thread("Renderer::FILE")); |
| 788 file_thread_->Start(); | 797 file_thread_->Start(); |
| 789 } | 798 } |
| 790 return file_thread_->message_loop_proxy(); | 799 return file_thread_->message_loop_proxy(); |
| 791 } | 800 } |
| 801 |
| OLD | NEW |