• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
9 #include "content/public/browser/browser_message_filter.h"
10 
11 namespace content {
12 
13 // Filter for MessagePort related IPC messages (creating and destroying a
14 // MessagePort, sending a message via a MessagePort etc).
15 class MessagePortMessageFilter : public BrowserMessageFilter {
16  public:
17   typedef base::Callback<int(void)> NextRoutingIDCallback;
18 
19   // |next_routing_id| is owned by this object.  It can be used up until
20   // OnChannelClosing.
21   explicit MessagePortMessageFilter(const NextRoutingIDCallback& callback);
22 
23   // BrowserMessageFilter implementation.
24   virtual void OnChannelClosing() OVERRIDE;
25   virtual bool OnMessageReceived(const IPC::Message& message,
26                                  bool* message_was_ok) OVERRIDE;
27   virtual void OnDestruct() const OVERRIDE;
28 
29   int GetNextRoutingID();
30 
31  private:
32   friend class BrowserThread;
33   friend class base::DeleteHelper<MessagePortMessageFilter>;
34 
35   virtual ~MessagePortMessageFilter();
36 
37   // Message handlers.
38   void OnCreateMessagePort(int* route_id, int* message_port_id);
39 
40   // This is guaranteed to be valid until OnChannelClosing is invoked, and it's
41   // not used after.
42   NextRoutingIDCallback next_routing_id_;
43 
44   DISALLOW_IMPLICIT_CONSTRUCTORS(MessagePortMessageFilter);
45 };
46 
47 }  // namespace content
48 
49 #endif  // CONTENT_BROWSER_WORKER_MESSAGE_FILTER_H_
50