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

Side by Side Diff: content/browser/device_orientation/device_motion_provider.cc

Issue 18572014: Implement Android shared memory data fetcher for Device Motion. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@renderer-sync-12June-tryASYNC-2-bis-tryRebase-6
Patch Set: fixed comments, added proper singleton implementation and shutdown. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "content/browser/device_orientation/data_fetcher_shared_memory.h"
6 #include "content/browser/device_orientation/device_motion_provider.h" 7 #include "content/browser/device_orientation/device_motion_provider.h"
7 #include "content/common/device_motion_hardware_buffer.h" 8 #include "content/common/device_motion_hardware_buffer.h"
8 9
9 namespace content { 10 namespace content {
10 11
11 DeviceMotionProvider::DeviceMotionProvider() 12 DeviceMotionProvider::DeviceMotionProvider()
12 : is_started_(false) { 13 : is_started_(false) {
13 size_t data_size = sizeof(DeviceMotionHardwareBuffer); 14 size_t data_size = sizeof(DeviceMotionHardwareBuffer);
14 bool res = device_motion_shared_memory_.CreateAndMapAnonymous(data_size); 15 bool res = device_motion_shared_memory_.CreateAndMapAnonymous(data_size);
15 CHECK(res); 16 CHECK(res);
16 DeviceMotionHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); 17 DeviceMotionHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer();
17 memset(hwbuf, 0, sizeof(DeviceMotionHardwareBuffer)); 18 memset(hwbuf, 0, sizeof(DeviceMotionHardwareBuffer));
18 } 19 }
19 20
20 DeviceMotionProvider::~DeviceMotionProvider() { 21 DeviceMotionProvider::~DeviceMotionProvider() {
22 StopFetchingDeviceMotionData();
21 } 23 }
22 24
23 base::SharedMemoryHandle DeviceMotionProvider::GetSharedMemoryHandleForProcess( 25 base::SharedMemoryHandle DeviceMotionProvider::GetSharedMemoryHandleForProcess(
24 base::ProcessHandle process) { 26 base::ProcessHandle process) {
25 base::SharedMemoryHandle renderer_handle; 27 base::SharedMemoryHandle renderer_handle;
26 device_motion_shared_memory_.ShareToProcess(process, &renderer_handle); 28 device_motion_shared_memory_.ShareToProcess(process, &renderer_handle);
27 return renderer_handle; 29 return renderer_handle;
28 } 30 }
29 31
30 void DeviceMotionProvider::StartFetchingDeviceMotionData() { 32 void DeviceMotionProvider::StartFetchingDeviceMotionData() {
31 if (is_started_) 33 if (is_started_)
32 return; 34 return;
33 // FIXME: call data_fetcher_->StartFetchingDeviceMotionData( 35 DataFetcherSharedMemory::instance()->StartFetchingDeviceMotionData(
34 // SharedMemoryAsHardwareBuffer()); 36 SharedMemoryAsHardwareBuffer());
35 is_started_ = true; 37 is_started_ = true;
36 } 38 }
37 39
38 void DeviceMotionProvider::StopFetchingDeviceMotionData() { 40 void DeviceMotionProvider::StopFetchingDeviceMotionData() {
39 // FIXME: call data_fetcher_->StopFetchingDeviceMotionData(); 41 DataFetcherSharedMemory::instance()->StopFetchingDeviceMotionData();
40 is_started_ = false; 42 is_started_ = false;
41 } 43 }
42 44
43 DeviceMotionHardwareBuffer* DeviceMotionProvider:: 45 DeviceMotionHardwareBuffer* DeviceMotionProvider::
44 SharedMemoryAsHardwareBuffer() { 46 SharedMemoryAsHardwareBuffer() {
45 void* mem = device_motion_shared_memory_.memory(); 47 void* mem = device_motion_shared_memory_.memory();
46 CHECK(mem); 48 CHECK(mem);
47 return static_cast<DeviceMotionHardwareBuffer*>(mem); 49 return static_cast<DeviceMotionHardwareBuffer*>(mem);
48 } 50 }
49 51
50 } // namespace content 52 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698