| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/field_trial.h" |
| 13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/nullable_string16.h" | 16 #include "base/nullable_string16.h" |
| 16 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 17 #include "base/shared_memory.h" | 18 #include "base/shared_memory.h" |
| 18 #include "base/stats_table.h" | 19 #include "base/stats_table.h" |
| 19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 20 #include "base/task.h" | 21 #include "base/task.h" |
| 21 #include "base/thread_local.h" | 22 #include "base/thread_local.h" |
| 22 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 using WebKit::WebString; | 110 using WebKit::WebString; |
| 110 using WebKit::WebStorageEventDispatcher; | 111 using WebKit::WebStorageEventDispatcher; |
| 111 using WebKit::WebView; | 112 using WebKit::WebView; |
| 112 | 113 |
| 113 namespace { | 114 namespace { |
| 114 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; | 115 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; |
| 115 static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; | 116 static const double kInitialIdleHandlerDelayS = 1.0 /* seconds */; |
| 116 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; | 117 static const double kInitialExtensionIdleHandlerDelayS = 5.0 /* seconds */; |
| 117 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; | 118 static const int64 kMaxExtensionIdleHandlerDelayS = 5*60 /* seconds */; |
| 118 | 119 |
| 120 static const int kPrelauchGpuPercentage = 5; |
| 121 static const int kPrelauchGpuProcessDelayMS = 10000; |
| 122 |
| 119 // Keep the global RenderThread in a TLS slot so it is impossible to access | 123 // Keep the global RenderThread in a TLS slot so it is impossible to access |
| 120 // incorrectly from the wrong thread. | 124 // incorrectly from the wrong thread. |
| 121 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( | 125 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( |
| 122 base::LINKER_INITIALIZED); | 126 base::LINKER_INITIALIZED); |
| 123 | 127 |
| 124 #if defined(OS_POSIX) | 128 #if defined(OS_POSIX) |
| 125 class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { | 129 class SuicideOnChannelErrorFilter : public IPC::ChannelProxy::MessageFilter { |
| 126 void OnChannelError() { | 130 void OnChannelError() { |
| 127 // On POSIX, at least, one can install an unload handler which loops | 131 // On POSIX, at least, one can install an unload handler which loops |
| 128 // forever and leave behind a renderer process which eats 100% CPU forever. | 132 // forever and leave behind a renderer process which eats 100% CPU forever. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 cookie_message_filter_ = new CookieMessageFilter(); | 265 cookie_message_filter_ = new CookieMessageFilter(); |
| 262 AddFilter(cookie_message_filter_.get()); | 266 AddFilter(cookie_message_filter_.get()); |
| 263 | 267 |
| 264 #if defined(OS_POSIX) | 268 #if defined(OS_POSIX) |
| 265 suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter; | 269 suicide_on_channel_error_filter_ = new SuicideOnChannelErrorFilter; |
| 266 AddFilter(suicide_on_channel_error_filter_.get()); | 270 AddFilter(suicide_on_channel_error_filter_.get()); |
| 267 #endif | 271 #endif |
| 268 | 272 |
| 269 // Establish a channel to the GPU process asynchronously if requested. If the | 273 // Establish a channel to the GPU process asynchronously if requested. If the |
| 270 // channel is established in time, EstablishGpuChannelSync will not block when | 274 // channel is established in time, EstablishGpuChannelSync will not block when |
| 271 // it is later called. | 275 // it is later called. Delays by a fixed period of time to avoid loading the |
| 272 if (CommandLine::ForCurrentProcess()->HasSwitch( | 276 // GPU immediately in an attempt to not slow startup time. |
| 273 switches::kPrelaunchGpuProcess)) { | 277 scoped_refptr<FieldTrial> prelaunch_trial( |
| 274 EstablishGpuChannel(); | 278 new FieldTrial("PrelaunchGpuProcessExperiment", 100)); |
| 279 int prelaunch_group = prelaunch_trial->AppendGroup("prelaunch_gpu_process", |
| 280 kPrelauchGpuPercentage); |
| 281 if (prelaunch_group == prelaunch_trial->group() || |
| 282 CommandLine::ForCurrentProcess()->HasSwitch( |
| 283 switches::kPrelaunchGpuProcess)) { |
| 284 message_loop()->PostDelayedTask(FROM_HERE, |
| 285 task_factory_->NewRunnableMethod( |
| 286 &RenderThread::EstablishGpuChannel), |
| 287 kPrelauchGpuProcessDelayMS); |
| 275 } | 288 } |
| 276 } | 289 } |
| 277 | 290 |
| 278 RenderThread::~RenderThread() { | 291 RenderThread::~RenderThread() { |
| 279 // Wait for all databases to be closed. | 292 // Wait for all databases to be closed. |
| 280 if (web_database_observer_impl_.get()) | 293 if (web_database_observer_impl_.get()) |
| 281 web_database_observer_impl_->WaitForAllDatabasesToClose(); | 294 web_database_observer_impl_->WaitForAllDatabasesToClose(); |
| 282 | 295 |
| 283 // Shutdown in reverse of the initialization order. | 296 // Shutdown in reverse of the initialization order. |
| 284 RemoveFilter(db_message_filter_.get()); | 297 RemoveFilter(db_message_filter_.get()); |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 } | 1080 } |
| 1068 | 1081 |
| 1069 std::string RenderThread::GetExtensionIdByBrowseExtent(const GURL& url) { | 1082 std::string RenderThread::GetExtensionIdByBrowseExtent(const GURL& url) { |
| 1070 for (size_t i = 0; i < extension_extents_.size(); ++i) { | 1083 for (size_t i = 0; i < extension_extents_.size(); ++i) { |
| 1071 if (extension_extents_[i].browse_extent.ContainsURL(url)) | 1084 if (extension_extents_[i].browse_extent.ContainsURL(url)) |
| 1072 return extension_extents_[i].extension_id; | 1085 return extension_extents_[i].extension_id; |
| 1073 } | 1086 } |
| 1074 | 1087 |
| 1075 return std::string(); | 1088 return std::string(); |
| 1076 } | 1089 } |
| OLD | NEW |