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

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

Issue 18570003: Move Renderer-side NPObject owner tracking to JavaBridgeChannel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move some comment cleanup to crrev.com/17428003 Created 7 years, 5 months 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/atomicops.h" 7 #include "base/atomicops.h"
8 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "content/common/java_bridge_messages.h" 11 #include "content/common/java_bridge_messages.h"
12 #include "third_party/WebKit/public/web/WebBindings.h"
12 13
13 using base::WaitableEvent; 14 using base::WaitableEvent;
14 15
15 namespace content { 16 namespace content {
16 namespace { 17 namespace {
17 struct WaitableEventLazyInstanceTraits 18 struct WaitableEventLazyInstanceTraits
18 : public base::DefaultLazyInstanceTraits<WaitableEvent> { 19 : public base::DefaultLazyInstanceTraits<WaitableEvent> {
19 static WaitableEvent* New(void* instance) { 20 static WaitableEvent* New(void* instance) {
20 // Use placement new to initialize our instance in our preallocated space. 21 // Use placement new to initialize our instance in our preallocated space.
21 // The parenthesis is very important here to force POD type initialization. 22 // The parenthesis is very important here to force POD type initialization.
22 return new (instance) WaitableEvent(false, false); 23 return new (instance) WaitableEvent(false, false);
23 } 24 }
24 }; 25 };
25 base::LazyInstance<WaitableEvent, WaitableEventLazyInstanceTraits> dummy_event = 26 base::LazyInstance<WaitableEvent, WaitableEventLazyInstanceTraits> dummy_event =
26 LAZY_INSTANCE_INITIALIZER; 27 LAZY_INSTANCE_INITIALIZER;
27 28
28 base::subtle::AtomicWord g_last_id = 0; 29 base::subtle::AtomicWord g_last_id = 0;
29 } 30 }
30 31
32 JavaBridgeChannelHost::JavaBridgeChannelHost()
33 : peer_owner_id_(new struct _NPP) {
34 // Register a dummy owner Id for objects received from the peer Renderer
35 // process.
36 WebKit::WebBindings::registerObjectOwner(peer_owner_id_.get());
37 SetDefaultNPObjectOwner(peer_owner_id_.get());
38 }
39
31 JavaBridgeChannelHost::~JavaBridgeChannelHost() { 40 JavaBridgeChannelHost::~JavaBridgeChannelHost() {
41 WebKit::WebBindings::unregisterObjectOwner(peer_owner_id_.get());
32 #if defined(OS_POSIX) 42 #if defined(OS_POSIX)
33 if (channel_handle_.socket.fd > 0) { 43 if (channel_handle_.socket.fd > 0) {
34 close(channel_handle_.socket.fd); 44 close(channel_handle_.socket.fd);
35 } 45 }
36 #endif 46 #endif
37 } 47 }
38 48
39 JavaBridgeChannelHost* JavaBridgeChannelHost::GetJavaBridgeChannelHost( 49 JavaBridgeChannelHost* JavaBridgeChannelHost::GetJavaBridgeChannelHost(
40 int renderer_id, 50 int renderer_id,
41 base::MessageLoopProxy* ipc_message_loop) { 51 base::MessageLoopProxy* ipc_message_loop) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 IPC_MESSAGE_HANDLER(JavaBridgeMsg_GenerateRouteID, OnGenerateRouteID) 96 IPC_MESSAGE_HANDLER(JavaBridgeMsg_GenerateRouteID, OnGenerateRouteID)
87 IPC_END_MESSAGE_MAP() 97 IPC_END_MESSAGE_MAP()
88 return handled; 98 return handled;
89 } 99 }
90 100
91 void JavaBridgeChannelHost::OnGenerateRouteID(int* route_id) { 101 void JavaBridgeChannelHost::OnGenerateRouteID(int* route_id) {
92 *route_id = GenerateRouteID(); 102 *route_id = GenerateRouteID();
93 } 103 }
94 104
95 } // namespace content 105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698