| 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/basictypes.h" | 12 #include "base/basictypes.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 "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 class MessagePortMessageFilter; | 18 class MessagePortMessageFilter; |
| 19 | 19 |
| 20 class MessagePortService { | 20 class MessagePortService { |
| 21 public: | 21 public: |
| 22 typedef std::vector<std::pair<string16, std::vector<int> > > QueuedMessages; | 22 typedef std::vector<std::pair<base::string16, std::vector<int> > > |
| 23 QueuedMessages; |
| 23 | 24 |
| 24 // Returns the MessagePortService singleton. | 25 // Returns the MessagePortService singleton. |
| 25 static MessagePortService* GetInstance(); | 26 static MessagePortService* GetInstance(); |
| 26 | 27 |
| 27 // These methods correspond to the message port related IPCs. | 28 // These methods correspond to the message port related IPCs. |
| 28 void Create(int route_id, | 29 void Create(int route_id, |
| 29 MessagePortMessageFilter* filter, | 30 MessagePortMessageFilter* filter, |
| 30 int* message_port_id); | 31 int* message_port_id); |
| 31 void Destroy(int message_port_id); | 32 void Destroy(int message_port_id); |
| 32 void Entangle(int local_message_port_id, int remote_message_port_id); | 33 void Entangle(int local_message_port_id, int remote_message_port_id); |
| 33 void PostMessage(int sender_message_port_id, | 34 void PostMessage(int sender_message_port_id, |
| 34 const string16& message, | 35 const base::string16& message, |
| 35 const std::vector<int>& sent_message_port_ids); | 36 const std::vector<int>& sent_message_port_ids); |
| 36 void QueueMessages(int message_port_id); | 37 void QueueMessages(int message_port_id); |
| 37 void SendQueuedMessages(int message_port_id, | 38 void SendQueuedMessages(int message_port_id, |
| 38 const QueuedMessages& queued_messages); | 39 const QueuedMessages& queued_messages); |
| 39 | 40 |
| 40 // Updates the information needed to reach a message port when it's sent to a | 41 // Updates the information needed to reach a message port when it's sent to a |
| 41 // (possibly different) process. | 42 // (possibly different) process. |
| 42 void UpdateMessagePort( | 43 void UpdateMessagePort( |
| 43 int message_port_id, | 44 int message_port_id, |
| 44 MessagePortMessageFilter* filter, | 45 MessagePortMessageFilter* filter, |
| 45 int routing_id); | 46 int routing_id); |
| 46 | 47 |
| 47 void OnMessagePortMessageFilterClosing(MessagePortMessageFilter* filter); | 48 void OnMessagePortMessageFilterClosing(MessagePortMessageFilter* filter); |
| 48 | 49 |
| 49 // Attempts to send the queued messages for a message port. | 50 // Attempts to send the queued messages for a message port. |
| 50 void SendQueuedMessagesIfPossible(int message_port_id); | 51 void SendQueuedMessagesIfPossible(int message_port_id); |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 friend struct DefaultSingletonTraits<MessagePortService>; | 54 friend struct DefaultSingletonTraits<MessagePortService>; |
| 54 | 55 |
| 55 MessagePortService(); | 56 MessagePortService(); |
| 56 ~MessagePortService(); | 57 ~MessagePortService(); |
| 57 | 58 |
| 58 void PostMessageTo(int message_port_id, | 59 void PostMessageTo(int message_port_id, |
| 59 const string16& message, | 60 const base::string16& message, |
| 60 const std::vector<int>& sent_message_port_ids); | 61 const std::vector<int>& sent_message_port_ids); |
| 61 | 62 |
| 62 // Handles the details of removing a message port id. Before calling this, | 63 // Handles the details of removing a message port id. Before calling this, |
| 63 // verify that the message port id exists. | 64 // verify that the message port id exists. |
| 64 void Erase(int message_port_id); | 65 void Erase(int message_port_id); |
| 65 | 66 |
| 66 struct MessagePort; | 67 struct MessagePort; |
| 67 typedef std::map<int, MessagePort> MessagePorts; | 68 typedef std::map<int, MessagePort> MessagePorts; |
| 68 MessagePorts message_ports_; | 69 MessagePorts message_ports_; |
| 69 | 70 |
| 70 // We need globally unique identifiers for each message port. | 71 // We need globally unique identifiers for each message port. |
| 71 int next_message_port_id_; | 72 int next_message_port_id_; |
| 72 | 73 |
| 73 DISALLOW_COPY_AND_ASSIGN(MessagePortService); | 74 DISALLOW_COPY_AND_ASSIGN(MessagePortService); |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 } // namespace content | 77 } // namespace content |
| 77 | 78 |
| 78 #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ | 79 #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |
| OLD | NEW |