| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/render_thread.h" | 5 #include "chrome/renderer/render_thread.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "chrome/renderer/renderer_webkitclient_impl.h" | 41 #include "chrome/renderer/renderer_webkitclient_impl.h" |
| 42 #include "chrome/renderer/user_script_slave.h" | 42 #include "chrome/renderer/user_script_slave.h" |
| 43 #include "webkit/api/public/WebColor.h" | 43 #include "webkit/api/public/WebColor.h" |
| 44 #include "webkit/api/public/WebCache.h" | 44 #include "webkit/api/public/WebCache.h" |
| 45 #include "webkit/api/public/WebKit.h" | 45 #include "webkit/api/public/WebKit.h" |
| 46 #include "webkit/api/public/WebString.h" | 46 #include "webkit/api/public/WebString.h" |
| 47 #include "webkit/extensions/v8/benchmarking_extension.h" | 47 #include "webkit/extensions/v8/benchmarking_extension.h" |
| 48 #include "webkit/extensions/v8/gears_extension.h" | 48 #include "webkit/extensions/v8/gears_extension.h" |
| 49 #include "webkit/extensions/v8/interval_extension.h" | 49 #include "webkit/extensions/v8/interval_extension.h" |
| 50 #include "webkit/extensions/v8/playback_extension.h" | 50 #include "webkit/extensions/v8/playback_extension.h" |
| 51 #include "third_party/tcmalloc/google/malloc_extension.h" |
| 51 | 52 |
| 52 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| 53 #include <windows.h> | 54 #include <windows.h> |
| 54 #include <objbase.h> | 55 #include <objbase.h> |
| 55 #endif | 56 #endif |
| 56 | 57 |
| 57 using WebKit::WebCache; | 58 using WebKit::WebCache; |
| 58 using WebKit::WebString; | 59 using WebKit::WebString; |
| 59 | 60 |
| 60 namespace { | 61 namespace { |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (RenderProcess::current()->initialized_media_library()) | 453 if (RenderProcess::current()->initialized_media_library()) |
| 453 WebKit::enableMediaPlayer(); | 454 WebKit::enableMediaPlayer(); |
| 454 } | 455 } |
| 455 | 456 |
| 456 void RenderThread::IdleHandler() { | 457 void RenderThread::IdleHandler() { |
| 457 // It is possible that the timer was set while the widgets were idle, | 458 // It is possible that the timer was set while the widgets were idle, |
| 458 // but that they are no longer idle. If so, just return. | 459 // but that they are no longer idle. If so, just return. |
| 459 if (!widget_count_ || hidden_widget_count_ < widget_count_) | 460 if (!widget_count_ || hidden_widget_count_ < widget_count_) |
| 460 return; | 461 return; |
| 461 | 462 |
| 462 if (v8::V8::IsDead()) | 463 #if defined(OS_WIN) |
| 463 return; | 464 MallocExtension::instance()->Scavenge(); |
| 465 #endif |
| 464 | 466 |
| 465 LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this; | 467 if (!v8::V8::IsDead()) { |
| 468 LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this; |
| 469 v8::V8::IdleNotification(false); |
| 470 } |
| 466 | 471 |
| 467 // When V8::IdleNotification returns true, it means that it has cleaned up | 472 // Schedule next invocation. |
| 468 // as much as it can. There is no point in continuing to call it. | 473 // Dampen the delay using the algorithm: |
| 469 if (!v8::V8::IdleNotification(false)) { | 474 // delay = delay + 1 / (delay + 2) |
| 470 // Dampen the delay using the algorithm: | 475 // Using floor(delay) has a dampening effect such as: |
| 471 // delay = delay + 1 / (delay + 2) | 476 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... |
| 472 // Using floor(delay) has a dampening effect such as: | 477 // Note that idle_notification_delay_in_s_ would be reset to |
| 473 // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... | 478 // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden. |
| 474 idle_notification_delay_in_s_ += | 479 idle_notification_delay_in_s_ += |
| 475 1.0 / (idle_notification_delay_in_s_ + 2.0); | 480 1.0 / (idle_notification_delay_in_s_ + 2.0); |
| 476 | 481 |
| 477 // Schedule the next timer. | 482 // Schedule the next timer. |
| 478 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 483 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 479 task_factory_->NewRunnableMethod(&RenderThread::IdleHandler), | 484 task_factory_->NewRunnableMethod(&RenderThread::IdleHandler), |
| 480 static_cast<int64>(floor(idle_notification_delay_in_s_)) * 1000); | 485 static_cast<int64>(floor(idle_notification_delay_in_s_)) * 1000); |
| 481 } | |
| 482 } | 486 } |
| 483 | 487 |
| 484 void RenderThread::OnExtensionMessageInvoke(const std::string& function_name, | 488 void RenderThread::OnExtensionMessageInvoke(const std::string& function_name, |
| 485 const ListValue& args) { | 489 const ListValue& args) { |
| 486 RendererExtensionBindings::Invoke(function_name, args, NULL); | 490 RendererExtensionBindings::Invoke(function_name, args, NULL); |
| 487 } | 491 } |
| 488 | 492 |
| 489 void RenderThread::OnPurgePluginListCache() { | 493 void RenderThread::OnPurgePluginListCache() { |
| 490 // The call below will cause a GetPlugins call with refresh=true, but at this | 494 // The call below will cause a GetPlugins call with refresh=true, but at this |
| 491 // point we already know that the browser has refreshed its list, so disable | 495 // point we already know that the browser has refreshed its list, so disable |
| 492 // refresh temporarily to prevent each renderer process causing the list to be | 496 // refresh temporarily to prevent each renderer process causing the list to be |
| 493 // regenerated. | 497 // regenerated. |
| 494 plugin_refresh_allowed_ = false; | 498 plugin_refresh_allowed_ = false; |
| 495 WebKit::resetPluginCache(); | 499 WebKit::resetPluginCache(); |
| 496 plugin_refresh_allowed_ = true; | 500 plugin_refresh_allowed_ = true; |
| 497 } | 501 } |
| OLD | NEW |