Convert remaining WebContentsObservers loading callbacks to use RFH.
[chromium-blink-merge.git] / content / browser / message_port_message_filter.h
blob64d07d6c328b3e3e5430dcecb19d6aca0759424b
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_MESSAGE_FILTER_H_
6 #define CONTENT_BROWSER_MESSAGE_PORT_MESSAGE_FILTER_H_
8 #include "base/callback.h"
9 #include "content/common/content_export.h"
10 #include "content/public/browser/browser_message_filter.h"
12 namespace content {
14 // Filter for MessagePort related IPC messages (creating and destroying a
15 // MessagePort, sending a message via a MessagePort etc).
16 class CONTENT_EXPORT MessagePortMessageFilter : public BrowserMessageFilter {
17 public:
18 typedef base::Callback<int(void)> NextRoutingIDCallback;
20 // |next_routing_id| is owned by this object. It can be used up until
21 // OnChannelClosing.
22 explicit MessagePortMessageFilter(const NextRoutingIDCallback& callback);
24 // BrowserMessageFilter implementation.
25 virtual void OnChannelClosing() OVERRIDE;
26 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
27 virtual void OnDestruct() const OVERRIDE;
29 int GetNextRoutingID();
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);
37 protected:
38 // This is protected, so we can define sub classes for testing.
39 virtual ~MessagePortMessageFilter();
41 private:
42 friend class BrowserThread;
43 friend class base::DeleteHelper<MessagePortMessageFilter>;
45 // Message handlers.
46 void OnCreateMessagePort(int* route_id, int* message_port_id);
48 // This is guaranteed to be valid until OnChannelClosing is invoked, and it's
49 // not used after.
50 NextRoutingIDCallback next_routing_id_;
52 DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortMessageFilter);
55 } // namespace content
57 #endif // CONTENT_BROWSER_WORKER_MESSAGE_FILTER_H_