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

Unified Diff: ash/content/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: Reduce Singleton Usage 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/content/accelerometer/sensor_manager_delegate_chromeos.cc
diff --git a/ash/content/accelerometer/sensor_manager_delegate_chromeos.cc b/ash/content/accelerometer/sensor_manager_delegate_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9951759cce32fcc528f3aa6863065638b8be2177
--- /dev/null
+++ b/ash/content/accelerometer/sensor_manager_delegate_chromeos.cc
@@ -0,0 +1,53 @@
+// 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/content/accelerometer/sensor_manager_delegate_chromeos.h"
+
+#include "ash/accelerometer/accelerometer_controller.h"
+#include "ash/shell.h"
+#include "content/public/browser/sensor_manager_delegate_chromeos.h"
+#include "ui/accelerometer/accelerometer_types.h"
+
+namespace ash {
+
+SensorManagerDelegateChromeOS::SensorManagerDelegateChromeOS() {
+ content::SensorManagerDelegateChromeOS::SetDelegate(this);
+}
+
+SensorManagerDelegateChromeOS::~SensorManagerDelegateChromeOS() {
+ // Ensure we have stopped observing when shutdown.
+ StopFetchingDeviceOrientationData();
+ // Content Shell will have closed itself, do not remove as delegate
timvolodine 2014/11/26 19:32:19 nit: "." and the end also not sure what this comme
jonross 2014/11/26 23:17:56 When this class is being destructed, content::Sens
+}
+
+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;
+ }
+
+ orientation_callback_.Run(update.get(source).x(), update.get(source).y(),
+ update.get(source).z());
+}
+
+void SensorManagerDelegateChromeOS::StartFetchingDeviceOrientationData(
+ const content::OrientationDataCallback& callback) {
+ DCHECK(orientation_callback_.is_null());
+ Shell::GetInstance()->accelerometer_controller()->AddObserver(this);
+ orientation_callback_ = callback;
+}
+
+void SensorManagerDelegateChromeOS::StopFetchingDeviceOrientationData() {
+ if (!orientation_callback_.is_null())
+ Shell::GetInstance()->accelerometer_controller()->RemoveObserver(this);
+ orientation_callback_.Reset();
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698