summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-18 23:39:02 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-18 23:39:02 +0000
commit1d97d2e32c0912611926a7364b5350593d713906 (patch)
tree40136fca534855d1dac7b2243f52d70ce683c33c /chrome
parent8a31b03c82d432b6554e17f2e0bec59ca90a40df (diff)
downloadchromium_src-1d97d2e32c0912611926a7364b5350593d713906.zip
chromium_src-1d97d2e32c0912611926a7364b5350593d713906.tar.gz
chromium_src-1d97d2e32c0912611926a7364b5350593d713906.tar.bz2
Make the global render thread object a regular global object rather than a
special TLS value. This is slightly faster for this commonly-used function, and we don't ever have more than one (it's like this because we were originally planning on having more than one RenderThread). BUG=5635 Review URL: http://codereview.chromium.org/15052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7272 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/renderer/chrome_plugin_host.cc8
-rw-r--r--chrome/renderer/net/render_dns_master.cc8
-rw-r--r--chrome/renderer/render_thread.cc20
-rw-r--r--chrome/renderer/render_thread.h12
-rw-r--r--chrome/renderer/render_view.cc16
-rw-r--r--chrome/renderer/render_widget.h2
-rw-r--r--chrome/renderer/renderer_glue.cc38
-rw-r--r--chrome/renderer/webplugin_delegate_proxy.cc8
8 files changed, 51 insertions, 61 deletions
diff --git a/chrome/renderer/chrome_plugin_host.cc b/chrome/renderer/chrome_plugin_host.cc
index 5caa99c..bd84b26 100644
--- a/chrome/renderer/chrome_plugin_host.cc
+++ b/chrome/renderer/chrome_plugin_host.cc
@@ -318,7 +318,7 @@ int STDCALL CPB_GetBrowsingContextInfo(
return sizeof(char*);
std::wstring wretval;
- if (!RenderThread::current()->Send(new ViewHostMsg_GetDataDir(&wretval)))
+ if (!g_render_thread->Send(new ViewHostMsg_GetDataDir(&wretval)))
return CPERR_FAILURE;
file_util::AppendToPath(&wretval, chrome::kChromePluginDataDirname);
*static_cast<char**>(buf) = CPB_StringDup(CPB_Alloc, WideToUTF8(wretval));
@@ -489,8 +489,8 @@ CPError STDCALL CPB_SendMessage(CPID id, const void *data, uint32 data_len) {
const uint8* data_ptr = static_cast<const uint8*>(data);
std::vector<uint8> v(data_ptr, data_ptr + data_len);
- if (!RenderThread::current()->Send(new ViewHostMsg_PluginMessage(
- plugin->filename(), v))) {
+ if (!g_render_thread->Send(new ViewHostMsg_PluginMessage(plugin->filename(),
+ v))) {
return CPERR_FAILURE;
}
return CPERR_SUCCESS;
@@ -505,7 +505,7 @@ CPError STDCALL CPB_SendSyncMessage(CPID id, const void *data, uint32 data_len,
const uint8* data_ptr = static_cast<const uint8*>(data);
std::vector<uint8> v(data_ptr, data_ptr + data_len);
std::vector<uint8> r;
- if (!RenderThread::current()->Send(new ViewHostMsg_PluginSyncMessage(
+ if (!g_render_thread->Send(new ViewHostMsg_PluginSyncMessage(
plugin->filename(), v, &r))) {
return CPERR_FAILURE;
}
diff --git a/chrome/renderer/net/render_dns_master.cc b/chrome/renderer/net/render_dns_master.cc
index 0ae4851..736c81e 100644
--- a/chrome/renderer/net/render_dns_master.cc
+++ b/chrome/renderer/net/render_dns_master.cc
@@ -19,7 +19,7 @@
// This API is used in the render process by renderer_glue.cc.
// IF you are in the render process, you MUST be on the renderer thread to call.
void DnsPrefetchCString(const char* hostname, size_t length) {
- RenderThread::current()->Resolve(hostname, length);
+ g_render_thread->Resolve(hostname, length);
}
// The number of hostnames submitted to Browser DNS resolver per call to
@@ -58,7 +58,7 @@ void RenderDnsMaster::Resolve(const char* name, size_t length) {
if (0 != old_size)
return; // Overkill safety net: Don't send too many InvokeLater's.
render_dns_factory_.RevokeAll();
- RenderThread::current()->message_loop()->PostDelayedTask(FROM_HERE,
+ g_render_thread->message_loop()->PostDelayedTask(FROM_HERE,
render_dns_factory_.NewRunnableMethod(
&RenderDnsMaster::SubmitHostnames), 10);
}
@@ -92,7 +92,7 @@ void RenderDnsMaster::SubmitHostnames() {
DnsPrefetchNames(kMAX_SUBMISSION_PER_TASK);
if (new_name_count_ > 0 || 0 < c_string_queue_.Size()) {
render_dns_factory_.RevokeAll();
- RenderThread::current()->message_loop()->PostDelayedTask(FROM_HERE,
+ g_render_thread->message_loop()->PostDelayedTask(FROM_HERE,
render_dns_factory_.NewRunnableMethod(
&RenderDnsMaster::SubmitHostnames), 10);
} else {
@@ -148,7 +148,7 @@ void RenderDnsMaster::DnsPrefetchNames(size_t max_count) {
new_name_count_ -= names.size();
DCHECK(new_name_count_ >= 0);
- RenderThread::current()->Send(new ViewHostMsg_DnsPrefetch(names));
+ g_render_thread->Send(new ViewHostMsg_DnsPrefetch(names));
}
// is_numeric_ip() checks to see if all characters in name are either numeric,
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 60ac402..9a4e4ed 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -7,9 +7,7 @@
#include "chrome/renderer/render_thread.h"
-#include "base/lazy_instance.h"
#include "base/shared_memory.h"
-#include "base/thread_local.h"
#include "chrome/common/chrome_plugin_lib.h"
#include "chrome/common/ipc_logging.h"
#include "chrome/common/notification_service.h"
@@ -21,22 +19,16 @@
#include "chrome/renderer/visitedlink_slave.h"
#include "webkit/glue/cache_manager.h"
+RenderThread* g_render_thread;
+
static const unsigned int kCacheStatsDelayMS = 2000 /* milliseconds */;
// V8 needs a 1MB stack size.
static const size_t kStackSize = 1024 * 1024;
-static base::LazyInstance<base::ThreadLocalPointer<RenderThread> >
- lazy_tls_ptr(base::LINKER_INITIALIZED);
-
//-----------------------------------------------------------------------------
// Methods below are only called on the owner's thread:
-// static
-RenderThread* RenderThread::current() {
- return lazy_tls_ptr.Pointer()->Get();
-}
-
RenderThread::RenderThread(const std::wstring& channel_name)
: Thread("Chrome_RenderThread"),
channel_name_(channel_name),
@@ -97,7 +89,8 @@ void RenderThread::RemoveRoute(int32 routing_id) {
}
void RenderThread::Init() {
- DCHECK(!current()) << "should only have one RenderThread per thread";
+ DCHECK(!g_render_thread);
+ g_render_thread = this;
notification_service_.reset(new NotificationService);
@@ -108,8 +101,6 @@ void RenderThread::Init() {
IPC::Channel::MODE_CLIENT, this, NULL, owner_loop_, true,
RenderProcess::GetShutDownEvent()));
- lazy_tls_ptr.Pointer()->Set(this);
-
// The renderer thread should wind-up COM.
CoInitialize(0);
@@ -124,7 +115,8 @@ void RenderThread::Init() {
}
void RenderThread::CleanUp() {
- DCHECK(current() == this);
+ DCHECK(g_render_thread == this);
+ g_render_thread = NULL;
// Need to destruct the SyncChannel to the browser before we go away because
// it caches a pointer to this thread.
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 6de92324..68c51cf 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_RENDERER_RENDER_THREAD_H__
-#define CHROME_RENDERER_RENDER_THREAD_H__
+#ifndef CHROME_RENDERER_RENDER_THREAD_H_
+#define CHROME_RENDERER_RENDER_THREAD_H_
#include "base/ref_counted.h"
#include "base/shared_memory.h"
@@ -62,9 +62,6 @@ class RenderThread : public IPC::Channel::Listener,
void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
void RemoveFilter(IPC::ChannelProxy::MessageFilter* filter);
- // The RenderThread instance for the current thread.
- static RenderThread* current();
-
// Gets the VisitedLinkSlave instance for this thread
VisitedLinkSlave* visited_link_slave() const { return visited_link_slave_; }
@@ -139,5 +136,8 @@ class RenderThread : public IPC::Channel::Listener,
DISALLOW_EVIL_CONSTRUCTORS(RenderThread);
};
-#endif // CHROME_RENDERER_RENDER_THREAD_H__
+// The global RenderThread object for this process. Note that this should only
+// be accessed when running on the render thread itself.
+extern RenderThread* g_render_thread;
+#endif // CHROME_RENDERER_RENDER_THREAD_H_
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 2289d61..161c482 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -143,7 +143,7 @@ class RenderViewExtraRequestData : public WebRequest::ExtraData {
///////////////////////////////////////////////////////////////////////////////
RenderView::RenderView()
- : RenderWidget(RenderThread::current(), true),
+ : RenderWidget(g_render_thread, true),
is_loading_(false),
page_id_(-1),
last_page_id_sent_to_browser_(-1),
@@ -183,7 +183,7 @@ RenderView::~RenderView() {
it = plugin_delegates_.erase(it);
}
- RenderThread::current()->RemoveFilter(debug_message_handler_);
+ g_render_thread->RemoveFilter(debug_message_handler_);
#ifdef CHROME_PERSONALIZATION
Personalization::CleanupRendererPersonalization(personalization_);
@@ -271,7 +271,7 @@ void RenderView::Init(HWND parent_hwnd,
webview()->SetBackForwardListSize(1);
routing_id_ = routing_id;
- RenderThread::current()->AddRoute(routing_id_, this);
+ g_render_thread->AddRoute(routing_id_, this);
// Take a reference on behalf of the RenderThread. This will be balanced
// when we receive ViewMsg_Close.
AddRef();
@@ -295,7 +295,7 @@ void RenderView::Init(HWND parent_hwnd,
command_line.HasSwitch(switches::kEnableGreasemonkey);
debug_message_handler_ = new DebugMessageHandler(this);
- RenderThread::current()->AddFilter(debug_message_handler_);
+ g_render_thread->AddFilter(debug_message_handler_);
}
void RenderView::OnMessageReceived(const IPC::Message& message) {
@@ -1461,7 +1461,7 @@ void RenderView::DidFinishDocumentLoadForFrame(WebView* webview,
if (gurl.SchemeIs("file") ||
gurl.SchemeIs("http") ||
gurl.SchemeIs("https")) {
- RenderThread::current()->greasemonkey_slave()->InjectScripts(frame);
+ g_render_thread->greasemonkey_slave()->InjectScripts(frame);
}
}
}
@@ -1785,7 +1785,7 @@ WebView* RenderView::CreateWebView(WebView* webview, bool user_gesture) {
int32 routing_id = MSG_ROUTING_NONE;
HANDLE modal_dialog_event = NULL;
- bool result = RenderThread::current()->Send(
+ bool result = g_render_thread->Send(
new ViewHostMsg_CreateWindow(routing_id_, user_gesture, &routing_id,
&modal_dialog_event));
if (routing_id == MSG_ROUTING_NONE) {
@@ -1811,7 +1811,7 @@ WebView* RenderView::CreateWebView(WebView* webview, bool user_gesture) {
WebWidget* RenderView::CreatePopupWidget(WebView* webview,
bool focus_on_show) {
RenderWidget* widget = RenderWidget::Create(routing_id_,
- RenderThread::current(),
+ g_render_thread,
focus_on_show);
return widget->webwidget();
}
@@ -1839,7 +1839,7 @@ WebPluginDelegate* RenderView::CreatePluginDelegate(
bool is_gears = false;
if (ShouldLoadPluginInProcess(mime_type, &is_gears)) {
std::wstring path;
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_GetPluginPath(url, mime_type, clsid, &path,
actual_mime_type));
if (path.empty())
diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h
index e3a750e..8eefe47 100644
--- a/chrome/renderer/render_widget.h
+++ b/chrome/renderer/render_widget.h
@@ -29,7 +29,7 @@ class RenderWidget : public IPC::Channel::Listener,
public:
// Creates a new RenderWidget. The opener_id is the routing ID of the
// RenderView that this widget lives inside. The render_thread is any
- // RenderThreadBase implementation, mostly commonly RenderThread::current().
+ // RenderThreadBase implementation, mostly commonly g_render_thread.
static RenderWidget* Create(int32 opener_id,
RenderThreadBase* render_thread,
bool focus_on_show);
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index 44b2f01..7516ace 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -122,14 +122,14 @@ ScopedClipboardWriterGlue::~ScopedClipboardWriterGlue() {
#if defined(OS_WIN)
if (shared_buf_) {
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_ClipboardWriteObjectsSync(objects_));
RenderProcess::FreeSharedMemory(shared_buf_);
return;
}
#endif
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_ClipboardWriteObjectsAsync(objects_));
}
@@ -163,7 +163,7 @@ bool webkit_glue::GetMimeTypeFromExtension(const std::wstring &ext,
// The sandbox restricts our access to the registry, so we need to proxy
// these calls over to the browser process.
DCHECK(mime_type->empty());
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_GetMimeTypeFromExtension(ext, mime_type));
return !mime_type->empty();
}
@@ -176,7 +176,7 @@ bool webkit_glue::GetMimeTypeFromFile(const std::wstring &file_path,
// The sandbox restricts our access to the registry, so we need to proxy
// these calls over to the browser process.
DCHECK(mime_type->empty());
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_GetMimeTypeFromFile(file_path, mime_type));
return !mime_type->empty();
}
@@ -189,7 +189,7 @@ bool webkit_glue::GetPreferredExtensionForMimeType(const std::string& mime_type,
// The sandbox restricts our access to the registry, so we need to proxy
// these calls over to the browser process.
DCHECK(ext->empty());
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_GetPreferredExtensionForMimeType(mime_type, ext));
return !ext->empty();
}
@@ -214,21 +214,21 @@ Clipboard* webkit_glue::ClipboardGetClipboard(){
bool webkit_glue::ClipboardIsFormatAvailable(unsigned int format) {
bool result;
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_ClipboardIsFormatAvailable(format, &result));
return result;
}
void webkit_glue::ClipboardReadText(std::wstring* result) {
- RenderThread::current()->Send(new ViewHostMsg_ClipboardReadText(result));
+ g_render_thread->Send(new ViewHostMsg_ClipboardReadText(result));
}
void webkit_glue::ClipboardReadAsciiText(std::string* result) {
- RenderThread::current()->Send(new ViewHostMsg_ClipboardReadAsciiText(result));
+ g_render_thread->Send(new ViewHostMsg_ClipboardReadAsciiText(result));
}
void webkit_glue::ClipboardReadHTML(std::wstring* markup, GURL* url) {
- RenderThread::current()->Send(new ViewHostMsg_ClipboardReadHTML(markup, url));
+ g_render_thread->Send(new ViewHostMsg_ClipboardReadHTML(markup, url));
}
GURL webkit_glue::GetInspectorURL() {
@@ -241,30 +241,30 @@ std::string webkit_glue::GetUIResourceProtocol() {
bool webkit_glue::GetPlugins(bool refresh,
std::vector<WebPluginInfo>* plugins) {
- return RenderThread::current()->Send(
+ return g_render_thread->Send(
new ViewHostMsg_GetPlugins(refresh, plugins));
}
bool webkit_glue::EnsureFontLoaded(HFONT font) {
LOGFONT logfont;
GetObject(font, sizeof(LOGFONT), &logfont);
- return RenderThread::current()->Send(new ViewHostMsg_LoadFont(logfont));
+ return g_render_thread->Send(new ViewHostMsg_LoadFont(logfont));
}
webkit_glue::ScreenInfo webkit_glue::GetScreenInfo(gfx::NativeView window) {
webkit_glue::ScreenInfo results;
- RenderThread::current()->Send(
+ g_render_thread->Send(
new ViewHostMsg_GetScreenInfo(window, &results));
return results;
}
uint64 webkit_glue::VisitedLinkHash(const char* canonical_url, size_t length) {
- return RenderThread::current()->visited_link_slave()->ComputeURLFingerprint(
+ return g_render_thread->visited_link_slave()->ComputeURLFingerprint(
canonical_url, length);
}
bool webkit_glue::IsLinkVisited(uint64 link_hash) {
- return RenderThread::current()->visited_link_slave()->IsVisited(link_hash);
+ return g_render_thread->visited_link_slave()->IsVisited(link_hash);
}
#ifndef USING_SIMPLE_RESOURCE_LOADER_BRIDGE
@@ -311,14 +311,12 @@ ResourceLoaderBridge* ResourceLoaderBridge::Create(
void SetCookie(const GURL& url, const GURL& policy_url,
const std::string& cookie) {
- RenderThread::current()->Send(new ViewHostMsg_SetCookie(url, policy_url,
- cookie));
+ g_render_thread->Send(new ViewHostMsg_SetCookie(url, policy_url, cookie));
}
std::string GetCookies(const GURL& url, const GURL& policy_url) {
std::string cookies;
- RenderThread::current()->Send(new ViewHostMsg_GetCookies(url, policy_url,
- &cookies));
+ g_render_thread->Send(new ViewHostMsg_GetCookies(url, policy_url, &cookies));
return cookies;
}
@@ -326,8 +324,8 @@ void NotifyCacheStats() {
// Update the browser about our cache
// NOTE: Since this can be called from the plugin process, we might not have
// a RenderThread. Do nothing in that case.
- if (RenderThread::current())
- RenderThread::current()->InformHostOfCacheStatsLater();
+ if (g_render_thread)
+ g_render_thread->InformHostOfCacheStatsLater();
}
#endif // !USING_SIMPLE_RESOURCE_LOADER_BRIDGE
diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc
index a268edf..b5c92a5 100644
--- a/chrome/renderer/webplugin_delegate_proxy.cc
+++ b/chrome/renderer/webplugin_delegate_proxy.cc
@@ -208,12 +208,12 @@ bool WebPluginDelegateProxy::Initialize(const GURL& url, char** argn,
WebPlugin* plugin,
bool load_manually) {
std::wstring channel_name, plugin_path;
- if (!RenderThread::current()->Send(new ViewHostMsg_OpenChannelToPlugin(
- url, mime_type_, clsid_, webkit_glue::GetWebKitLocale(),
- &channel_name, &plugin_path)))
+ if (!g_render_thread->Send(new ViewHostMsg_OpenChannelToPlugin(
+ url, mime_type_, clsid_, webkit_glue::GetWebKitLocale(),
+ &channel_name, &plugin_path)))
return false;
- MessageLoop* ipc_message_loop = RenderThread::current()->owner_loop();
+ MessageLoop* ipc_message_loop = g_render_thread->owner_loop();
scoped_refptr<PluginChannelHost> channel_host =
PluginChannelHost::GetPluginChannelHost(channel_name, ipc_message_loop);
if (!channel_host.get())