OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ | 5 #ifndef CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |
6 #define CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ | 6 #define CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
16 #include "content/public/common/message_port_types.h" | |
17 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 class MessagePortDelegate; | 19 class MessagePortDelegate; |
21 | 20 |
22 class CONTENT_EXPORT MessagePortService { | 21 class CONTENT_EXPORT MessagePortService { |
23 public: | 22 public: |
24 typedef std::vector<std::pair<content::MessagePortMessage, | 23 typedef std::vector<std::pair<base::string16, std::vector<int>>> |
25 std::vector<TransferredMessagePort>>> | |
26 QueuedMessages; | 24 QueuedMessages; |
27 | 25 |
28 // Returns the MessagePortService singleton. | 26 // Returns the MessagePortService singleton. |
29 static MessagePortService* GetInstance(); | 27 static MessagePortService* GetInstance(); |
30 | 28 |
31 // These methods correspond to the message port related IPCs. | 29 // These methods correspond to the message port related IPCs. |
32 void Create(int route_id, | 30 void Create(int route_id, |
33 MessagePortDelegate* delegate, | 31 MessagePortDelegate* delegate, |
34 int* message_port_id); | 32 int* message_port_id); |
35 void Destroy(int message_port_id); | 33 void Destroy(int message_port_id); |
36 void Entangle(int local_message_port_id, int remote_message_port_id); | 34 void Entangle(int local_message_port_id, int remote_message_port_id); |
37 void PostMessage( | 35 void PostMessage( |
38 int sender_message_port_id, | 36 int sender_message_port_id, |
39 const MessagePortMessage& message, | 37 const base::string16& message, |
40 const std::vector<TransferredMessagePort>& sent_message_ports); | 38 const std::vector<int>& sent_message_ports); |
41 void QueueMessages(int message_port_id); | 39 void QueueMessages(int message_port_id); |
42 void SendQueuedMessages(int message_port_id, | 40 void SendQueuedMessages(int message_port_id, |
43 const QueuedMessages& queued_messages); | 41 const QueuedMessages& queued_messages); |
44 void ReleaseMessages(int message_port_id); | 42 void ReleaseMessages(int message_port_id); |
45 | 43 |
46 // Updates the information needed to reach a message port when it's sent to a | 44 // Updates the information needed to reach a message port when it's sent to a |
47 // (possibly different) process. | 45 // (possibly different) process. |
48 void UpdateMessagePort(int message_port_id, | 46 void UpdateMessagePort(int message_port_id, |
49 MessagePortDelegate* delegate, | 47 MessagePortDelegate* delegate, |
50 int routing_id); | 48 int routing_id); |
(...skipping 28 matching lines...) Expand all Loading... |
79 void SendQueuedMessagesIfPossible(int message_port_id); | 77 void SendQueuedMessagesIfPossible(int message_port_id); |
80 | 78 |
81 private: | 79 private: |
82 friend struct base::DefaultSingletonTraits<MessagePortService>; | 80 friend struct base::DefaultSingletonTraits<MessagePortService>; |
83 | 81 |
84 MessagePortService(); | 82 MessagePortService(); |
85 ~MessagePortService(); | 83 ~MessagePortService(); |
86 | 84 |
87 void PostMessageTo( | 85 void PostMessageTo( |
88 int message_port_id, | 86 int message_port_id, |
89 const MessagePortMessage& message, | 87 const base::string16& message, |
90 const std::vector<TransferredMessagePort>& sent_message_ports); | 88 const std::vector<int>& sent_message_ports); |
91 | 89 |
92 // Handles the details of removing a message port id. Before calling this, | 90 // Handles the details of removing a message port id. Before calling this, |
93 // verify that the message port id exists. | 91 // verify that the message port id exists. |
94 void Erase(int message_port_id); | 92 void Erase(int message_port_id); |
95 | 93 |
96 struct MessagePort; | 94 struct MessagePort; |
97 typedef std::map<int, MessagePort> MessagePorts; | 95 typedef std::map<int, MessagePort> MessagePorts; |
98 MessagePorts message_ports_; | 96 MessagePorts message_ports_; |
99 | 97 |
100 // We need globally unique identifiers for each message port. | 98 // We need globally unique identifiers for each message port. |
101 int next_message_port_id_; | 99 int next_message_port_id_; |
102 | 100 |
103 DISALLOW_COPY_AND_ASSIGN(MessagePortService); | 101 DISALLOW_COPY_AND_ASSIGN(MessagePortService); |
104 }; | 102 }; |
105 | 103 |
106 } // namespace content | 104 } // namespace content |
107 | 105 |
108 #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ | 106 #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |
OLD | NEW |