| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" |
| 11 #include "base/lazy_instance.h" |
| 11 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
| 12 #include "base/stats_table.h" | 13 #include "base/stats_table.h" |
| 14 #include "base/thread_local.h" |
| 13 #include "chrome/common/app_cache/app_cache_context_impl.h" | 15 #include "chrome/common/app_cache/app_cache_context_impl.h" |
| 14 #include "chrome/common/app_cache/app_cache_dispatcher.h" | 16 #include "chrome/common/app_cache/app_cache_dispatcher.h" |
| 15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
| 17 #include "chrome/common/renderer_preferences.h" | 19 #include "chrome/common/renderer_preferences.h" |
| 18 #include "chrome/common/notification_service.h" | 20 #include "chrome/common/notification_service.h" |
| 19 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/plugin/npobject_util.h" | 22 #include "chrome/plugin/npobject_util.h" |
| 21 // TODO(port) | 23 // TODO(port) |
| 22 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 50 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| 51 #include <windows.h> | 53 #include <windows.h> |
| 52 #include <objbase.h> | 54 #include <objbase.h> |
| 53 #endif | 55 #endif |
| 54 | 56 |
| 55 using WebKit::WebCache; | 57 using WebKit::WebCache; |
| 56 using WebKit::WebString; | 58 using WebKit::WebString; |
| 57 | 59 |
| 58 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; | 60 static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */; |
| 59 | 61 |
| 62 static base::LazyInstance<base::ThreadLocalPointer<RenderThread> > lazy_tls( |
| 63 base::LINKER_INITIALIZED); |
| 64 |
| 60 //----------------------------------------------------------------------------- | 65 //----------------------------------------------------------------------------- |
| 61 // Methods below are only called on the owner's thread: | 66 // Methods below are only called on the owner's thread: |
| 62 | 67 |
| 63 // When we run plugins in process, we actually run them on the render thread, | 68 // When we run plugins in process, we actually run them on the render thread, |
| 64 // which means that we need to make the render thread pump UI events. | 69 // which means that we need to make the render thread pump UI events. |
| 65 RenderThread::RenderThread() | 70 RenderThread::RenderThread() |
| 66 : ChildThread( | 71 : ChildThread( |
| 67 base::Thread::Options(RenderProcess::InProcessPlugins() ? | 72 base::Thread::Options(RenderProcess::InProcessPlugins() ? |
| 68 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)), | 73 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)), |
| 69 plugin_refresh_allowed_(true) { | 74 plugin_refresh_allowed_(true) { |
| 70 } | 75 } |
| 71 | 76 |
| 72 RenderThread::RenderThread(const std::string& channel_name) | 77 RenderThread::RenderThread(const std::string& channel_name) |
| 73 : ChildThread( | 78 : ChildThread( |
| 74 base::Thread::Options(RenderProcess::InProcessPlugins() ? | 79 base::Thread::Options(RenderProcess::InProcessPlugins() ? |
| 75 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)), | 80 MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kV8StackSize)), |
| 76 plugin_refresh_allowed_(true) { | 81 plugin_refresh_allowed_(true) { |
| 77 SetChannelName(channel_name); | 82 SetChannelName(channel_name); |
| 78 } | 83 } |
| 79 | 84 |
| 80 RenderThread::~RenderThread() { | 85 RenderThread::~RenderThread() { |
| 81 } | 86 } |
| 82 | 87 |
| 83 RenderThread* RenderThread::current() { | 88 RenderThread* RenderThread::current() { |
| 84 DCHECK(!IsPluginProcess()); | 89 return lazy_tls.Pointer()->Get(); |
| 85 return static_cast<RenderThread*>(ChildThread::current()); | |
| 86 } | 90 } |
| 87 | 91 |
| 88 void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { | 92 void RenderThread::AddFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 89 channel()->AddFilter(filter); | 93 channel()->AddFilter(filter); |
| 90 } | 94 } |
| 91 | 95 |
| 92 void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { | 96 void RenderThread::RemoveFilter(IPC::ChannelProxy::MessageFilter* filter) { |
| 93 channel()->RemoveFilter(filter); | 97 channel()->RemoveFilter(filter); |
| 94 } | 98 } |
| 95 | 99 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 121 // the CPU. | 125 // the CPU. |
| 122 // | 126 // |
| 123 // So, we install a filter on the channel so that we can process this event | 127 // So, we install a filter on the channel so that we can process this event |
| 124 // here and kill the process. | 128 // here and kill the process. |
| 125 _exit(0); | 129 _exit(0); |
| 126 } | 130 } |
| 127 }; | 131 }; |
| 128 #endif | 132 #endif |
| 129 | 133 |
| 130 void RenderThread::Init() { | 134 void RenderThread::Init() { |
| 135 lazy_tls.Pointer()->Set(this); |
| 131 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 132 // If you are running plugins in this thread you need COM active but in | 137 // If you are running plugins in this thread you need COM active but in |
| 133 // the normal case you don't. | 138 // the normal case you don't. |
| 134 if (RenderProcess::InProcessPlugins()) | 139 if (RenderProcess::InProcessPlugins()) |
| 135 CoInitialize(0); | 140 CoInitialize(0); |
| 136 #endif | 141 #endif |
| 137 | 142 |
| 138 ChildThread::Init(); | 143 ChildThread::Init(); |
| 139 notification_service_.reset(new NotificationService); | 144 notification_service_.reset(new NotificationService); |
| 140 cache_stats_factory_.reset( | 145 cache_stats_factory_.reset( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 165 dns_master_.reset(); | 170 dns_master_.reset(); |
| 166 user_script_slave_.reset(); | 171 user_script_slave_.reset(); |
| 167 visited_link_slave_.reset(); | 172 visited_link_slave_.reset(); |
| 168 | 173 |
| 169 if (webkit_client_.get()) { | 174 if (webkit_client_.get()) { |
| 170 WebKit::shutdown(); | 175 WebKit::shutdown(); |
| 171 webkit_client_.reset(); | 176 webkit_client_.reset(); |
| 172 } | 177 } |
| 173 | 178 |
| 174 notification_service_.reset(); | 179 notification_service_.reset(); |
| 175 | |
| 176 ChildThread::CleanUp(); | 180 ChildThread::CleanUp(); |
| 181 lazy_tls.Pointer()->Set(NULL); |
| 177 | 182 |
| 178 // TODO(port) | 183 // TODO(port) |
| 179 #if defined(OS_WIN) | 184 #if defined(OS_WIN) |
| 180 // Clean up plugin channels before this thread goes away. | 185 // Clean up plugin channels before this thread goes away. |
| 181 PluginChannelBase::CleanupChannels(); | 186 PluginChannelBase::CleanupChannels(); |
| 182 // Don't call COM if the renderer is in the sandbox. | 187 // Don't call COM if the renderer is in the sandbox. |
| 183 if (RenderProcess::InProcessPlugins()) | 188 if (RenderProcess::InProcessPlugins()) |
| 184 CoUninitialize(); | 189 CoUninitialize(); |
| 185 #endif | 190 #endif |
| 186 } | 191 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 399 |
| 395 void RenderThread::OnPurgePluginListCache() { | 400 void RenderThread::OnPurgePluginListCache() { |
| 396 // The call below will cause a GetPlugins call with refresh=true, but at this | 401 // The call below will cause a GetPlugins call with refresh=true, but at this |
| 397 // point we already know that the browser has refreshed its list, so disable | 402 // point we already know that the browser has refreshed its list, so disable |
| 398 // refresh temporarily to prevent each renderer process causing the list to be | 403 // refresh temporarily to prevent each renderer process causing the list to be |
| 399 // regenerated. | 404 // regenerated. |
| 400 plugin_refresh_allowed_ = false; | 405 plugin_refresh_allowed_ = false; |
| 401 WebKit::resetPluginCache(); | 406 WebKit::resetPluginCache(); |
| 402 plugin_refresh_allowed_ = true; | 407 plugin_refresh_allowed_ = true; |
| 403 } | 408 } |
| OLD | NEW |