Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: chrome/browser/worker_host/message_port_service.h

Issue 6055002: Create a message filter for message port messages. This allows a nice cleanu... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_DISPATCHER_H_ 5 #ifndef CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_SERVICE_H_
6 #define CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_DISPATCHER_H_ 6 #define CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h"
15 #include "base/singleton.h" 14 #include "base/singleton.h"
16 #include "base/string16.h" 15 #include "base/string16.h"
17 #include "base/task.h" 16 #include "base/task.h"
18 #include "chrome/common/notification_observer.h"
19 #include "chrome/common/notification_registrar.h"
20 #include "ipc/ipc_message.h" 17 #include "ipc/ipc_message.h"
21 18
22 class MessagePortDispatcher : public NotificationObserver { 19 class WorkerMessageFilter;
20
21 class MessagePortService {
23 public: 22 public:
24 typedef std::vector<std::pair<string16, std::vector<int> > > QueuedMessages; 23 typedef std::vector<std::pair<string16, std::vector<int> > > QueuedMessages;
25 24
26 // Returns the MessagePortDispatcher singleton. 25 // Returns the MessagePortService singleton.
27 static MessagePortDispatcher* GetInstance(); 26 static MessagePortService* GetInstance();
28 27
29 bool OnMessageReceived(const IPC::Message& message, 28 // These methods correspond to the message port related IPCs.
30 IPC::Message::Sender* sender, 29 void Create(int route_id, WorkerMessageFilter* filter, int* message_port_id);
31 CallbackWithReturnValue<int>::Type* next_routing_id, 30 void Destroy(int message_port_id);
32 bool* message_was_ok); 31 void Entangle(int local_message_port_id, int remote_message_port_id);
32 void PostMessage(int sender_message_port_id,
33 const string16& message,
34 const std::vector<int>& sent_message_port_ids);
35 void QueueMessages(int message_port_id);
36 void SendQueuedMessages(int message_port_id,
37 const QueuedMessages& queued_messages);
33 38
34 // Updates the information needed to reach a message port when it's sent to a 39 // Updates the information needed to reach a message port when it's sent to a
35 // (possibly different) process. 40 // (possibly different) process.
36 void UpdateMessagePort( 41 void UpdateMessagePort(
37 int message_port_id, 42 int message_port_id,
38 IPC::Message::Sender* sender, 43 WorkerMessageFilter* filter,
39 int routing_id, 44 int routing_id);
40 CallbackWithReturnValue<int>::Type* next_routing_id); 45
46 void OnWorkerMessageFilterClosing(WorkerMessageFilter* filter);
41 47
42 // Attempts to send the queued messages for a message port. 48 // Attempts to send the queued messages for a message port.
43 void SendQueuedMessagesIfPossible(int message_port_id); 49 void SendQueuedMessagesIfPossible(int message_port_id);
44 50
45 bool Send(IPC::Message* message); 51 private:
52 friend struct DefaultSingletonTraits<MessagePortService>;
46 53
47 private: 54 MessagePortService();
48 friend struct DefaultSingletonTraits<MessagePortDispatcher>; 55 ~MessagePortService();
49
50 MessagePortDispatcher();
51 ~MessagePortDispatcher();
52
53 // Message handlers.
54 void OnCreate(int* route_id, int* message_port_id);
55 void OnDestroy(int message_port_id);
56 void OnEntangle(int local_message_port_id, int remote_message_port_id);
57 void OnPostMessage(int sender_message_port_id,
58 const string16& message,
59 const std::vector<int>& sent_message_port_ids);
60 void OnQueueMessages(int message_port_id);
61 void OnSendQueuedMessages(int message_port_id,
62 const QueuedMessages& queued_messages);
63 56
64 void PostMessageTo(int message_port_id, 57 void PostMessageTo(int message_port_id,
65 const string16& message, 58 const string16& message,
66 const std::vector<int>& sent_message_port_ids); 59 const std::vector<int>& sent_message_port_ids);
67 60
68 // NotificationObserver interface.
69 virtual void Observe(NotificationType type,
70 const NotificationSource& source,
71 const NotificationDetails& details);
72
73 // Handles the details of removing a message port id. Before calling this, 61 // Handles the details of removing a message port id. Before calling this,
74 // verify that the message port id exists. 62 // verify that the message port id exists.
75 void Erase(int message_port_id); 63 void Erase(int message_port_id);
76 64
77 struct MessagePort; 65 struct MessagePort;
78 typedef std::map<int, MessagePort> MessagePorts; 66 typedef std::map<int, MessagePort> MessagePorts;
79 MessagePorts message_ports_; 67 MessagePorts message_ports_;
80 68
81 // We need globally unique identifiers for each message port. 69 // We need globally unique identifiers for each message port.
82 int next_message_port_id_; 70 int next_message_port_id_;
83 71
84 // Valid only during IPC message dispatching. 72 DISALLOW_COPY_AND_ASSIGN(MessagePortService);
85 IPC::Message::Sender* sender_;
86 CallbackWithReturnValue<int>::Type* next_routing_id_;
87
88 NotificationRegistrar registrar_;
89
90 DISALLOW_COPY_AND_ASSIGN(MessagePortDispatcher);
91 }; 73 };
92 74
93 #endif // CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_DISPATCHER_H_ 75 #endif // CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698