Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" | 16 #include "chrome/browser/extensions/api/messaging/message_property_provider.h" |
| 17 #include "chrome/browser/extensions/api/messaging/native_message_process_host.h" | |
| 18 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 19 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #include "extensions/browser/api/messaging/native_message_host.h" | |
| 20 #include "extensions/browser/browser_context_keyed_api_factory.h" | 20 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 21 #include "extensions/common/api/messaging/message.h" | 21 #include "extensions/common/api/messaging/message.h" |
| 22 | 22 |
| 23 class GURL; | 23 class GURL; |
| 24 class Profile; | 24 class Profile; |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 class DictionaryValue; | 27 class DictionaryValue; |
| 28 } | 28 } |
| 29 | 29 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 54 // a message to the opposite side of the channel, which may have multiple | 54 // a message to the opposite side of the channel, which may have multiple |
| 55 // listeners. | 55 // listeners. |
| 56 // | 56 // |
| 57 // Terminology: | 57 // Terminology: |
| 58 // channel: connection between two ports | 58 // channel: connection between two ports |
| 59 // port: an IPC::Message::Process interface and an optional routing_id (in the | 59 // port: an IPC::Message::Process interface and an optional routing_id (in the |
| 60 // case that the port is a tab). The Process is usually either a | 60 // case that the port is a tab). The Process is usually either a |
| 61 // RenderProcessHost or a RenderViewHost. | 61 // RenderProcessHost or a RenderViewHost. |
| 62 class MessageService : public BrowserContextKeyedAPI, | 62 class MessageService : public BrowserContextKeyedAPI, |
| 63 public content::NotificationObserver, | 63 public content::NotificationObserver, |
| 64 public NativeMessageProcessHost::Client { | 64 public NativeMessageHost::Client { |
| 65 public: | 65 public: |
| 66 // A messaging channel. Note that the opening port can be the same as the | 66 // A messaging channel. Note that the opening port can be the same as the |
| 67 // receiver, if an extension background page wants to talk to its tab (for | 67 // receiver, if an extension background page wants to talk to its tab (for |
| 68 // example). | 68 // example). |
| 69 struct MessageChannel; | 69 struct MessageChannel; |
| 70 | 70 |
| 71 // One side of the communication handled by extensions::MessageService. | 71 // One side of the communication handled by extensions::MessageService. |
| 72 class MessagePort { | 72 class MessagePort { |
| 73 public: | 73 public: |
| 74 virtual ~MessagePort() {} | 74 virtual ~MessagePort() {} |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 146 |
| 147 // Closes the message channel associated with the given port, and notifies | 147 // Closes the message channel associated with the given port, and notifies |
| 148 // the other side. | 148 // the other side. |
| 149 virtual void CloseChannel(int port_id, | 149 virtual void CloseChannel(int port_id, |
| 150 const std::string& error_message) OVERRIDE; | 150 const std::string& error_message) OVERRIDE; |
| 151 | 151 |
| 152 // Enqueues a message on a pending channel, or sends a message to the given | 152 // Enqueues a message on a pending channel, or sends a message to the given |
| 153 // port if the channel isn't pending. | 153 // port if the channel isn't pending. |
| 154 void PostMessage(int port_id, const Message& message); | 154 void PostMessage(int port_id, const Message& message); |
| 155 | 155 |
| 156 // NativeMessageProcessHost::Client | 156 // NativeMessageHost::Client implementation. |
| 157 virtual void PostMessageFromNativeProcess( | 157 virtual void PostMessageFromNative(int port_id, |
|
Sergey Ulanov
2014/09/22 23:42:58
I think it's better to keep the old name.
kelvinp
2014/09/23 20:16:41
Renamed to PostMessageFromNative.
| |
| 158 int port_id, | 158 const std::string& message) OVERRIDE; |
| 159 const std::string& message) OVERRIDE; | |
| 160 | 159 |
| 161 private: | 160 private: |
| 162 friend class MockMessageService; | 161 friend class MockMessageService; |
| 163 friend class BrowserContextKeyedAPIFactory<MessageService>; | 162 friend class BrowserContextKeyedAPIFactory<MessageService>; |
| 164 struct OpenChannelParams; | 163 struct OpenChannelParams; |
| 165 | 164 |
| 166 // A map of channel ID to its channel object. | 165 // A map of channel ID to its channel object. |
| 167 typedef std::map<int, MessageChannel*> MessageChannelMap; | 166 typedef std::map<int, MessageChannel*> MessageChannelMap; |
| 168 | 167 |
| 169 typedef std::pair<int, Message> PendingMessage; | 168 typedef std::pair<int, Message> PendingMessage; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 LazyBackgroundTaskQueue* lazy_background_task_queue_; | 267 LazyBackgroundTaskQueue* lazy_background_task_queue_; |
| 269 | 268 |
| 270 base::WeakPtrFactory<MessageService> weak_factory_; | 269 base::WeakPtrFactory<MessageService> weak_factory_; |
| 271 | 270 |
| 272 DISALLOW_COPY_AND_ASSIGN(MessageService); | 271 DISALLOW_COPY_AND_ASSIGN(MessageService); |
| 273 }; | 272 }; |
| 274 | 273 |
| 275 } // namespace extensions | 274 } // namespace extensions |
| 276 | 275 |
| 277 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ | 276 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_MESSAGE_SERVICE_H_ |
| OLD | NEW |