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
3 // found in the LICENSE file.
5 #include "content/browser/device_orientation/observer_delegate.h"
7 #include "base/logging.h"
8 #include "content/browser/device_orientation/device_data.h"
9 #include "content/browser/device_orientation/motion.h"
10 #include "content/browser/device_orientation/orientation.h"
11 #include "ipc/ipc_sender.h"
15 ObserverDelegate::ObserverDelegate(DeviceData::Type device_data_type
,
16 Provider
* provider
, int render_view_id
,
18 : Observer(device_data_type
),
20 render_view_id_(render_view_id
),
22 provider_
->AddObserver(this);
25 ObserverDelegate::~ObserverDelegate() {
26 provider_
->RemoveObserver(this);
29 void ObserverDelegate::OnDeviceDataUpdate(
30 const DeviceData
* device_data
, DeviceData::Type device_data_type
) {
31 scoped_refptr
<const DeviceData
> new_device_data(device_data
);
33 new_device_data
= EmptyDeviceData(device_data_type
);
35 sender_
->Send(new_device_data
->CreateIPCMessage(render_view_id_
));
38 DeviceData
* ObserverDelegate::EmptyDeviceData(DeviceData::Type type
) {
40 case DeviceData::kTypeMotion
:
42 case DeviceData::kTypeOrientation
:
43 return new Orientation();
44 case DeviceData::kTypeTest
:
51 } // namespace content