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

Side by Side Diff: content/renderer/device_sensors/device_orientation_absolute_event_pump.cc

Issue 2885203004: Refactor content/renderer/device_sensors to use device/generic_sensor instead of device/sensors (Closed)
Patch Set: updated content/renderer/BUILD.gn Created 3 years, 7 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
(Empty)
1 // Copyright 2014 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.
4
5 #include "content/renderer/device_sensors/device_orientation_absolute_event_pump .h"
6
7 #include "base/memory/ptr_util.h"
8 #include "content/public/renderer/render_thread.h"
9 #include "content/renderer/device_sensors/device_orientation_util.h"
10 #include "third_party/WebKit/public/platform/modules/device_orientation/WebDevic eOrientationListener.h"
11
12 namespace content {
13
14 DeviceOrientationAbsoluteEventPump::DeviceOrientationAbsoluteEventPump(
15 RenderThread* thread)
16 : DeviceSensorEventPump<blink::WebDeviceOrientationListener>(thread) {}
17
18 DeviceOrientationAbsoluteEventPump::~DeviceOrientationAbsoluteEventPump() {}
19
20 void DeviceOrientationAbsoluteEventPump::SendStartMessage() {
21 sensors_.push_back(base::MakeUnique<SensorEntry>(this));
22 GetSensor(device::mojom::SensorType::ABSOLUTE_ORIENTATION, sensors_[0].get());
Reilly Grant (use Gerrit) 2017/05/19 20:20:10 Can you combine these two lines into a single call
juncai 2017/05/20 00:55:02 Fixed it in a new CL: https://codereview.chromium.
23 }
24
25 void DeviceOrientationAbsoluteEventPump::SendFakeDataForTesting(
26 void* fake_data) {
27 blink::WebDeviceOrientationData data =
28 *static_cast<blink::WebDeviceOrientationData*>(fake_data);
29 listener()->DidChangeDeviceOrientation(data);
30 }
31
32 bool DeviceOrientationAbsoluteEventPump::CanStart() const {
33 DCHECK_EQ(1u, sensors_.size());
34 return sensors_[0]->active;
35 }
36
37 void DeviceOrientationAbsoluteEventPump::FireEvent() {
38 blink::WebDeviceOrientationData data;
39
40 DCHECK(listener());
41
42 if (GetDataFromSharedMemory(&data) && IsSignificantlyDifferent(data_, data)) {
43 data_ = data;
44 listener()->DidChangeDeviceOrientation(data);
45 }
46 }
47
48 bool DeviceOrientationAbsoluteEventPump::GetDataFromSharedMemory(
49 blink::WebDeviceOrientationData* data) {
50 DCHECK_EQ(1u, sensors_.size());
51 DCHECK_EQ(device::mojom::SensorType::ABSOLUTE_ORIENTATION, sensors_[0]->type);
52
53 if (!sensors_[0]->SensorReadingUpdated())
54 return false;
55
56 ComputeDeviceOrientationFromQuaternion(sensors_[0]->reading.values[0].value(),
57 sensors_[0]->reading.values[1].value(),
58 sensors_[0]->reading.values[2].value(),
59 sensors_[0]->reading.values[3].value(),
60 &data->alpha, &data->beta,
61 &data->gamma);
62 data->has_alpha = true;
63 data->has_beta = true;
64 data->has_gamma = true;
65 data->absolute = true;
66 return true;
67 }
68
69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698