Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: content/browser/renderer_host/java/java_bridge_channel_host.cc

Issue 8491043: Allow linker initialization of lazy instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: thakis comment, renamed LAZY_INSTANCE_INITIALIZER Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/renderer_host/java/java_bridge_channel_host.h" 5 #include "content/browser/renderer_host/java/java_bridge_channel_host.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 10
11 using base::WaitableEvent; 11 using base::WaitableEvent;
12 12
13 namespace { 13 namespace {
14 struct WaitableEventLazyInstanceTraits 14 struct WaitableEventLazyInstanceTraits
15 : public base::DefaultLazyInstanceTraits<WaitableEvent> { 15 : public base::DefaultLazyInstanceTraits<WaitableEvent> {
16 static WaitableEvent* New(void* instance) { 16 static WaitableEvent* New(void* instance) {
17 // Use placement new to initialize our instance in our preallocated space. 17 // Use placement new to initialize our instance in our preallocated space.
18 // The parenthesis is very important here to force POD type initialization. 18 // The parenthesis is very important here to force POD type initialization.
19 return new (instance) WaitableEvent(false, false); 19 return new (instance) WaitableEvent(false, false);
20 } 20 }
21 }; 21 };
22 base::LazyInstance<WaitableEvent, WaitableEventLazyInstanceTraits> dummy_event( 22 base::LazyInstance<WaitableEvent, WaitableEventLazyInstanceTraits> dummy_event =
23 base::LINKER_INITIALIZED); 23 LAZY_INSTANCE_INITIALIZER;
24 } 24 }
25 25
26 JavaBridgeChannelHost* JavaBridgeChannelHost::GetJavaBridgeChannelHost( 26 JavaBridgeChannelHost* JavaBridgeChannelHost::GetJavaBridgeChannelHost(
27 int renderer_id, base::MessageLoopProxy* ipc_message_loop) { 27 int renderer_id, base::MessageLoopProxy* ipc_message_loop) {
28 std::string channel_name(StringPrintf("r%d.javabridge", renderer_id)); 28 std::string channel_name(StringPrintf("r%d.javabridge", renderer_id));
29 // We don't use a shutdown event because the Java Bridge only sends messages 29 // We don't use a shutdown event because the Java Bridge only sends messages
30 // from renderer to browser, so we'll never be waiting for a sync IPC to 30 // from renderer to browser, so we'll never be waiting for a sync IPC to
31 // complete. So we use an event which is never signaled. 31 // complete. So we use an event which is never signaled.
32 return static_cast<JavaBridgeChannelHost*>(NPChannelBase::GetChannel( 32 return static_cast<JavaBridgeChannelHost*>(NPChannelBase::GetChannel(
33 channel_name, 33 channel_name,
(...skipping 23 matching lines...) Expand all
57 #endif 57 #endif
58 58
59 return true; 59 return true;
60 } 60 }
61 61
62 bool JavaBridgeChannelHost::Send(IPC::Message* msg) { 62 bool JavaBridgeChannelHost::Send(IPC::Message* msg) {
63 CHECK(!msg->is_sync() && msg->is_reply()) << 63 CHECK(!msg->is_sync() && msg->is_reply()) <<
64 "Java Bridge only sends messages from renderer to browser."; 64 "Java Bridge only sends messages from renderer to browser.";
65 return NPChannelBase::Send(msg); 65 return NPChannelBase::Send(msg);
66 } 66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698