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

Unified Diff: content/renderer/device_orientation/device_orientation_event_pump.cc

Issue 236833003: Rename device_orientation to device_sensors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/device_orientation/device_orientation_event_pump.cc
diff --git a/content/renderer/device_orientation/device_orientation_event_pump.cc b/content/renderer/device_orientation/device_orientation_event_pump.cc
deleted file mode 100644
index 2ee6d218cd0da4d0594545dba2ecfba08bfdab2f..0000000000000000000000000000000000000000
--- a/content/renderer/device_orientation/device_orientation_event_pump.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "device_orientation_event_pump.h"
-
-#include <cmath>
-
-#include "content/common/device_orientation/device_orientation_messages.h"
-#include "content/public/renderer/render_thread.h"
-#include "third_party/WebKit/public/platform/WebDeviceOrientationListener.h"
-
-namespace content {
-
-const double DeviceOrientationEventPump::kOrientationThreshold = 0.1;
-
-DeviceOrientationEventPump::DeviceOrientationEventPump()
- : DeviceSensorEventPump(), listener_(0) {
-}
-
-DeviceOrientationEventPump::DeviceOrientationEventPump(int pump_delay_millis)
- : DeviceSensorEventPump(pump_delay_millis), listener_(0) {
-}
-
-DeviceOrientationEventPump::~DeviceOrientationEventPump() {
-}
-
-bool DeviceOrientationEventPump::SetListener(
- blink::WebDeviceOrientationListener* listener) {
- listener_ = listener;
- return listener_ ? RequestStart() : Stop();
-}
-
-bool DeviceOrientationEventPump::OnControlMessageReceived(
- const IPC::Message& message) {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(DeviceOrientationEventPump, message)
- IPC_MESSAGE_HANDLER(DeviceOrientationMsg_DidStartPolling, OnDidStart)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void DeviceOrientationEventPump::FireEvent() {
- DCHECK(listener_);
- blink::WebDeviceOrientationData data;
- if (reader_->GetLatestData(&data) && ShouldFireEvent(data)) {
- memcpy(&data_, &data, sizeof(data));
- listener_->didChangeDeviceOrientation(data);
- }
-}
-
-static bool IsSignificantlyDifferent(bool hasAngle1, double angle1,
- bool hasAngle2, double angle2) {
- if (hasAngle1 != hasAngle2)
- return true;
- return (hasAngle1 && std::fabs(angle1 - angle2) >=
- DeviceOrientationEventPump::kOrientationThreshold);
-}
-
-bool DeviceOrientationEventPump::ShouldFireEvent(
- const blink::WebDeviceOrientationData& data) const {
- if (!data.allAvailableSensorsAreActive)
- return false;
-
- if (!data.hasAlpha && !data.hasBeta && !data.hasGamma) {
- // no data can be provided, this is an all-null event.
- return true;
- }
-
- return IsSignificantlyDifferent(
- data_.hasAlpha, data_.alpha, data.hasAlpha, data.alpha) ||
- IsSignificantlyDifferent(
- data_.hasBeta, data_.beta, data.hasBeta, data.beta) ||
- IsSignificantlyDifferent(
- data_.hasGamma, data_.gamma, data.hasGamma, data.gamma);
-}
-
-bool DeviceOrientationEventPump::InitializeReader(
- base::SharedMemoryHandle handle) {
- memset(&data_, 0, sizeof(data_));
- if (!reader_)
- reader_.reset(new DeviceOrientationSharedMemoryReader());
- return reader_->Initialize(handle);
-}
-
-bool DeviceOrientationEventPump::SendStartMessage() {
- return RenderThread::Get()->Send(new DeviceOrientationHostMsg_StartPolling());
-}
-
-bool DeviceOrientationEventPump::SendStopMessage() {
- return RenderThread::Get()->Send(new DeviceOrientationHostMsg_StopPolling());
-}
-
-} // namespace content

Powered by Google App Engine
This is Rietveld 408576698