Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_ |
| 6 | #define CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_ |
| 7 | |
| 8 | #include "base/callback.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 9 | #include "content/common/content_export.h" |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 10 | #include "content/public/browser/browser_message_filter.h" |
| 11 | |
| 12 | namespace content { |
| 13 | |
| 14 | // Filter for MessagePort related IPC messages (creating and destroying a |
| 15 | // MessagePort, sending a message via a MessagePort etc). |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 16 | class CONTENT_EXPORT MessagePortMessageFilter : public BrowserMessageFilter { |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 17 | public: |
| 18 | typedef base::Callback<int(void)> NextRoutingIDCallback; |
| 19 | |
| 20 | // |next_routing_id| is owned by this object. It can be used up until |
| 21 | // OnChannelClosing. |
| 22 | explicit MessagePortMessageFilter(const NextRoutingIDCallback& callback); |
| 23 | |
| 24 | // BrowserMessageFilter implementation. |
| 25 | virtual void OnChannelClosing() OVERRIDE; |
Torne (Richard Coles) | cedac22 | 2014-06-03 10:58:34 +0100 | [diff] [blame] | 26 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 27 | virtual void OnDestruct() const OVERRIDE; |
| 28 | |
| 29 | int GetNextRoutingID(); |
| 30 | |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 31 | // Updates message ports registered for |message_port_ids| and returns |
| 32 | // new routing IDs for the updated ports via |new_routing_ids|. |
| 33 | void UpdateMessagePortsWithNewRoutes( |
| 34 | const std::vector<int>& message_port_ids, |
| 35 | std::vector<int>* new_routing_ids); |
| 36 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 37 | protected: |
| 38 | // This is protected, so we can define sub classes for testing. |
| 39 | virtual ~MessagePortMessageFilter(); |
| 40 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 41 | private: |
| 42 | friend class BrowserThread; |
| 43 | friend class base::DeleteHelper<MessagePortMessageFilter>; |
| 44 | |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 45 | // Message handlers. |
| 46 | void OnCreateMessagePort(int* route_id, int* message_port_id); |
| 47 | |
| 48 | // This is guaranteed to be valid until OnChannelClosing is invoked, and it's |
| 49 | // not used after. |
| 50 | NextRoutingIDCallback next_routing_id_; |
| 51 | |
| 52 | DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortMessageFilter); |
| 53 | }; |
| 54 | |
| 55 | } // namespace content |
| 56 | |
| 57 | #endif // CONTENT_BROWSER_WORKER_MESSAGE_FILTER_H_ |