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 MessagePortHandler; |
19 | 19 |
20 class MessagePortService { | 20 class MessagePortService { |
21 public: | 21 public: |
22 typedef std::vector<std::pair<base::string16, std::vector<int> > > | 22 typedef std::vector<std::pair<base::string16, std::vector<int> > > |
23 QueuedMessages; | 23 QueuedMessages; |
24 | 24 |
25 // Returns the MessagePortService singleton. | 25 // Returns the MessagePortService singleton. |
26 static MessagePortService* GetInstance(); | 26 static MessagePortService* GetInstance(); |
27 | 27 |
28 // These methods correspond to the message port related IPCs. | 28 // These methods correspond to the message port related IPCs. |
29 void Create(int route_id, | 29 void Create(int route_id, MessagePortHandler* filter, int* message_port_id); |
30 MessagePortMessageFilter* filter, | |
31 int* message_port_id); | |
32 void Destroy(int message_port_id); | 30 void Destroy(int message_port_id); |
33 void Entangle(int local_message_port_id, int remote_message_port_id); | 31 void Entangle(int local_message_port_id, int remote_message_port_id); |
34 void PostMessage(int sender_message_port_id, | 32 void PostMessage(int sender_message_port_id, |
35 const base::string16& message, | 33 const base::string16& message, |
36 const std::vector<int>& sent_message_port_ids); | 34 const std::vector<int>& sent_message_port_ids); |
37 void QueueMessages(int message_port_id); | 35 void QueueMessages(int message_port_id); |
38 void SendQueuedMessages(int message_port_id, | 36 void SendQueuedMessages(int message_port_id, |
39 const QueuedMessages& queued_messages); | 37 const QueuedMessages& queued_messages); |
40 void ReleaseMessages(int message_port_id); | 38 void ReleaseMessages(int message_port_id); |
41 | 39 |
42 // Updates the information needed to reach a message port when it's sent to a | 40 // Updates the information needed to reach a message port when it's sent to a |
43 // (possibly different) process. | 41 // (possibly different) process. |
44 void UpdateMessagePort( | 42 void UpdateMessagePort(int message_port_id, |
45 int message_port_id, | 43 MessagePortHandler* filter, |
46 MessagePortMessageFilter* filter, | 44 int routing_id); |
47 int routing_id); | |
48 | 45 |
49 // The message port is being transferred to a new renderer process, but the | 46 // The message port is being transferred to a new renderer process, but the |
50 // code doing that isn't able to immediately update the message port with a | 47 // code doing that isn't able to immediately update the message port with a |
51 // new filter and routing_id. This queues up all messages sent to this port | 48 // new filter and routing_id. This queues up all messages sent to this port |
52 // until later ReleaseMessages is called for this port (this will happen | 49 // until later ReleaseMessages is called for this port (this will happen |
53 // automatically as soon as a WebMessagePortChannelImpl instance is created | 50 // automatically as soon as a WebMessagePortChannelImpl instance is created |
54 // for this port in the renderer. The browser side code is still responsible | 51 // for this port in the renderer. The browser side code is still responsible |
55 // for updating the port with a new filter before that happens. If ultimately | 52 // for updating the port with a new filter before that happens. If ultimately |
56 // transfering the port to a new process fails, ClosePort should be called to | 53 // transfering the port to a new process fails, ClosePort should be called to |
57 // clean up the port. | 54 // clean up the port. |
58 void HoldMessages(int message_port_id); | 55 void HoldMessages(int message_port_id); |
59 | 56 |
60 // Closes and cleans up the message port. | 57 // Closes and cleans up the message port. |
61 void ClosePort(int message_port_id); | 58 void ClosePort(int message_port_id); |
62 | 59 |
63 void OnMessagePortMessageFilterClosing(MessagePortMessageFilter* filter); | 60 void OnMessagePortMessageFilterClosing(MessagePortHandler* filter); |
64 | 61 |
65 // Attempts to send the queued messages for a message port. | 62 // Attempts to send the queued messages for a message port. |
66 void SendQueuedMessagesIfPossible(int message_port_id); | 63 void SendQueuedMessagesIfPossible(int message_port_id); |
67 | 64 |
68 private: | 65 private: |
69 friend struct DefaultSingletonTraits<MessagePortService>; | 66 friend struct DefaultSingletonTraits<MessagePortService>; |
70 | 67 |
71 MessagePortService(); | 68 MessagePortService(); |
72 ~MessagePortService(); | 69 ~MessagePortService(); |
73 | 70 |
(...skipping 11 matching lines...) Expand all Loading... |
85 | 82 |
86 // We need globally unique identifiers for each message port. | 83 // We need globally unique identifiers for each message port. |
87 int next_message_port_id_; | 84 int next_message_port_id_; |
88 | 85 |
89 DISALLOW_COPY_AND_ASSIGN(MessagePortService); | 86 DISALLOW_COPY_AND_ASSIGN(MessagePortService); |
90 }; | 87 }; |
91 | 88 |
92 } // namespace content | 89 } // namespace content |
93 | 90 |
94 #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ | 91 #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_ |
OLD | NEW |