diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 17:00:42 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-13 17:00:42 +0000 |
commit | 9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8 (patch) | |
tree | b9991ef261fb6107a25947da1231c36e70919bd1 /chrome/browser/device_orientation | |
parent | dc8caba097e35e536697f3bf6605257317640d26 (diff) | |
download | chromium_src-9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8.zip chromium_src-9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8.tar.gz chromium_src-9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8.tar.bz2 |
Switch a bunch of remaining filters to derive from BrowserMessageFilters so that ResourceMessageFilter doesn't have to know about them and vice versa. A bunch of small cleanup in the process. I've added new message files for classes that want their messages dispatched on threads other than the IO.
Review URL: http://codereview.chromium.org/5698008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/device_orientation')
-rw-r--r-- | chrome/browser/device_orientation/message_filter.cc (renamed from chrome/browser/device_orientation/dispatcher_host.cc) | 50 | ||||
-rw-r--r-- | chrome/browser/device_orientation/message_filter.h (renamed from chrome/browser/device_orientation/dispatcher_host.h) | 26 |
2 files changed, 34 insertions, 42 deletions
diff --git a/chrome/browser/device_orientation/dispatcher_host.cc b/chrome/browser/device_orientation/message_filter.cc index 6bec33f..06f49cb 100644 --- a/chrome/browser/device_orientation/dispatcher_host.cc +++ b/chrome/browser/device_orientation/message_filter.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/device_orientation/dispatcher_host.h" +#include "chrome/browser/device_orientation/message_filter.h" #include "base/scoped_ptr.h" #include "chrome/browser/browser_thread.h" @@ -16,24 +16,21 @@ namespace device_orientation { -DispatcherHost::DispatcherHost(int process_id) - : process_id_(process_id), - observers_map_(), - provider_(NULL) { +MessageFilter::MessageFilter() : provider_(NULL) { } -DispatcherHost::~DispatcherHost() { +MessageFilter::~MessageFilter() { } -class DispatcherHost::ObserverDelegate +class MessageFilter::ObserverDelegate : public base::RefCounted<ObserverDelegate>, public Provider::Observer { public: // Create ObserverDelegate that observes provider and forwards updates to // render_view_id in process_id. // Will stop observing provider when destructed. ObserverDelegate(Provider* provider, - int process_id, - int render_view_id); + int render_view_id, + IPC::Message::Sender* sender); // From Provider::Observer. virtual void OnOrientationUpdate(const Orientation& orientation); @@ -43,26 +40,26 @@ class DispatcherHost::ObserverDelegate virtual ~ObserverDelegate(); scoped_refptr<Provider> provider_; - int process_id_; int render_view_id_; + IPC::Message::Sender* sender_; // Weak pointer. DISALLOW_COPY_AND_ASSIGN(ObserverDelegate); }; -DispatcherHost::ObserverDelegate::ObserverDelegate(Provider* provider, - int process_id, - int render_view_id) +MessageFilter::ObserverDelegate::ObserverDelegate(Provider* provider, + int render_view_id, + IPC::Message::Sender* sender) : provider_(provider), - process_id_(process_id), - render_view_id_(render_view_id) { + render_view_id_(render_view_id), + sender_(sender) { provider_->AddObserver(this); } -DispatcherHost::ObserverDelegate::~ObserverDelegate() { +MessageFilter::ObserverDelegate::~ObserverDelegate() { provider_->RemoveObserver(this); } -void DispatcherHost::ObserverDelegate::OnOrientationUpdate( +void MessageFilter::ObserverDelegate::OnOrientationUpdate( const Orientation& orientation) { ViewMsg_DeviceOrientationUpdated_Params params; params.can_provide_alpha = orientation.can_provide_alpha_; @@ -72,17 +69,14 @@ void DispatcherHost::ObserverDelegate::OnOrientationUpdate( params.can_provide_gamma = orientation.can_provide_gamma_; params.gamma = orientation.gamma_; - IPC::Message* message = new ViewMsg_DeviceOrientationUpdated(render_view_id_, - params); - CallRenderViewHost(process_id_, render_view_id_, &RenderViewHost::Send, - message); + sender_->Send(new ViewMsg_DeviceOrientationUpdated(render_view_id_, params)); } -bool DispatcherHost::OnMessageReceived(const IPC::Message& msg, - bool* msg_was_ok) { +bool MessageFilter::OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(DispatcherHost, msg, *msg_was_ok) + IPC_BEGIN_MESSAGE_MAP_EX(MessageFilter, message, *message_was_ok) IPC_MESSAGE_HANDLER(ViewHostMsg_DeviceOrientation_StartUpdating, OnStartUpdating) IPC_MESSAGE_HANDLER(ViewHostMsg_DeviceOrientation_StopUpdating, @@ -92,18 +86,18 @@ bool DispatcherHost::OnMessageReceived(const IPC::Message& msg, return handled; } -void DispatcherHost::OnStartUpdating(int render_view_id) { +void MessageFilter::OnStartUpdating(int render_view_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (!provider_) provider_ = Provider::GetInstance(); observers_map_[render_view_id] = new ObserverDelegate(provider_, - process_id_, - render_view_id); + render_view_id, + this); } -void DispatcherHost::OnStopUpdating(int render_view_id) { +void MessageFilter::OnStopUpdating(int render_view_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); observers_map_.erase(render_view_id); diff --git a/chrome/browser/device_orientation/dispatcher_host.h b/chrome/browser/device_orientation/message_filter.h index d30e8201..468fe6f 100644 --- a/chrome/browser/device_orientation/dispatcher_host.h +++ b/chrome/browser/device_orientation/message_filter.h @@ -2,28 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_DEVICE_ORIENTATION_DISPATCHER_HOST_H_ -#define CHROME_BROWSER_DEVICE_ORIENTATION_DISPATCHER_HOST_H_ +#ifndef CHROME_BROWSER_DEVICE_ORIENTATION_MESSAGE_FILTER_H_ +#define CHROME_BROWSER_DEVICE_ORIENTATION_MESSAGE_FILTER_H_ #include <map> -#include "base/ref_counted.h" +#include "chrome/browser/browser_message_filter.h" #include "chrome/browser/device_orientation/provider.h" -namespace IPC { class Message; } - namespace device_orientation { class Orientation; -class DispatcherHost : public base::RefCounted<DispatcherHost> { +class MessageFilter : public BrowserMessageFilter { public: - explicit DispatcherHost(int process_id); - bool OnMessageReceived(const IPC::Message& msg, bool* msg_was_ok); + MessageFilter(); + + // BrowserMessageFilter implementation. + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok); private: - virtual ~DispatcherHost(); - friend class base::RefCounted<DispatcherHost>; + virtual ~MessageFilter(); void OnStartUpdating(int render_view_id); void OnStopUpdating(int render_view_id); @@ -31,16 +31,14 @@ class DispatcherHost : public base::RefCounted<DispatcherHost> { // Helper class that observes a Provider and forwards updates to a RenderView. class ObserverDelegate; - int process_id_; - // map from render_view_id to ObserverDelegate. std::map<int, scoped_refptr<ObserverDelegate> > observers_map_; scoped_refptr<Provider> provider_; - DISALLOW_COPY_AND_ASSIGN(DispatcherHost); + DISALLOW_COPY_AND_ASSIGN(MessageFilter); }; } // namespace device_orientation -#endif // CHROME_BROWSER_DEVICE_ORIENTATION_DISPATCHER_HOST_H_ +#endif // CHROME_BROWSER_DEVICE_ORIENTATION_MESSAGE_FILTER_H_ |