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

Unified Diff: ash/accelerometer/sensor_manager_delegate_chromeos.cc

Issue 680383007: DeviceOrientation API on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove implementation details from content/public/browser Created 6 years, 1 month 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: ash/accelerometer/sensor_manager_delegate_chromeos.cc
diff --git a/ash/accelerometer/sensor_manager_delegate_chromeos.cc b/ash/accelerometer/sensor_manager_delegate_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..efb9fe65e90eea2e5f66ca2d932b924829e39957
--- /dev/null
+++ b/ash/accelerometer/sensor_manager_delegate_chromeos.cc
@@ -0,0 +1,56 @@
+// Copyright 2014 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 "ash/accelerometer/sensor_manager_delegate_chromeos.h"
+
+#include "ash/accelerometer/accelerometer_controller.h"
+#include "ash/shell.h"
+#include "content/public/browser/sensor_manager_delegate.h"
+#include "ui/accelerometer/accelerometer_types.h"
+
+namespace ash {
+
+SensorManagerDelegateChromeOS::SensorManagerDelegateChromeOS()
+ : observing_accelerometer_(false) {
+ content::SensorManagerDelegate::SetDelegate(this);
+}
+
+SensorManagerDelegateChromeOS::~SensorManagerDelegateChromeOS() {
+ // Remove self as observer, if still active during shutdown.
+ if (observing_accelerometer_)
flackr 2014/11/13 00:07:34 Call StopFetchingDeviceOrientationData?
jonross 2014/11/13 01:34:05 Done.
+ Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
+ // Content Shell will have closed itself, do not remove as delegate
+}
+
+void SensorManagerDelegateChromeOS::OnAccelerometerUpdated(
+ const ui::AccelerometerUpdate& update) {
+ ui::AccelerometerSource source;
+
+ if (update.has(ui::ACCELEROMETER_SOURCE_SCREEN)) {
+ source = ui::ACCELEROMETER_SOURCE_SCREEN;
+ } else if (update.has(ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD)) {
+ source = ui::ACCELEROMETER_SOURCE_ATTACHED_KEYBOARD;
+ } else {
+ return;
+ }
+
+ double x = update.get(source).x();
+ double y = update.get(source).y();
+ double z = update.get(source).z();
flackr 2014/11/13 00:07:34 Variables only used once, just call update.get(sou
jonross 2014/11/13 01:34:05 Done.
+ orientation_callback_.Run(x, y, z);
+}
+
+void SensorManagerDelegateChromeOS::StartFetchingDeviceOrientationData(
+ const base::Callback<void(double, double, double)>& callback) {
+ Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
+ orientation_callback_ = callback;
flackr 2014/11/13 00:07:34 maybe D?CHECK(orientation_callback_.is_null()) to
jonross 2014/11/13 01:34:05 Done.
+ observing_accelerometer_ = true;
+}
+
+void SensorManagerDelegateChromeOS::StopFetchingDeviceOrientationData() {
+ Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
+ observing_accelerometer_ = false;
flackr 2014/11/13 00:07:34 orientation_callback_.Reset();
jonross 2014/11/13 01:34:05 Done.
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698