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

Side by Side Diff: chrome/browser/extensions/api/messaging/message_service.h

Issue 16226004: Replace JSON (de)serialization of extension messages with direct Value pickling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" 15 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h"
16 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" 16 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
17 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
19 19
20 class GURL; 20 class GURL;
21 class Profile; 21 class Profile;
22 22
23 namespace base { 23 namespace base {
24 class DictionaryValue; 24 class DictionaryValue;
25 class ListValue;
25 } 26 }
26 27
27 namespace content { 28 namespace content {
28 class RenderProcessHost; 29 class RenderProcessHost;
29 class WebContents; 30 class WebContents;
30 } 31 }
31 32
32 namespace extensions { 33 namespace extensions {
33 class Extension; 34 class Extension;
34 class ExtensionHost; 35 class ExtensionHost;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const std::string& source_extension_id, 76 const std::string& source_extension_id,
76 const std::string& target_extension_id, 77 const std::string& target_extension_id,
77 const GURL& source_url) {} 78 const GURL& source_url) {}
78 79
79 // Notify the port that the channel has been closed. If |error_message| is 80 // Notify the port that the channel has been closed. If |error_message| is
80 // non-empty, it indicates an error occurred while opening the connection. 81 // non-empty, it indicates an error occurred while opening the connection.
81 virtual void DispatchOnDisconnect(int source_port_id, 82 virtual void DispatchOnDisconnect(int source_port_id,
82 const std::string& error_message) {} 83 const std::string& error_message) {}
83 84
84 // Dispatch a message to this end of the communication. 85 // Dispatch a message to this end of the communication.
85 virtual void DispatchOnMessage(const std::string& message, 86 virtual void DispatchOnMessage(scoped_ptr<base::ListValue> message,
86 int target_port_id) = 0; 87 int target_port_id) = 0;
87 88
88 // MessagPorts that target extensions will need to adjust their keepalive 89 // MessagPorts that target extensions will need to adjust their keepalive
89 // counts for their lazy background page. 90 // counts for their lazy background page.
90 virtual void IncrementLazyKeepaliveCount() {} 91 virtual void IncrementLazyKeepaliveCount() {}
91 virtual void DecrementLazyKeepaliveCount() {} 92 virtual void DecrementLazyKeepaliveCount() {}
92 93
93 // Get the RenderProcessHost (if any) associated with the port. 94 // Get the RenderProcessHost (if any) associated with the port.
94 virtual content::RenderProcessHost* GetRenderProcessHost(); 95 virtual content::RenderProcessHost* GetRenderProcessHost();
95 96
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 int receiver_port_id, 138 int receiver_port_id,
138 const std::string& source_extension_id, 139 const std::string& source_extension_id,
139 const std::string& native_app_name); 140 const std::string& native_app_name);
140 141
141 // Closes the message channel associated with the given port, and notifies 142 // Closes the message channel associated with the given port, and notifies
142 // the other side. 143 // the other side.
143 virtual void CloseChannel(int port_id, 144 virtual void CloseChannel(int port_id,
144 const std::string& error_message) OVERRIDE; 145 const std::string& error_message) OVERRIDE;
145 146
146 // Sends a message to the given port. 147 // Sends a message to the given port.
147 void PostMessage(int port_id, const std::string& message); 148 void PostMessage(int port_id, scoped_ptr<base::ListValue> message);
148 149
149 // NativeMessageProcessHost::Client 150 // NativeMessageProcessHost::Client
150 virtual void PostMessageFromNativeProcess( 151 virtual void PostMessageFromNativeProcess(
151 int port_id, 152 int port_id,
152 const std::string& message) OVERRIDE; 153 scoped_ptr<base::ListValue> message) OVERRIDE;
153 154
154 private: 155 private:
155 friend class MockMessageService; 156 friend class MockMessageService;
156 friend class ProfileKeyedAPIFactory<MessageService>; 157 friend class ProfileKeyedAPIFactory<MessageService>;
157 struct OpenChannelParams; 158 struct OpenChannelParams;
158 159
159 // A map of channel ID to its channel object. 160 // A map of channel ID to its channel object.
160 typedef std::map<int, MessageChannel*> MessageChannelMap; 161 typedef std::map<int, MessageChannel*> MessageChannelMap;
161 162
162 // A map of channel ID to information about the extension that is waiting 163 // A map of channel ID to information about the extension that is waiting
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 void PendingOpenChannel(scoped_ptr<OpenChannelParams> params, 199 void PendingOpenChannel(scoped_ptr<OpenChannelParams> params,
199 int source_process_id, 200 int source_process_id,
200 extensions::ExtensionHost* host); 201 extensions::ExtensionHost* host);
201 void PendingCloseChannel(int port_id, 202 void PendingCloseChannel(int port_id,
202 const std::string& error_message, 203 const std::string& error_message,
203 extensions::ExtensionHost* host) { 204 extensions::ExtensionHost* host) {
204 if (host) 205 if (host)
205 CloseChannel(port_id, error_message); 206 CloseChannel(port_id, error_message);
206 } 207 }
207 void PendingPostMessage(int port_id, 208 void PendingPostMessage(int port_id,
208 const std::string& message, 209 scoped_ptr<base::ListValue> message,
209 extensions::ExtensionHost* host) { 210 extensions::ExtensionHost* host) {
210 if (host) 211 if (host)
211 PostMessage(port_id, message); 212 PostMessage(port_id, message.Pass());
212 } 213 }
213 214
214 // ProfileKeyedAPI implementation. 215 // ProfileKeyedAPI implementation.
215 static const char* service_name() { 216 static const char* service_name() {
216 return "MessageService"; 217 return "MessageService";
217 } 218 }
218 static const bool kServiceRedirectedInIncognito = true; 219 static const bool kServiceRedirectedInIncognito = true;
219 220
220 content::NotificationRegistrar registrar_; 221 content::NotificationRegistrar registrar_;
221 MessageChannelMap channels_; 222 MessageChannelMap channels_;
222 PendingChannelMap pending_channels_; 223 PendingChannelMap pending_channels_;
223 224
224 // Weak pointer. Guaranteed to outlive this class. 225 // Weak pointer. Guaranteed to outlive this class.
225 LazyBackgroundTaskQueue* lazy_background_task_queue_; 226 LazyBackgroundTaskQueue* lazy_background_task_queue_;
226 227
227 base::WeakPtrFactory<MessageService> weak_factory_; 228 base::WeakPtrFactory<MessageService> weak_factory_;
228 229
229 DISALLOW_COPY_AND_ASSIGN(MessageService); 230 DISALLOW_COPY_AND_ASSIGN(MessageService);
230 }; 231 };
231 232
232 } // namespace extensions 233 } // namespace extensions
233 234
234 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ 235 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698