OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/logging.h" |
| 6 #include "content/browser/device_orientation/device_motion_provider.h" |
| 7 #include "content/common/device_motion_hardware_buffer.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 DeviceMotionProvider::DeviceMotionProvider() |
| 12 : is_started_(false) { |
| 13 size_t data_size = sizeof(DeviceMotionHardwareBuffer); |
| 14 bool res = device_motion_shared_memory_.CreateAndMapAnonymous(data_size); |
| 15 // TODO(timvolodine): consider not crashing the browser if the check fails. |
| 16 CHECK(res); |
| 17 DeviceMotionHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); |
| 18 memset(hwbuf, 0, sizeof(DeviceMotionHardwareBuffer)); |
| 19 } |
| 20 |
| 21 DeviceMotionProvider::~DeviceMotionProvider() { |
| 22 } |
| 23 |
| 24 base::SharedMemoryHandle DeviceMotionProvider::GetSharedMemoryHandleForProcess( |
| 25 base::ProcessHandle process) { |
| 26 base::SharedMemoryHandle renderer_handle; |
| 27 device_motion_shared_memory_.ShareToProcess(process, &renderer_handle); |
| 28 return renderer_handle; |
| 29 } |
| 30 |
| 31 void DeviceMotionProvider::StartFetchingDeviceMotionData() { |
| 32 if (is_started_) |
| 33 return; |
| 34 // TODO(timvolodine): call data_fetcher_->StartFetchingDeviceMotionData( |
| 35 // SharedMemoryAsHardwareBuffer()); |
| 36 is_started_ = true; |
| 37 } |
| 38 |
| 39 void DeviceMotionProvider::StopFetchingDeviceMotionData() { |
| 40 // TODO(timvolodine): call data_fetcher_->StopFetchingDeviceMotionData(); |
| 41 is_started_ = false; |
| 42 } |
| 43 |
| 44 DeviceMotionHardwareBuffer* DeviceMotionProvider:: |
| 45 SharedMemoryAsHardwareBuffer() { |
| 46 void* mem = device_motion_shared_memory_.memory(); |
| 47 CHECK(mem); |
| 48 return static_cast<DeviceMotionHardwareBuffer*>(mem); |
| 49 } |
| 50 |
| 51 } // namespace content |
OLD | NEW |