summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-31 03:00:41 +0000
committerapatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-31 03:00:41 +0000
commitbf531bdbdf853614f7e9e97b0a0be761b4dfb532 (patch)
tree1bf2184045b9abca7df1bc0318a704e58315d0b9 /content
parent8572987bc6919b6f9dd69edf77c3e366629b2746 (diff)
downloadchromium_src-bf531bdbdf853614f7e9e97b0a0be761b4dfb532.zip
chromium_src-bf531bdbdf853614f7e9e97b0a0be761b4dfb532.tar.gz
chromium_src-bf531bdbdf853614f7e9e97b0a0be761b4dfb532.tar.bz2
Remove static initializers from GpuProcessHost and GpuProcessHostUIShim.
Review URL: http://codereview.chromium.org/7740066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98920 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/gpu/gpu_process_host.cc16
-rw-r--r--content/browser/gpu/gpu_process_host_ui_shim.cc14
2 files changed, 17 insertions, 13 deletions
diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc
index 48f3a74..03c45e25 100644
--- a/content/browser/gpu/gpu_process_host.cc
+++ b/content/browser/gpu/gpu_process_host.cc
@@ -7,6 +7,7 @@
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/debug/trace_event.h"
+#include "base/lazy_instance.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
#include "base/process_util.h"
@@ -46,7 +47,8 @@ enum GPUProcessLifetimeEvent {
};
// A global map from GPU process host ID to GpuProcessHost.
-static IDMap<GpuProcessHost> g_hosts_by_id;
+static base::LazyInstance<IDMap<GpuProcessHost> > g_hosts_by_id(
+ base::LINKER_INITIALIZED);
// Number of times the gpu process has crashed in the current browser session.
static int g_gpu_crash_count = 0;
@@ -178,8 +180,8 @@ GpuProcessHost* GpuProcessHost::GetForRenderer(
// The current policy is to ignore the renderer ID and use a single GPU
// process for all renderers. Later this will be extended to allow the
// use of multiple GPU processes.
- if (!g_hosts_by_id.IsEmpty()) {
- IDMap<GpuProcessHost>::iterator it(&g_hosts_by_id);
+ if (!g_hosts_by_id.Pointer()->IsEmpty()) {
+ IDMap<GpuProcessHost>::iterator it(g_hosts_by_id.Pointer());
return it.GetCurrentValue();
}
@@ -218,7 +220,7 @@ GpuProcessHost* GpuProcessHost::FromID(int host_id) {
if (host_id == 0)
return NULL;
- return g_hosts_by_id.Lookup(host_id);
+ return g_hosts_by_id.Pointer()->Lookup(host_id);
}
GpuProcessHost::GpuProcessHost(int host_id)
@@ -232,9 +234,9 @@ GpuProcessHost::GpuProcessHost(int host_id)
// If the 'single GPU process' policy ever changes, we still want to maintain
// it for 'gpu thread' mode and only create one instance of host and thread.
- DCHECK(!in_process_ || g_hosts_by_id.IsEmpty());
+ DCHECK(!in_process_ || g_hosts_by_id.Pointer()->IsEmpty());
- g_hosts_by_id.AddWithID(this, host_id_);
+ g_hosts_by_id.Pointer()->AddWithID(this, host_id_);
// Post a task to create the corresponding GpuProcessHostUIShim. The
// GpuProcessHostUIShim will be destroyed if either the browser exits,
@@ -260,7 +262,7 @@ GpuProcessHost::~GpuProcessHost() {
queued_messages_.pop();
}
- g_hosts_by_id.Remove(host_id_);
+ g_hosts_by_id.Pointer()->Remove(host_id_);
BrowserThread::PostTask(BrowserThread::UI,
FROM_HERE,
diff --git a/content/browser/gpu/gpu_process_host_ui_shim.cc b/content/browser/gpu/gpu_process_host_ui_shim.cc
index 365aa24..48697ac 100644
--- a/content/browser/gpu/gpu_process_host_ui_shim.cc
+++ b/content/browser/gpu/gpu_process_host_ui_shim.cc
@@ -9,6 +9,7 @@
#include "base/id_map.h"
#include "base/process_util.h"
#include "base/debug/trace_event.h"
+#include "base/lazy_instance.h"
#include "content/browser/browser_thread.h"
#include "content/browser/gpu/gpu_data_manager.h"
#include "content/browser/gpu/gpu_process_host.h"
@@ -31,7 +32,8 @@ namespace {
#undef DestroyAll
#endif
-IDMap<GpuProcessHostUIShim> g_hosts_by_id;
+base::LazyInstance<IDMap<GpuProcessHostUIShim> > g_hosts_by_id(
+ base::LINKER_INITIALIZED);
class SendOnIOThreadTask : public Task {
public:
@@ -71,7 +73,7 @@ void RouteToGpuProcessHostUIShimTask::Run() {
GpuProcessHostUIShim::GpuProcessHostUIShim(int host_id)
: host_id_(host_id) {
- g_hosts_by_id.AddWithID(this, host_id_);
+ g_hosts_by_id.Pointer()->AddWithID(this, host_id_);
}
// static
@@ -89,8 +91,8 @@ void GpuProcessHostUIShim::Destroy(int host_id) {
// static
void GpuProcessHostUIShim::DestroyAll() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- while (!g_hosts_by_id.IsEmpty()) {
- IDMap<GpuProcessHostUIShim>::iterator it(&g_hosts_by_id);
+ while (!g_hosts_by_id.Pointer()->IsEmpty()) {
+ IDMap<GpuProcessHostUIShim>::iterator it(g_hosts_by_id.Pointer());
delete it.GetCurrentValue();
}
}
@@ -98,7 +100,7 @@ void GpuProcessHostUIShim::DestroyAll() {
// static
GpuProcessHostUIShim* GpuProcessHostUIShim::FromID(int host_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return g_hosts_by_id.Lookup(host_id);
+ return g_hosts_by_id.Pointer()->Lookup(host_id);
}
bool GpuProcessHostUIShim::Send(IPC::Message* msg) {
@@ -137,7 +139,7 @@ void GpuProcessHostUIShim::SendToGpuHost(int host_id, IPC::Message* msg) {
GpuProcessHostUIShim::~GpuProcessHostUIShim() {
DCHECK(CalledOnValidThread());
- g_hosts_by_id.Remove(host_id_);
+ g_hosts_by_id.Pointer()->Remove(host_id_);
}
bool GpuProcessHostUIShim::OnControlMessageReceived(