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

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

Issue 152893002: [DeviceLight API] Content Side Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix in Java file, stop() Created 6 years, 8 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_inertial_sensor_service.h" 5 #include "content/browser/device_orientation/device_inertial_sensor_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "content/browser/device_orientation/data_fetcher_shared_memory.h" 10 #include "content/browser/device_orientation/data_fetcher_shared_memory.h"
11 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 DeviceInertialSensorService::DeviceInertialSensorService() 15 DeviceInertialSensorService::DeviceInertialSensorService()
16 : num_motion_readers_(0), 16 : num_light_readers_(0),
17 num_motion_readers_(0),
17 num_orientation_readers_(0), 18 num_orientation_readers_(0),
18 is_shutdown_(false) { 19 is_shutdown_(false) {
19 } 20 }
20 21
21 DeviceInertialSensorService::~DeviceInertialSensorService() { 22 DeviceInertialSensorService::~DeviceInertialSensorService() {
22 } 23 }
23 24
24 DeviceInertialSensorService* DeviceInertialSensorService::GetInstance() { 25 DeviceInertialSensorService* DeviceInertialSensorService::GetInstance() {
25 return Singleton<DeviceInertialSensorService, 26 return Singleton<DeviceInertialSensorService,
26 LeakySingletonTraits<DeviceInertialSensorService> >::get(); 27 LeakySingletonTraits<DeviceInertialSensorService> >::get();
(...skipping 18 matching lines...) Expand all
45 data_fetcher_->StopFetchingDeviceData(consumer_type); 46 data_fetcher_->StopFetchingDeviceData(consumer_type);
46 } 47 }
47 48
48 bool DeviceInertialSensorService::ChangeNumberConsumers( 49 bool DeviceInertialSensorService::ChangeNumberConsumers(
49 ConsumerType consumer_type, int delta) { 50 ConsumerType consumer_type, int delta) {
50 DCHECK(thread_checker_.CalledOnValidThread()); 51 DCHECK(thread_checker_.CalledOnValidThread());
51 if (is_shutdown_) 52 if (is_shutdown_)
52 return false; 53 return false;
53 54
54 switch (consumer_type) { 55 switch (consumer_type) {
56 case CONSUMER_TYPE_LIGHT:
57 num_light_readers_ += delta;
58 DCHECK_GE(num_light_readers_ , 0);
59 return true;
55 case CONSUMER_TYPE_MOTION: 60 case CONSUMER_TYPE_MOTION:
56 num_motion_readers_ += delta; 61 num_motion_readers_ += delta;
57 DCHECK(num_motion_readers_ >= 0); 62 DCHECK_GE(num_motion_readers_ , 0);
58 return true; 63 return true;
59 case CONSUMER_TYPE_ORIENTATION: 64 case CONSUMER_TYPE_ORIENTATION:
60 num_orientation_readers_ += delta; 65 num_orientation_readers_ += delta;
61 DCHECK(num_orientation_readers_ >= 0); 66 DCHECK_GE(num_orientation_readers_ , 0);
62 return true; 67 return true;
63 default: 68 default:
64 NOTREACHED(); 69 NOTREACHED();
65 } 70 }
66 return false; 71 return false;
67 } 72 }
68 73
69 int DeviceInertialSensorService::GetNumberConsumers( 74 int DeviceInertialSensorService::GetNumberConsumers(
70 ConsumerType consumer_type) const { 75 ConsumerType consumer_type) const {
71 switch (consumer_type) { 76 switch (consumer_type) {
77 case CONSUMER_TYPE_LIGHT:
78 return num_light_readers_;
72 case CONSUMER_TYPE_MOTION: 79 case CONSUMER_TYPE_MOTION:
73 return num_motion_readers_; 80 return num_motion_readers_;
74 case CONSUMER_TYPE_ORIENTATION: 81 case CONSUMER_TYPE_ORIENTATION:
75 return num_orientation_readers_; 82 return num_orientation_readers_;
76 default: 83 default:
77 NOTREACHED(); 84 NOTREACHED();
78 } 85 }
79 return 0; 86 return 0;
80 } 87 }
81 88
82 base::SharedMemoryHandle 89 base::SharedMemoryHandle
83 DeviceInertialSensorService::GetSharedMemoryHandleForProcess( 90 DeviceInertialSensorService::GetSharedMemoryHandleForProcess(
84 ConsumerType consumer_type, base::ProcessHandle handle) { 91 ConsumerType consumer_type, base::ProcessHandle handle) {
85 DCHECK(thread_checker_.CalledOnValidThread()); 92 DCHECK(thread_checker_.CalledOnValidThread());
86 return data_fetcher_->GetSharedMemoryHandleForProcess(consumer_type, handle); 93 return data_fetcher_->GetSharedMemoryHandleForProcess(consumer_type, handle);
87 } 94 }
88 95
89 void DeviceInertialSensorService::Shutdown() { 96 void DeviceInertialSensorService::Shutdown() {
90 data_fetcher_.reset(); 97 data_fetcher_.reset();
91 is_shutdown_ = true; 98 is_shutdown_ = true;
92 } 99 }
93 100
94 void DeviceInertialSensorService::SetDataFetcherForTests( 101 void DeviceInertialSensorService::SetDataFetcherForTests(
95 DataFetcherSharedMemory* test_data_fetcher) { 102 DataFetcherSharedMemory* test_data_fetcher) {
96 data_fetcher_.reset(test_data_fetcher); 103 data_fetcher_.reset(test_data_fetcher);
97 } 104 }
98 105
99 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698