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

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: rebased 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "content/browser/device_orientation/device_motion_provider.h"
6
5 #include "base/logging.h" 7 #include "base/logging.h"
6 #include "content/browser/device_orientation/device_motion_provider.h" 8 #include "content/browser/device_orientation/data_fetcher_shared_memory.h"
7 #include "content/common/device_motion_hardware_buffer.h" 9 #include "content/common/device_motion_hardware_buffer.h"
8 10
9 namespace content { 11 namespace content {
10 12
11 DeviceMotionProvider::DeviceMotionProvider() 13 DeviceMotionProvider::DeviceMotionProvider()
12 : is_started_(false) { 14 : is_started_(false) {
13 size_t data_size = sizeof(DeviceMotionHardwareBuffer); 15 size_t data_size = sizeof(DeviceMotionHardwareBuffer);
14 bool res = device_motion_shared_memory_.CreateAndMapAnonymous(data_size); 16 bool res = device_motion_shared_memory_.CreateAndMapAnonymous(data_size);
15 // TODO(timvolodine): consider not crashing the browser if the check fails. 17 // TODO(timvolodine): consider not crashing the browser if the check fails.
16 CHECK(res); 18 CHECK(res);
17 DeviceMotionHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer(); 19 DeviceMotionHardwareBuffer* hwbuf = SharedMemoryAsHardwareBuffer();
18 memset(hwbuf, 0, sizeof(DeviceMotionHardwareBuffer)); 20 memset(hwbuf, 0, sizeof(DeviceMotionHardwareBuffer));
19 } 21 }
20 22
21 DeviceMotionProvider::~DeviceMotionProvider() { 23 DeviceMotionProvider::~DeviceMotionProvider() {
22 } 24 }
23 25
24 base::SharedMemoryHandle DeviceMotionProvider::GetSharedMemoryHandleForProcess( 26 base::SharedMemoryHandle DeviceMotionProvider::GetSharedMemoryHandleForProcess(
25 base::ProcessHandle process) { 27 base::ProcessHandle process) {
26 base::SharedMemoryHandle renderer_handle; 28 base::SharedMemoryHandle renderer_handle;
27 device_motion_shared_memory_.ShareToProcess(process, &renderer_handle); 29 device_motion_shared_memory_.ShareToProcess(process, &renderer_handle);
28 return renderer_handle; 30 return renderer_handle;
29 } 31 }
30 32
31 void DeviceMotionProvider::StartFetchingDeviceMotionData() { 33 void DeviceMotionProvider::StartFetchingDeviceMotionData() {
32 if (is_started_) 34 if (is_started_)
33 return; 35 return;
34 // TODO(timvolodine): call data_fetcher_->StartFetchingDeviceMotionData( 36 if (!data_fetcher_)
35 // SharedMemoryAsHardwareBuffer()); 37 data_fetcher_.reset(new DataFetcherSharedMemory);
38 data_fetcher_->StartFetchingDeviceMotionData(SharedMemoryAsHardwareBuffer());
36 is_started_ = true; 39 is_started_ = true;
37 } 40 }
38 41
39 void DeviceMotionProvider::StopFetchingDeviceMotionData() { 42 void DeviceMotionProvider::StopFetchingDeviceMotionData() {
40 // TODO(timvolodine): call data_fetcher_->StopFetchingDeviceMotionData(); 43 if (data_fetcher_)
44 data_fetcher_->StopFetchingDeviceMotionData();
41 is_started_ = false; 45 is_started_ = false;
42 } 46 }
43 47
44 DeviceMotionHardwareBuffer* DeviceMotionProvider:: 48 DeviceMotionHardwareBuffer* DeviceMotionProvider::
45 SharedMemoryAsHardwareBuffer() { 49 SharedMemoryAsHardwareBuffer() {
46 void* mem = device_motion_shared_memory_.memory(); 50 void* mem = device_motion_shared_memory_.memory();
47 CHECK(mem); 51 CHECK(mem);
48 return static_cast<DeviceMotionHardwareBuffer*>(mem); 52 return static_cast<DeviceMotionHardwareBuffer*>(mem);
49 } 53 }
50 54
51 } // namespace content 55 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/device_orientation/device_motion_provider.h ('k') | content/browser/device_orientation/provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698