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

Side by Side Diff: chrome/plugin/plugin_channel_base.h

Issue 5598010: Convert over to channel handles (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed up bad whitespace Created 10 years 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 CHROME_PLUGIN_PLUGIN_CHANNEL_BASE_H_ 5 #ifndef CHROME_PLUGIN_PLUGIN_CHANNEL_BASE_H_
6 #define CHROME_PLUGIN_PLUGIN_CHANNEL_BASE_H_ 6 #define CHROME_PLUGIN_PLUGIN_CHANNEL_BASE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/ref_counted.h" 14 #include "base/ref_counted.h"
15 #include "base/scoped_ptr.h" 15 #include "base/scoped_ptr.h"
16 #include "chrome/common/message_router.h" 16 #include "chrome/common/message_router.h"
17 #include "chrome/plugin/npobject_base.h" 17 #include "chrome/plugin/npobject_base.h"
18 #include "gfx/native_widget_types.h" 18 #include "gfx/native_widget_types.h"
19 #include "ipc/ipc_channel_handle.h"
19 #include "ipc/ipc_sync_channel.h" 20 #include "ipc/ipc_sync_channel.h"
20 21
21 // Encapsulates an IPC channel between a renderer and a plugin process. 22 // Encapsulates an IPC channel between a renderer and a plugin process.
22 class PluginChannelBase : public IPC::Channel::Listener, 23 class PluginChannelBase : public IPC::Channel::Listener,
23 public IPC::Message::Sender, 24 public IPC::Message::Sender,
24 public base::RefCountedThreadSafe<PluginChannelBase> { 25 public base::RefCountedThreadSafe<PluginChannelBase> {
25 public: 26 public:
26 27
27 // WebPlugin[Delegate] call these on construction and destruction to setup 28 // WebPlugin[Delegate] call these on construction and destruction to setup
28 // the routing and manage lifetime of this object. This is also called by 29 // the routing and manage lifetime of this object. This is also called by
29 // NPObjectProxy and NPObjectStub. However the latter don't control the 30 // NPObjectProxy and NPObjectStub. However the latter don't control the
30 // lifetime of this object (by passing true for npobject) because we don't 31 // lifetime of this object (by passing true for npobject) because we don't
31 // want a leak of an NPObject in a plugin to keep the channel around longer 32 // want a leak of an NPObject in a plugin to keep the channel around longer
32 // than necessary. 33 // than necessary.
33 void AddRoute(int route_id, IPC::Channel::Listener* listener, 34 void AddRoute(int route_id, IPC::Channel::Listener* listener,
34 NPObjectBase* npobject); 35 NPObjectBase* npobject);
35 void RemoveRoute(int route_id); 36 void RemoveRoute(int route_id);
36 37
37 // IPC::Message::Sender implementation: 38 // IPC::Message::Sender implementation:
38 virtual bool Send(IPC::Message* msg); 39 virtual bool Send(IPC::Message* msg);
39 40
40 int peer_pid() { return peer_pid_; } 41 int peer_pid() { return peer_pid_; }
41 std::string channel_name() const { return channel_name_; } 42 IPC::ChannelHandle channel_handle() const { return channel_handle_; }
42 43
43 // Returns the number of open plugin channels in this process. 44 // Returns the number of open plugin channels in this process.
44 static int Count(); 45 static int Count();
45 46
46 // Returns a new route id. 47 // Returns a new route id.
47 virtual int GenerateRouteID() = 0; 48 virtual int GenerateRouteID() = 0;
48 49
49 // Returns whether the channel is valid or not. A channel is invalid 50 // Returns whether the channel is valid or not. A channel is invalid
50 // if it is disconnected due to a channel error. 51 // if it is disconnected due to a channel error.
51 bool channel_valid() { 52 bool channel_valid() {
(...skipping 16 matching lines...) Expand all
68 friend class base::RefCountedThreadSafe<PluginChannelBase>; 69 friend class base::RefCountedThreadSafe<PluginChannelBase>;
69 70
70 virtual ~PluginChannelBase(); 71 virtual ~PluginChannelBase();
71 72
72 // Returns a PluginChannelBase derived object for the given channel name. 73 // Returns a PluginChannelBase derived object for the given channel name.
73 // If an existing channel exists returns that object, otherwise creates a 74 // If an existing channel exists returns that object, otherwise creates a
74 // new one. Even though on creation the object is refcounted, each caller 75 // new one. Even though on creation the object is refcounted, each caller
75 // must still ref count the returned value. When there are no more routes 76 // must still ref count the returned value. When there are no more routes
76 // on the channel and its ref count is 0, the object deletes itself. 77 // on the channel and its ref count is 0, the object deletes itself.
77 static PluginChannelBase* GetChannel( 78 static PluginChannelBase* GetChannel(
78 const std::string& channel_key, IPC::Channel::Mode mode, 79 const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode,
79 PluginChannelFactory factory, MessageLoop* ipc_message_loop, 80 PluginChannelFactory factory, MessageLoop* ipc_message_loop,
80 bool create_pipe_now); 81 bool create_pipe_now);
81 82
82 // Sends a message to all instances. 83 // Sends a message to all instances.
83 static void Broadcast(IPC::Message* message); 84 static void Broadcast(IPC::Message* message);
84 85
85 // Called on the worker thread 86 // Called on the worker thread
86 PluginChannelBase(); 87 PluginChannelBase();
87 88
88 virtual void CleanUp() { } 89 virtual void CleanUp() { }
89 90
90 // Implemented by derived classes to handle control messages 91 // Implemented by derived classes to handle control messages
91 virtual void OnControlMessageReceived(const IPC::Message& msg); 92 virtual void OnControlMessageReceived(const IPC::Message& msg);
92 93
93 // IPC::Channel::Listener implementation: 94 // IPC::Channel::Listener implementation:
94 virtual void OnMessageReceived(const IPC::Message& msg); 95 virtual void OnMessageReceived(const IPC::Message& msg);
95 virtual void OnChannelConnected(int32 peer_pid); 96 virtual void OnChannelConnected(int32 peer_pid);
96 virtual void OnChannelError(); 97 virtual void OnChannelError();
97 98
98 void set_send_unblocking_only_during_unblock_dispatch() { 99 void set_send_unblocking_only_during_unblock_dispatch() {
99 send_unblocking_only_during_unblock_dispatch_ = true; 100 send_unblocking_only_during_unblock_dispatch_ = true;
100 } 101 }
101 102
102 virtual bool Init(MessageLoop* ipc_message_loop, bool create_pipe_now); 103 virtual bool Init(MessageLoop* ipc_message_loop, bool create_pipe_now);
103 104
104 scoped_ptr<IPC::SyncChannel> channel_; 105 scoped_ptr<IPC::SyncChannel> channel_;
105 106
106 private: 107 private:
107 IPC::Channel::Mode mode_; 108 IPC::Channel::Mode mode_;
108 std::string channel_name_; 109 IPC::ChannelHandle channel_handle_;
109 int plugin_count_; 110 int plugin_count_;
110 int peer_pid_; 111 int peer_pid_;
111 112
112 // true when in the middle of a RemoveRoute call 113 // true when in the middle of a RemoveRoute call
113 bool in_remove_route_; 114 bool in_remove_route_;
114 115
115 // Keep track of all the registered NPObjects proxies/stubs so that when the 116 // Keep track of all the registered NPObjects proxies/stubs so that when the
116 // channel is closed we can inform them. 117 // channel is closed we can inform them.
117 typedef base::hash_map<int, NPObjectBase*> ListenerMap; 118 typedef base::hash_map<int, NPObjectBase*> ListenerMap;
118 ListenerMap npobject_listeners_; 119 ListenerMap npobject_listeners_;
(...skipping 20 matching lines...) Expand all
139 // renderer. We additionally have to do this for async messages from the 140 // renderer. We additionally have to do this for async messages from the
140 // renderer that have the unblock flag set, since they could be followed by a 141 // renderer that have the unblock flag set, since they could be followed by a
141 // sync message that won't get dispatched until the call to the renderer is 142 // sync message that won't get dispatched until the call to the renderer is
142 // complete. 143 // complete.
143 bool send_unblocking_only_during_unblock_dispatch_; 144 bool send_unblocking_only_during_unblock_dispatch_;
144 145
145 DISALLOW_COPY_AND_ASSIGN(PluginChannelBase); 146 DISALLOW_COPY_AND_ASSIGN(PluginChannelBase);
146 }; 147 };
147 148
148 #endif // CHROME_PLUGIN_PLUGIN_CHANNEL_BASE_H_ 149 #endif // CHROME_PLUGIN_PLUGIN_CHANNEL_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698