| OLD | NEW |
| 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_DISPATCHER_H_ |
| 6 #define CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_DISPATCHER_H_ | 6 #define CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_DISPATCHER_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/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/task.h" | 15 #include "base/task.h" |
| 16 #include "chrome/common/notification_registrar.h" | 16 #include "chrome/common/notification_registrar.h" |
| 17 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 18 | 18 |
| 19 class MessagePortDispatcher : public NotificationObserver { | 19 class MessagePortDispatcher : public NotificationObserver { |
| 20 public: | 20 public: |
| 21 typedef std::vector<std::pair<string16, int> > QueuedMessages; | 21 typedef std::vector<std::pair<string16, std::vector<int> > > QueuedMessages; |
| 22 | 22 |
| 23 // Returns the MessagePortDispatcher singleton. | 23 // Returns the MessagePortDispatcher singleton. |
| 24 static MessagePortDispatcher* GetInstance(); | 24 static MessagePortDispatcher* GetInstance(); |
| 25 | 25 |
| 26 bool OnMessageReceived(const IPC::Message& message, | 26 bool OnMessageReceived(const IPC::Message& message, |
| 27 IPC::Message::Sender* sender, | 27 IPC::Message::Sender* sender, |
| 28 CallbackWithReturnValue<int>::Type* next_routing_id, | 28 CallbackWithReturnValue<int>::Type* next_routing_id, |
| 29 bool* message_was_ok); | 29 bool* message_was_ok); |
| 30 | 30 |
| 31 void UpdateMessagePort( | 31 void UpdateMessagePort( |
| 32 int message_port_id, | 32 int message_port_id, |
| 33 IPC::Message::Sender* sender, | 33 IPC::Message::Sender* sender, |
| 34 int routing_id, | 34 int routing_id, |
| 35 CallbackWithReturnValue<int>::Type* next_routing_id); | 35 CallbackWithReturnValue<int>::Type* next_routing_id); |
| 36 | 36 |
| 37 bool Send(IPC::Message* message); | 37 bool Send(IPC::Message* message); |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 friend struct DefaultSingletonTraits<MessagePortDispatcher>; | 40 friend struct DefaultSingletonTraits<MessagePortDispatcher>; |
| 41 | 41 |
| 42 MessagePortDispatcher(); | 42 MessagePortDispatcher(); |
| 43 ~MessagePortDispatcher(); | 43 ~MessagePortDispatcher(); |
| 44 | 44 |
| 45 // Message handlers. | 45 // Message handlers. |
| 46 void OnCreate(int* route_id, int* message_port_id); | 46 void OnCreate(int* route_id, int* message_port_id); |
| 47 void OnDestroy(int message_port_id); | 47 void OnDestroy(int message_port_id); |
| 48 void OnEntangle(int local_message_port_id, int remote_message_port_id); | 48 void OnEntangle(int local_message_port_id, int remote_message_port_id); |
| 49 void OnPostMessage(int sender_message_port_id, | 49 void OnPostMessage(int sender_message_port_id, |
| 50 const string16& message, | 50 const string16& message, |
| 51 int sent_message_port_id); | 51 const std::vector<int>& sent_message_port_ids); |
| 52 void OnQueueMessages(int message_port_id); | 52 void OnQueueMessages(int message_port_id); |
| 53 void OnSendQueuedMessages(int message_port_id, | 53 void OnSendQueuedMessages(int message_port_id, |
| 54 const QueuedMessages& queued_messages); | 54 const QueuedMessages& queued_messages); |
| 55 | 55 |
| 56 void PostMessageTo(int message_port_id, | 56 void PostMessageTo(int message_port_id, |
| 57 const string16& message, | 57 const string16& message, |
| 58 int sent_message_port_id); | 58 const std::vector<int>& sent_message_port_ids); |
| 59 | 59 |
| 60 // NotificationObserver interface. | 60 // NotificationObserver interface. |
| 61 void Observe(NotificationType type, | 61 void Observe(NotificationType type, |
| 62 const NotificationSource& source, | 62 const NotificationSource& source, |
| 63 const NotificationDetails& details); | 63 const NotificationDetails& details); |
| 64 | 64 |
| 65 struct MessagePort { | 65 struct MessagePort { |
| 66 // sender and route_id are what we need to send messages to the port. | 66 // sender and route_id are what we need to send messages to the port. |
| 67 IPC::Message::Sender* sender; | 67 IPC::Message::Sender* sender; |
| 68 int route_id; | 68 int route_id; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 87 // Valid only during IPC message dispatching. | 87 // Valid only during IPC message dispatching. |
| 88 IPC::Message::Sender* sender_; | 88 IPC::Message::Sender* sender_; |
| 89 CallbackWithReturnValue<int>::Type* next_routing_id_; | 89 CallbackWithReturnValue<int>::Type* next_routing_id_; |
| 90 | 90 |
| 91 NotificationRegistrar registrar_; | 91 NotificationRegistrar registrar_; |
| 92 | 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(MessagePortDispatcher); | 93 DISALLOW_COPY_AND_ASSIGN(MessagePortDispatcher); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 #endif // CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_DISPATCHER_H_ | 96 #endif // CHROME_BROWSER_WORKER_HOST_MESSAGE_PORT_DISPATCHER_H_ |
| OLD | NEW |