[email protected] | 83fc55e4 | 2013-10-15 10:57:49 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 83fc55e4 | 2013-10-15 10:57:49 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |
| 6 | #define CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <utility> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/singleton.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 14 | #include "base/strings/string16.h" |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 15 | #include "ipc/ipc_message.h" |
| 16 | |
[email protected] | e6047e4a | 2012-10-25 01:34:49 | [diff] [blame] | 17 | namespace content { |
[email protected] | 83fc55e4 | 2013-10-15 10:57:49 | [diff] [blame] | 18 | class MessagePortMessageFilter; |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 19 | |
| 20 | class MessagePortService { |
| 21 | public: |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame^] | 22 | typedef std::vector<std::pair<base::string16, std::vector<int> > > |
| 23 | QueuedMessages; |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 24 | |
| 25 | // Returns the MessagePortService singleton. |
| 26 | static MessagePortService* GetInstance(); |
| 27 | |
| 28 | // These methods correspond to the message port related IPCs. |
[email protected] | 83fc55e4 | 2013-10-15 10:57:49 | [diff] [blame] | 29 | void Create(int route_id, |
| 30 | MessagePortMessageFilter* filter, |
| 31 | int* message_port_id); |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 32 | void Destroy(int message_port_id); |
| 33 | void Entangle(int local_message_port_id, int remote_message_port_id); |
| 34 | void PostMessage(int sender_message_port_id, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame^] | 35 | const base::string16& message, |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 36 | const std::vector<int>& sent_message_port_ids); |
| 37 | void QueueMessages(int message_port_id); |
| 38 | void SendQueuedMessages(int message_port_id, |
| 39 | const QueuedMessages& queued_messages); |
| 40 | |
| 41 | // Updates the information needed to reach a message port when it's sent to a |
| 42 | // (possibly different) process. |
| 43 | void UpdateMessagePort( |
| 44 | int message_port_id, |
[email protected] | 83fc55e4 | 2013-10-15 10:57:49 | [diff] [blame] | 45 | MessagePortMessageFilter* filter, |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 46 | int routing_id); |
| 47 | |
[email protected] | 83fc55e4 | 2013-10-15 10:57:49 | [diff] [blame] | 48 | void OnMessagePortMessageFilterClosing(MessagePortMessageFilter* filter); |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 49 | |
| 50 | // Attempts to send the queued messages for a message port. |
| 51 | void SendQueuedMessagesIfPossible(int message_port_id); |
| 52 | |
| 53 | private: |
| 54 | friend struct DefaultSingletonTraits<MessagePortService>; |
| 55 | |
| 56 | MessagePortService(); |
| 57 | ~MessagePortService(); |
| 58 | |
| 59 | void PostMessageTo(int message_port_id, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame^] | 60 | const base::string16& message, |
[email protected] | 6541227 | 2010-12-21 20:03:24 | [diff] [blame] | 61 | const std::vector<int>& sent_message_port_ids); |
| 62 | |
| 63 | // Handles the details of removing a message port id. Before calling this, |
| 64 | // verify that the message port id exists. |
| 65 | void Erase(int message_port_id); |
| 66 | |
| 67 | struct MessagePort; |
| 68 | typedef std::map<int, MessagePort> MessagePorts; |
| 69 | MessagePorts message_ports_; |
| 70 | |
| 71 | // We need globally unique identifiers for each message port. |
| 72 | int next_message_port_id_; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(MessagePortService); |
| 75 | }; |
| 76 | |
[email protected] | e6047e4a | 2012-10-25 01:34:49 | [diff] [blame] | 77 | } // namespace content |
| 78 | |
[email protected] | 83fc55e4 | 2013-10-15 10:57:49 | [diff] [blame] | 79 | #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |