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

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: Rebase Created 5 years, 11 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
« no previous file with comments | « ash/content/accelerometer/sensor_manager_delegate_chromeos.h ('k') | ash/shell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2b02297187d24078b448e0ca36b2cac3de2a9368
--- /dev/null
+++ b/ash/content/accelerometer/sensor_manager_delegate_chromeos.cc
@@ -0,0 +1,55 @@
+// 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/shell.h"
+#include "chromeos/accelerometer/accelerometer_reader.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();
+ // When this class is being destructed, content::SensorManagerDelegateChromeOS
+ // will have already been destructed. So calling SetDelegate(nullptr) to
+ // remove this class as the delegate will cause a crash.
+}
+
+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_reader()->AddObserver(this);
+ orientation_callback_ = callback;
+}
+
+void SensorManagerDelegateChromeOS::StopFetchingDeviceOrientationData() {
+ if (!orientation_callback_.is_null())
+ Shell::GetInstance()->accelerometer_reader()->RemoveObserver(this);
+ orientation_callback_.Reset();
+}
+
+} // namespace ash
« no previous file with comments | « ash/content/accelerometer/sensor_manager_delegate_chromeos.h ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698