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

Side by Side Diff: content/browser/device_orientation/orientation_message_filter.cc

Issue 10698046: Implements part of Device Motion in the Renderer (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/browser/device_orientation/orientation_message_filter.h" 5 #include "content/browser/device_orientation/orientation_message_filter.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "content/browser/device_orientation/orientation.h" 8 #include "content/browser/device_orientation/orientation.h"
9 #include "content/browser/device_orientation/provider.h" 9 #include "content/browser/device_orientation/provider.h"
10 #include "content/browser/renderer_host/render_view_host_impl.h" 10 #include "content/browser/renderer_host/render_view_host_impl.h"
11 #include "content/common/device_orientation_messages.h" 11 #include "content/common/device_orientation_messages.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 13
14 using content::BrowserThread; 14 using content::BrowserThread;
15 15
16 namespace device_orientation { 16 namespace device_orientation {
17 17
18 OrientationMessageFilter::OrientationMessageFilter() : provider_(NULL) { 18 OrientationMessageFilter::OrientationMessageFilter() : provider_(NULL) {
19 } 19 }
20 20
21 OrientationMessageFilter::~OrientationMessageFilter() { 21 OrientationMessageFilter::~OrientationMessageFilter() {
22 } 22 }
23 23
24 class OrientationMessageFilter::ObserverDelegate 24 class OrientationMessageFilter::OrientationObserverDelegate
25 : public base::RefCounted<ObserverDelegate>, public Provider::Observer { 25 : public base::RefCounted<OrientationObserverDelegate>,
26 public Provider::OrientationObserver {
26 public: 27 public:
27 // Create ObserverDelegate that observes provider and forwards updates to 28 // Create OrientationObserverDelegate that observes provider and forwards
28 // render_view_id in process_id. 29 // updates to render_view_id in process_id.
29 // Will stop observing provider when destructed. 30 // Will stop observing provider when destructed.
30 ObserverDelegate(Provider* provider, 31 OrientationObserverDelegate(Provider* provider,
31 int render_view_id, 32 int render_view_id,
32 IPC::Sender* sender); 33 IPC::Sender* sender);
33 34
34 // From Provider::Observer. 35 // From Provider::OrientationObserver.
35 virtual void OnOrientationUpdate(const Orientation& orientation); 36 virtual void OnOrientationUpdate(const Orientation& orientation);
bulach 2012/07/02 12:47:56 nit: unrelated to your patch, but please fix the i
aousterh 2012/07/04 13:31:55 Done.
36 37
37 private: 38 private:
38 friend class base::RefCounted<ObserverDelegate>; 39 friend class base::RefCounted<OrientationObserverDelegate>;
39 virtual ~ObserverDelegate(); 40 virtual ~OrientationObserverDelegate();
40 41
41 scoped_refptr<Provider> provider_; 42 scoped_refptr<Provider> provider_;
42 int render_view_id_; 43 int render_view_id_;
43 IPC::Sender* sender_; // Weak pointer. 44 IPC::Sender* sender_; // Weak pointer.
44 45
45 DISALLOW_COPY_AND_ASSIGN(ObserverDelegate); 46 DISALLOW_COPY_AND_ASSIGN(OrientationObserverDelegate);
46 }; 47 };
47 48
48 OrientationMessageFilter::ObserverDelegate::ObserverDelegate(Provider* provider, 49 OrientationMessageFilter::OrientationObserverDelegate::
49 int render_view_id, 50 OrientationObserverDelegate(Provider* provider, int render_view_id,
50 IPC::Sender* sender) 51 IPC::Sender* sender)
51 : provider_(provider), 52 : provider_(provider),
52 render_view_id_(render_view_id), 53 render_view_id_(render_view_id),
53 sender_(sender) { 54 sender_(sender) {
54 provider_->AddObserver(this); 55 provider_->AddOrientationObserver(this);
55 } 56 }
56 57
57 OrientationMessageFilter::ObserverDelegate::~ObserverDelegate() { 58 OrientationMessageFilter::OrientationObserverDelegate::
58 provider_->RemoveObserver(this); 59 ~OrientationObserverDelegate() {
60 provider_->RemoveOrientationObserver(this);
59 } 61 }
60 62
61 void OrientationMessageFilter::ObserverDelegate::OnOrientationUpdate( 63 void OrientationMessageFilter::OrientationObserverDelegate::OnOrientationUpdate(
62 const Orientation& orientation) { 64 const Orientation& orientation) {
63 DeviceOrientationMsg_Updated_Params params; 65 DeviceOrientationMsg_Updated_Params params;
64 params.can_provide_alpha = orientation.can_provide_alpha_; 66 params.can_provide_alpha = orientation.can_provide_alpha_;
65 params.alpha = orientation.alpha_; 67 params.alpha = orientation.alpha_;
66 params.can_provide_beta = orientation.can_provide_beta_; 68 params.can_provide_beta = orientation.can_provide_beta_;
67 params.beta = orientation.beta_; 69 params.beta = orientation.beta_;
68 params.can_provide_gamma = orientation.can_provide_gamma_; 70 params.can_provide_gamma = orientation.can_provide_gamma_;
69 params.gamma = orientation.gamma_; 71 params.gamma = orientation.gamma_;
70 params.can_provide_absolute = orientation.can_provide_absolute_; 72 params.can_provide_absolute = orientation.can_provide_absolute_;
71 params.absolute = orientation.absolute_; 73 params.absolute = orientation.absolute_;
72 74
73 sender_->Send(new DeviceOrientationMsg_Updated(render_view_id_, params)); 75 sender_->Send(new DeviceOrientationMsg_Updated(render_view_id_, params));
74 } 76 }
75 77
76 bool OrientationMessageFilter::OnMessageReceived(const IPC::Message& message, 78 bool OrientationMessageFilter::OnMessageReceived(const IPC::Message& message,
77 bool* message_was_ok) { 79 bool* message_was_ok) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
79 bool handled = true; 81 bool handled = true;
80 IPC_BEGIN_MESSAGE_MAP_EX(OrientationMessageFilter, message, *message_was_ok) 82 IPC_BEGIN_MESSAGE_MAP_EX(OrientationMessageFilter, message, *message_was_ok)
81 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StartUpdating, OnStartUpdating) 83 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StartUpdating, OnStartUpdating)
82 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StopUpdating, OnStopUpdating) 84 IPC_MESSAGE_HANDLER(DeviceOrientationHostMsg_StopUpdating, OnStopUpdating)
83 IPC_MESSAGE_UNHANDLED(handled = false) 85 IPC_MESSAGE_UNHANDLED(handled = false)
84 IPC_END_MESSAGE_MAP() 86 IPC_END_MESSAGE_MAP()
85 return handled; 87 return handled;
86 } 88 }
87 89
88 void OrientationMessageFilter::OnStartUpdating(int render_view_id) { 90 void OrientationMessageFilter::OnStartUpdating(int render_view_id) {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
90 92
91 if (!provider_) 93 if (!provider_)
92 provider_ = Provider::GetInstance(); 94 provider_ = Provider::GetInstance();
93 95
94 observers_map_[render_view_id] = new ObserverDelegate(provider_, 96 observers_map_[render_view_id] = new OrientationObserverDelegate(provider_,
95 render_view_id, 97 render_view_id, this);
bulach 2012/07/02 12:47:56 nit: indent +2
aousterh 2012/07/04 13:31:55 Done.
96 this);
97 } 98 }
98 99
99 void OrientationMessageFilter::OnStopUpdating(int render_view_id) { 100 void OrientationMessageFilter::OnStopUpdating(int render_view_id) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
101 102
102 observers_map_.erase(render_view_id); 103 observers_map_.erase(render_view_id);
103 } 104 }
104 105
105 } // namespace device_orientation 106 } // namespace device_orientation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698