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

Side by Side Diff: chrome/browser/browser_message_filter.h

Issue 5541005: Make BrowserMessageFilter support dispatching messages on different threads. (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
« no previous file with comments | « chrome/browser/browser_io_message_filter.cc ('k') | chrome/browser/browser_message_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_BROWSER_IO_MESSAGE_FILTER_H_ 5 #ifndef CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_
6 #define CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ 6 #define CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/process.h" 9 #include "base/process.h"
10 #include "chrome/browser/browser_thread.h"
10 #include "ipc/ipc_channel_proxy.h" 11 #include "ipc/ipc_channel_proxy.h"
11 12
12 // Base class for message filters in the browser process that reside on the IO 13 // Base class for message filters in the browser process. You can receive and
13 // thread. 14 // send messages on any thread.
14 class BrowserIOMessageFilter : public IPC::ChannelProxy::MessageFilter, 15 class BrowserMessageFilter : public IPC::ChannelProxy::MessageFilter,
15 public IPC::Message::Sender { 16 public IPC::Message::Sender {
16 public: 17 public:
17 BrowserIOMessageFilter(); 18 BrowserMessageFilter();
18 virtual ~BrowserIOMessageFilter(); 19 virtual ~BrowserMessageFilter();
19 20
20 // IPC::ChannelProxy::MessageFilter methods. If you override them, make sure 21 // IPC::ChannelProxy::MessageFilter methods. If you override them, make sure
21 // to call them as well. 22 // to call them as well. These are always called on the IO thread.
22 virtual void OnFilterAdded(IPC::Channel* channel); 23 virtual void OnFilterAdded(IPC::Channel* channel);
23 virtual void OnChannelClosing(); 24 virtual void OnChannelClosing();
24 virtual void OnChannelConnected(int32 peer_pid); 25 virtual void OnChannelConnected(int32 peer_pid);
26 // DON'T OVERRIDE THIS! Override the other version below.
27 virtual bool OnMessageReceived(const IPC::Message& message);
25 28
26 // IPC::Message::Sender implementation: 29 // IPC::Message::Sender implementation. Can be called on any thread. Can't
27 virtual bool Send(IPC::Message* msg); 30 // send sync messages (since we don't want to block the browser on any other
31 // process).
32 virtual bool Send(IPC::Message* message);
33
34 // This allows the message handler to be called on a different thread for the
35 // given message. If you want to handle the message on a different thread,
36 // change |thread| to the thread id. Otherwise leave it alone.
brettw 2010/12/09 23:44:12 Can you give a little more detail here? I think wh
jam 2010/12/10 01:03:53 Thanks, OverrideThreadForMessage is clearer. swit
37 virtual void HandleMessageOnThread(const IPC::Message& message,
38 BrowserThread::ID* thread);
39
40 // Override this to receive messages.
41 // Your function will normally be called on the IO thread. However, if your
42 // HandleMessageOnThread modifies the thread used to dispatch the message,
43 // your function will be called on the requested thread.
44 virtual bool OnMessageReceived(const IPC::Message& message,
45 bool* message_was_ok) = 0;
28 46
29 protected: 47 protected:
48 // Can be called on any thread, after OnChannelConnected is called.
30 base::ProcessHandle peer_handle() { return peer_handle_; } 49 base::ProcessHandle peer_handle() { return peer_handle_; }
31 50
32 // Call this if a message couldn't be deserialized. This kills the renderer. 51 // Call this if a message couldn't be deserialized. This kills the renderer.
52 // Can be called on any thread.
33 void BadMessageReceived(uint32 msg_type); 53 void BadMessageReceived(uint32 msg_type);
34 54
35 private: 55 private:
56 // Used for dispatching a message to the derived class.
brettw 2010/12/09 23:44:12 Google comment style: "Dispatches a message to the
57 bool DispatchMessage(const IPC::Message& message);
58
36 IPC::Channel* channel_; 59 IPC::Channel* channel_;
37 base::ProcessHandle peer_handle_; 60 base::ProcessHandle peer_handle_;
38 }; 61 };
39 62
40 #endif // CHROME_BROWSER_BROWSER_IO_MESSAGE_FILTER_H_ 63 #endif // CHROME_BROWSER_BROWSER_MESSAGE_FILTER_H_
OLDNEW
« no previous file with comments | « chrome/browser/browser_io_message_filter.cc ('k') | chrome/browser/browser_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698