[Storage] Blob Storage Refactoring pt 1:
[chromium-blink-merge.git] / content / browser / message_port_service.h
blob623b26b0faa524ed56ae72b9b5691dc49c63618c
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_
6 #define CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_
8 #include <map>
9 #include <utility>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/singleton.h"
14 #include "base/strings/string16.h"
15 #include "ipc/ipc_message.h"
17 namespace content {
18 class MessagePortDelegate;
20 class MessagePortService {
21 public:
22 typedef std::vector<std::pair<base::string16, std::vector<int> > >
23 QueuedMessages;
25 // Returns the MessagePortService singleton.
26 static MessagePortService* GetInstance();
28 // These methods correspond to the message port related IPCs.
29 void Create(int route_id,
30 MessagePortDelegate* delegate,
31 int* message_port_id);
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,
35 const base::string16& message,
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 void ReleaseMessages(int message_port_id);
42 // Updates the information needed to reach a message port when it's sent to a
43 // (possibly different) process.
44 void UpdateMessagePort(int message_port_id,
45 MessagePortDelegate* delegate,
46 int routing_id);
48 // The message port is being transferred to a new renderer process, but the
49 // code doing that isn't able to immediately update the message port with a
50 // new filter and routing_id. This queues up all messages sent to this port
51 // until later ReleaseMessages is called for this port (this will happen
52 // automatically as soon as a WebMessagePortChannelImpl instance is created
53 // for this port in the renderer. The browser side code is still responsible
54 // for updating the port with a new filter before that happens. If ultimately
55 // transfering the port to a new process fails, ClosePort should be called to
56 // clean up the port.
57 void HoldMessages(int message_port_id);
59 // Closes and cleans up the message port.
60 void ClosePort(int message_port_id);
62 void OnMessagePortDelegateClosing(MessagePortDelegate* filter);
64 // Attempts to send the queued messages for a message port.
65 void SendQueuedMessagesIfPossible(int message_port_id);
67 private:
68 friend struct DefaultSingletonTraits<MessagePortService>;
70 MessagePortService();
71 ~MessagePortService();
73 void PostMessageTo(int message_port_id,
74 const base::string16& message,
75 const std::vector<int>& sent_message_port_ids);
77 // Handles the details of removing a message port id. Before calling this,
78 // verify that the message port id exists.
79 void Erase(int message_port_id);
81 struct MessagePort;
82 typedef std::map<int, MessagePort> MessagePorts;
83 MessagePorts message_ports_;
85 // We need globally unique identifiers for each message port.
86 int next_message_port_id_;
88 DISALLOW_COPY_AND_ASSIGN(MessagePortService);
91 } // namespace content
93 #endif // CONTENT_BROWSER_MESSAGE_PORT_SERVICE_H_