OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CONTENT_CHILD_NPAPI_NP_CHANNEL_BASE_H_ | 5 #ifndef CONTENT_CHILD_NPAPI_NP_CHANNEL_BASE_H_ |
6 #define CONTENT_CHILD_NPAPI_NP_CHANNEL_BASE_H_ | 6 #define CONTENT_CHILD_NPAPI_NP_CHANNEL_BASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/process/process.h" | 14 #include "base/process/process.h" |
15 #include "content/child/npapi/npobject_base.h" | 15 #include "content/child/npapi/npobject_base.h" |
16 #include "content/common/message_router.h" | 16 #include "content/common/message_router.h" |
17 #include "ipc/ipc_channel_handle.h" | 17 #include "ipc/ipc_channel_handle.h" |
18 #include "ipc/ipc_sync_channel.h" | 18 #include "ipc/ipc_sync_channel.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
22 } | 22 } |
23 | 23 |
24 namespace IPC { | |
25 class AttachmentBroker; | |
26 } | |
27 | |
28 namespace content { | 24 namespace content { |
29 | 25 |
30 // Encapsulates an IPC channel between a renderer and another process. Used to | 26 // Encapsulates an IPC channel between a renderer and another process. Used to |
31 // proxy access to NP objects. | 27 // proxy access to NP objects. |
32 class NPChannelBase : public IPC::Listener, | 28 class NPChannelBase : public IPC::Listener, |
33 public IPC::Sender, | 29 public IPC::Sender, |
34 public base::RefCountedThreadSafe<NPChannelBase> { | 30 public base::RefCountedThreadSafe<NPChannelBase> { |
35 public: | 31 public: |
36 | 32 |
37 // WebPlugin[Delegate] call these on construction and destruction to setup | 33 // WebPlugin[Delegate] call these on construction and destruction to setup |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // If an existing channel exists returns that object, otherwise creates a | 98 // If an existing channel exists returns that object, otherwise creates a |
103 // new one. Even though on creation the object is refcounted, each caller | 99 // new one. Even though on creation the object is refcounted, each caller |
104 // must still ref count the returned value. When there are no more routes | 100 // must still ref count the returned value. When there are no more routes |
105 // on the channel and its ref count is 0, the object deletes itself. | 101 // on the channel and its ref count is 0, the object deletes itself. |
106 static NPChannelBase* GetChannel( | 102 static NPChannelBase* GetChannel( |
107 const IPC::ChannelHandle& channel_handle, | 103 const IPC::ChannelHandle& channel_handle, |
108 IPC::Channel::Mode mode, | 104 IPC::Channel::Mode mode, |
109 ChannelFactory factory, | 105 ChannelFactory factory, |
110 base::SingleThreadTaskRunner* ipc_task_runner, | 106 base::SingleThreadTaskRunner* ipc_task_runner, |
111 bool create_pipe_now, | 107 bool create_pipe_now, |
112 base::WaitableEvent* shutdown_event, | 108 base::WaitableEvent* shutdown_event); |
113 IPC::AttachmentBroker* broker); | |
114 | 109 |
115 // Sends a message to all instances. | 110 // Sends a message to all instances. |
116 static void Broadcast(IPC::Message* message); | 111 static void Broadcast(IPC::Message* message); |
117 | 112 |
118 // Called on the worker thread | 113 // Called on the worker thread |
119 NPChannelBase(); | 114 NPChannelBase(); |
120 | 115 |
121 virtual void CleanUp() { } | 116 virtual void CleanUp() { } |
122 | 117 |
123 // Implemented by derived classes to handle control messages | 118 // Implemented by derived classes to handle control messages |
124 virtual bool OnControlMessageReceived(const IPC::Message& msg); | 119 virtual bool OnControlMessageReceived(const IPC::Message& msg); |
125 | 120 |
126 // IPC::Listener implementation: | 121 // IPC::Listener implementation: |
127 bool OnMessageReceived(const IPC::Message& msg) override; | 122 bool OnMessageReceived(const IPC::Message& msg) override; |
128 void OnChannelConnected(int32 peer_pid) override; | 123 void OnChannelConnected(int32 peer_pid) override; |
129 void OnChannelError() override; | 124 void OnChannelError() override; |
130 | 125 |
131 void set_send_unblocking_only_during_unblock_dispatch() { | 126 void set_send_unblocking_only_during_unblock_dispatch() { |
132 send_unblocking_only_during_unblock_dispatch_ = true; | 127 send_unblocking_only_during_unblock_dispatch_ = true; |
133 } | 128 } |
134 | 129 |
135 virtual bool Init(base::SingleThreadTaskRunner* ipc_task_runner, | 130 virtual bool Init(base::SingleThreadTaskRunner* ipc_task_runner, |
136 bool create_pipe_now, | 131 bool create_pipe_now, |
137 base::WaitableEvent* shutdown_event, | 132 base::WaitableEvent* shutdown_event); |
138 IPC::AttachmentBroker* broker); | |
139 | 133 |
140 scoped_ptr<IPC::SyncChannel> channel_; | 134 scoped_ptr<IPC::SyncChannel> channel_; |
141 IPC::ChannelHandle channel_handle_; | 135 IPC::ChannelHandle channel_handle_; |
142 | 136 |
143 private: | 137 private: |
144 IPC::Channel::Mode mode_; | 138 IPC::Channel::Mode mode_; |
145 // This tracks the number of routes registered without an NPObject. It's used | 139 // This tracks the number of routes registered without an NPObject. It's used |
146 // to manage the lifetime of this object. See comment for AddRoute() and | 140 // to manage the lifetime of this object. See comment for AddRoute() and |
147 // RemoveRoute(). | 141 // RemoveRoute(). |
148 int non_npobject_count_; | 142 int non_npobject_count_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // have the unblock flag set, since they could be followed by a sync message | 189 // have the unblock flag set, since they could be followed by a sync message |
196 // that won't get dispatched until the call to the renderer is complete. | 190 // that won't get dispatched until the call to the renderer is complete. |
197 bool send_unblocking_only_during_unblock_dispatch_; | 191 bool send_unblocking_only_during_unblock_dispatch_; |
198 | 192 |
199 DISALLOW_COPY_AND_ASSIGN(NPChannelBase); | 193 DISALLOW_COPY_AND_ASSIGN(NPChannelBase); |
200 }; | 194 }; |
201 | 195 |
202 } // namespace content | 196 } // namespace content |
203 | 197 |
204 #endif // CONTENT_CHILD_NPAPI_NP_CHANNEL_BASE_H_ | 198 #endif // CONTENT_CHILD_NPAPI_NP_CHANNEL_BASE_H_ |
OLD | NEW |