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

Unified Diff: content/browser/device_orientation/device_motion_provider.cc

Issue 14678012: Implement the content/renderer and content/browser part of the Device Motion API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compilation: peer_handle -> PeerHandle() Created 7 years, 5 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/browser/device_orientation/device_motion_provider.cc
diff --git a/content/browser/device_orientation/device_motion_provider.cc b/content/browser/device_orientation/device_motion_provider.cc
new file mode 100644
index 0000000000000000000000000000000000000000..41ebcf615b25616001c1c3e86357aea2b0e0a353
--- /dev/null
+++ b/content/browser/device_orientation/device_motion_provider.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 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 "base/logging.h"
+#include "content/browser/device_orientation/device_motion_provider.h"
+#include "content/common/device_motion_hardware_buffer.h"
+
+namespace content {
+
+DeviceMotionProvider::DeviceMotionProvider()
+ : is_started_(false) {
+ size_t data_size = sizeof(DeviceMotionHardwareBuffer);
+ bool res = device_motion_shared_memory_.CreateAndMapAnonymous(data_size);
+ // TODO(timvolodine): consider not crashing the browser if the check fails.
+ CHECK(res);
+ DeviceMotionHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer();
+ memset(hwbuf, 0, sizeof(DeviceMotionHardwareBuffer));
+}
+
+DeviceMotionProvider::~DeviceMotionProvider() {
+}
+
+base::SharedMemoryHandle DeviceMotionProvider::GetSharedMemoryHandleForProcess(
+ base::ProcessHandle process) {
+ base::SharedMemoryHandle renderer_handle;
+ device_motion_shared_memory_.ShareToProcess(process, &renderer_handle);
+ return renderer_handle;
+}
+
+void DeviceMotionProvider::StartFetchingDeviceMotionData() {
+ if (is_started_)
+ return;
+ // TODO(timvolodine): call data_fetcher_->StartFetchingDeviceMotionData(
+ // SharedMemoryAsHardwareBuffer());
+ is_started_ = true;
+}
+
+void DeviceMotionProvider::StopFetchingDeviceMotionData() {
+ // TODO(timvolodine): call data_fetcher_->StopFetchingDeviceMotionData();
+ is_started_ = false;
+}
+
+DeviceMotionHardwareBuffer* DeviceMotionProvider::
+ SharedMemoryAsHardwareBuffer() {
+ void* mem = device_motion_shared_memory_.memory();
+ CHECK(mem);
+ return static_cast<DeviceMotionHardwareBuffer*>(mem);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698