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

Side by Side Diff: ppapi/proxy/dispatcher.h

Issue 6493004: Implement basic crash detection and shutdown handling for out of process PPAP... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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
« no previous file with comments | « ppapi/ppapi_cpp.gypi ('k') | ppapi/proxy/dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 PPAPI_PROXY_DISPATCHER_H_ 5 #ifndef PPAPI_PROXY_DISPATCHER_H_
6 #define PPAPI_PROXY_DISPATCHER_H_ 6 #define PPAPI_PROXY_DISPATCHER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // "Target" | "Source" 52 // "Target" | "Source"
53 // InterfaceProxy <---------------------- InterfaceProxy 53 // InterfaceProxy <---------------------- InterfaceProxy
54 // | 54 // |
55 class Dispatcher : public IPC::Channel::Listener, 55 class Dispatcher : public IPC::Channel::Listener,
56 public IPC::Message::Sender { 56 public IPC::Message::Sender {
57 public: 57 public:
58 typedef const void* (*GetInterfaceFunc)(const char*); 58 typedef const void* (*GetInterfaceFunc)(const char*);
59 typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc); 59 typedef int32_t (*InitModuleFunc)(PP_Module, GetInterfaceFunc);
60 typedef void (*ShutdownModuleFunc)(); 60 typedef void (*ShutdownModuleFunc)();
61 61
62 ~Dispatcher(); 62 virtual ~Dispatcher();
63 63
64 // You must call this function before anything else. Returns true on success. 64 // You must call this function before anything else. Returns true on success.
65 bool InitWithChannel(MessageLoop* ipc_message_loop, 65 bool InitWithChannel(MessageLoop* ipc_message_loop,
66 const IPC::ChannelHandle& channel_handle, 66 const IPC::ChannelHandle& channel_handle,
67 bool is_client, 67 bool is_client,
68 base::WaitableEvent* shutdown_event); 68 base::WaitableEvent* shutdown_event);
69 69
70 // Alternative to InitWithChannel() for unit tests that want to send all 70 // Alternative to InitWithChannel() for unit tests that want to send all
71 // messages sent via this dispatcher to the given test sink. The test sink 71 // messages sent via this dispatcher to the given test sink. The test sink
72 // must outlive this class. 72 // must outlive this class.
73 void InitWithTestSink(IPC::TestSink* test_sink); 73 void InitWithTestSink(IPC::TestSink* test_sink);
74 74
75 // Returns true if the dispatcher is on the plugin side, or false if it's the 75 // Returns true if the dispatcher is on the plugin side, or false if it's the
76 // browser side. 76 // browser side.
77 virtual bool IsPlugin() const = 0; 77 virtual bool IsPlugin() const = 0;
78 78
79 VarSerializationRules* serialization_rules() const { 79 VarSerializationRules* serialization_rules() const {
80 return serialization_rules_.get(); 80 return serialization_rules_.get();
81 } 81 }
82 PP_Module pp_module() const {
83 return pp_module_;
84 }
85 82
86 // Wrapper for calling the local GetInterface function. 83 // Wrapper for calling the local GetInterface function.
87 const void* GetLocalInterface(const char* interface); 84 const void* GetLocalInterface(const char* interface);
88 85
89 // Returns the remote process' handle. For the host dispatcher, this will be 86 // Returns the remote process' handle. For the host dispatcher, this will be
90 // the plugin process, and for the plugin dispatcher, this will be the 87 // the plugin process, and for the plugin dispatcher, this will be the
91 // renderer process. This is used for sharing memory and such and is 88 // renderer process. This is used for sharing memory and such and is
92 // guaranteed valid (unless the remote process has suddenly died). 89 // guaranteed valid (unless the remote process has suddenly died).
93 base::ProcessHandle remote_process_handle() const { 90 base::ProcessHandle remote_process_handle() const {
94 return remote_process_handle_; 91 return remote_process_handle_;
95 } 92 }
96 93
97 // Called if the remote side is declaring to us which interfaces it supports 94 // Called if the remote side is declaring to us which interfaces it supports
98 // so we don't have to query for each one. We'll pre-create proxies for 95 // so we don't have to query for each one. We'll pre-create proxies for
99 // each of the given interfaces. 96 // each of the given interfaces.
100 97
101 // IPC::Message::Sender implementation. 98 // IPC::Message::Sender implementation.
102 virtual bool Send(IPC::Message* msg); 99 virtual bool Send(IPC::Message* msg);
103 100
104 // IPC::Channel::Listener implementation. 101 // IPC::Channel::Listener implementation.
105 virtual bool OnMessageReceived(const IPC::Message& msg); 102 virtual bool OnMessageReceived(const IPC::Message& msg);
103 virtual void OnChannelError();
106 104
107 // Will be NULL in some unit tests. 105 // Will be NULL in some unit tests and if the remote side has crashed.
108 IPC::SyncChannel* channel() const { 106 IPC::SyncChannel* channel() const {
109 return channel_.get(); 107 return channel_.get();
110 } 108 }
111 109
112 CallbackTracker& callback_tracker() { 110 CallbackTracker& callback_tracker() {
113 return callback_tracker_; 111 return callback_tracker_;
114 } 112 }
115 113
116 // Retrieves the information associated with the given interface, identified 114 // Retrieves the information associated with the given interface, identified
117 // either by name or ID. Each function searches either PPP or PPB interfaces. 115 // either by name or ID. Each function searches either PPP or PPB interfaces.
118 static const InterfaceProxy::Info* GetPPBInterfaceInfo( 116 static const InterfaceProxy::Info* GetPPBInterfaceInfo(
119 const std::string& name); 117 const std::string& name);
120 static const InterfaceProxy::Info* GetPPBInterfaceInfo( 118 static const InterfaceProxy::Info* GetPPBInterfaceInfo(
121 InterfaceID id); 119 InterfaceID id);
122 static const InterfaceProxy::Info* GetPPPInterfaceInfo( 120 static const InterfaceProxy::Info* GetPPPInterfaceInfo(
123 const std::string& name); 121 const std::string& name);
124 static const InterfaceProxy::Info* GetPPPInterfaceInfo( 122 static const InterfaceProxy::Info* GetPPPInterfaceInfo(
125 InterfaceID id); 123 InterfaceID id);
126 124
127 protected: 125 protected:
128 Dispatcher(base::ProcessHandle remote_process_handle, 126 Dispatcher(base::ProcessHandle remote_process_handle,
129 GetInterfaceFunc local_get_interface); 127 GetInterfaceFunc local_get_interface);
130 128
131 // Setter for the derived classes to set the appropriate var serialization. 129 // Setter for the derived classes to set the appropriate var serialization.
132 // Takes ownership of the given pointer, which must be on the heap. 130 // Takes ownership of the given pointer, which must be on the heap.
133 void SetSerializationRules(VarSerializationRules* var_serialization_rules); 131 void SetSerializationRules(VarSerializationRules* var_serialization_rules);
134 132
135 void set_pp_module(PP_Module module) {
136 pp_module_ = module;
137 }
138
139 bool disallow_trusted_interfaces() const { 133 bool disallow_trusted_interfaces() const {
140 return disallow_trusted_interfaces_; 134 return disallow_trusted_interfaces_;
141 } 135 }
142 136
143 private: 137 private:
144 // Set by the derived classed to indicate the module ID corresponding to
145 // this dispatcher.
146 PP_Module pp_module_;
147
148 base::ProcessHandle remote_process_handle_; // See getter above. 138 base::ProcessHandle remote_process_handle_; // See getter above.
149 139
150 // When we're unit testing, this will indicate the sink for the messages to 140 // When we're unit testing, this will indicate the sink for the messages to
151 // be deposited so they can be inspected by the test. When non-NULL, this 141 // be deposited so they can be inspected by the test. When non-NULL, this
152 // indicates that the channel should not be used. 142 // indicates that the channel should not be used.
153 IPC::TestSink* test_sink_; 143 IPC::TestSink* test_sink_;
154 144
155 // Will be null for some tests when there is a test_sink_. 145 // Will be null for some tests when there is a test_sink_, and if the
146 // remote side has crashed.
156 scoped_ptr<IPC::SyncChannel> channel_; 147 scoped_ptr<IPC::SyncChannel> channel_;
157 148
158 bool disallow_trusted_interfaces_; 149 bool disallow_trusted_interfaces_;
159 150
160 GetInterfaceFunc local_get_interface_; 151 GetInterfaceFunc local_get_interface_;
161 152
162 CallbackTracker callback_tracker_; 153 CallbackTracker callback_tracker_;
163 154
164 scoped_ptr<VarSerializationRules> serialization_rules_; 155 scoped_ptr<VarSerializationRules> serialization_rules_;
165 156
166 DISALLOW_COPY_AND_ASSIGN(Dispatcher); 157 DISALLOW_COPY_AND_ASSIGN(Dispatcher);
167 }; 158 };
168 159
169 } // namespace proxy 160 } // namespace proxy
170 } // namespace pp 161 } // namespace pp
171 162
172 #endif // PPAPI_PROXY_DISPATCHER_H_ 163 #endif // PPAPI_PROXY_DISPATCHER_H_
OLDNEW
« no previous file with comments | « ppapi/ppapi_cpp.gypi ('k') | ppapi/proxy/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698