OLD | NEW |
---|---|
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/observer_delegate.h" | 5 #include "content/browser/device_orientation/observer_delegate.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/device_orientation/device_data.h" | 8 #include "content/browser/device_orientation/device_data.h" |
9 #include "content/browser/device_orientation/motion.h" | |
9 #include "content/browser/device_orientation/orientation.h" | 10 #include "content/browser/device_orientation/orientation.h" |
10 #include "ipc/ipc_sender.h" | 11 #include "ipc/ipc_sender.h" |
11 | 12 |
12 namespace device_orientation { | 13 namespace device_orientation { |
13 | 14 |
14 ObserverDelegate::ObserverDelegate(DeviceData::Type device_data_type, | 15 ObserverDelegate::ObserverDelegate(DeviceData::Type device_data_type, |
15 Provider* provider, int render_view_id, | 16 Provider* provider, int render_view_id, |
16 IPC::Sender* sender) | 17 IPC::Sender* sender) |
17 : Observer(device_data_type), | 18 : Observer(device_data_type), |
18 provider_(provider), | 19 provider_(provider), |
19 render_view_id_(render_view_id), | 20 render_view_id_(render_view_id), |
20 sender_(sender) { | 21 sender_(sender) { |
21 provider_->AddObserver(this); | 22 provider_->AddObserver(this); |
22 } | 23 } |
23 | 24 |
24 ObserverDelegate::~ObserverDelegate() { | 25 ObserverDelegate::~ObserverDelegate() { |
25 provider_->RemoveObserver(this); | 26 provider_->RemoveObserver(this); |
26 } | 27 } |
27 | 28 |
28 void ObserverDelegate::OnDeviceDataUpdate( | 29 void ObserverDelegate::OnDeviceDataUpdate( |
29 const DeviceData* device_data, DeviceData::Type device_data_type) { | 30 const DeviceData* device_data, DeviceData::Type device_data_type) { |
30 scoped_refptr<const DeviceData> new_device_data(device_data); | 31 scoped_refptr<const DeviceData> new_device_data(device_data); |
31 if (!new_device_data.get()) | 32 if (!new_device_data.get()) |
32 new_device_data = EmptyDeviceData(device_data_type); | 33 new_device_data = EmptyDeviceData(device_data_type); |
33 | 34 |
34 sender_->Send(new_device_data->CreateIPCMessage(render_view_id_)); | 35 sender_->Send(new_device_data->CreateIPCMessage(render_view_id_)); |
35 } | 36 } |
36 | 37 |
37 DeviceData* ObserverDelegate::EmptyDeviceData(DeviceData::Type type) { | 38 DeviceData* ObserverDelegate::EmptyDeviceData(DeviceData::Type type) { |
hans
2012/08/13 13:35:19
maybe a switch here would be better:
switch (type
aousterh
2012/08/16 15:23:49
Done.
| |
38 DCHECK(type == DeviceData::kTypeOrientation); | 39 if (type == DeviceData::kTypeMotion) |
39 return new Orientation(); | 40 return new Motion(); |
41 else if (type == DeviceData::kTypeOrientation) | |
42 return new Orientation(); | |
43 else { | |
44 NOTREACHED(); | |
45 return NULL; | |
46 } | |
40 } | 47 } |
41 | 48 |
42 } // namespace device_orientation | 49 } // namespace device_orientation |
OLD | NEW |