OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_sensors/device_inertial_sensor_service.h" | 5 #include "content/browser/device_sensors/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_sensors/data_fetcher_shared_memory.h" | 10 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 DeviceInertialSensorService::DeviceInertialSensorService() | 14 DeviceInertialSensorService::DeviceInertialSensorService() |
15 : num_motion_readers_(0), | 15 : num_light_readers_(0), |
| 16 num_motion_readers_(0), |
16 num_orientation_readers_(0), | 17 num_orientation_readers_(0), |
17 is_shutdown_(false) { | 18 is_shutdown_(false) { |
18 } | 19 } |
19 | 20 |
20 DeviceInertialSensorService::~DeviceInertialSensorService() { | 21 DeviceInertialSensorService::~DeviceInertialSensorService() { |
21 } | 22 } |
22 | 23 |
23 DeviceInertialSensorService* DeviceInertialSensorService::GetInstance() { | 24 DeviceInertialSensorService* DeviceInertialSensorService::GetInstance() { |
24 return Singleton<DeviceInertialSensorService, | 25 return Singleton<DeviceInertialSensorService, |
25 LeakySingletonTraits<DeviceInertialSensorService> >::get(); | 26 LeakySingletonTraits<DeviceInertialSensorService> >::get(); |
(...skipping 26 matching lines...) Expand all Loading... |
52 | 53 |
53 switch (consumer_type) { | 54 switch (consumer_type) { |
54 case CONSUMER_TYPE_MOTION: | 55 case CONSUMER_TYPE_MOTION: |
55 num_motion_readers_ += delta; | 56 num_motion_readers_ += delta; |
56 DCHECK_GE(num_motion_readers_, 0); | 57 DCHECK_GE(num_motion_readers_, 0); |
57 return true; | 58 return true; |
58 case CONSUMER_TYPE_ORIENTATION: | 59 case CONSUMER_TYPE_ORIENTATION: |
59 num_orientation_readers_ += delta; | 60 num_orientation_readers_ += delta; |
60 DCHECK_GE(num_orientation_readers_ , 0); | 61 DCHECK_GE(num_orientation_readers_ , 0); |
61 return true; | 62 return true; |
| 63 case CONSUMER_TYPE_LIGHT: |
| 64 num_light_readers_ += delta; |
| 65 DCHECK_GE(num_light_readers_, 0); |
| 66 return true; |
62 default: | 67 default: |
63 NOTREACHED(); | 68 NOTREACHED(); |
64 } | 69 } |
65 return false; | 70 return false; |
66 } | 71 } |
67 | 72 |
68 int DeviceInertialSensorService::GetNumberConsumers( | 73 int DeviceInertialSensorService::GetNumberConsumers( |
69 ConsumerType consumer_type) const { | 74 ConsumerType consumer_type) const { |
70 switch (consumer_type) { | 75 switch (consumer_type) { |
71 case CONSUMER_TYPE_MOTION: | 76 case CONSUMER_TYPE_MOTION: |
72 return num_motion_readers_; | 77 return num_motion_readers_; |
73 case CONSUMER_TYPE_ORIENTATION: | 78 case CONSUMER_TYPE_ORIENTATION: |
74 return num_orientation_readers_; | 79 return num_orientation_readers_; |
| 80 case CONSUMER_TYPE_LIGHT: |
| 81 return num_light_readers_; |
75 default: | 82 default: |
76 NOTREACHED(); | 83 NOTREACHED(); |
77 } | 84 } |
78 return 0; | 85 return 0; |
79 } | 86 } |
80 | 87 |
81 base::SharedMemoryHandle | 88 base::SharedMemoryHandle |
82 DeviceInertialSensorService::GetSharedMemoryHandleForProcess( | 89 DeviceInertialSensorService::GetSharedMemoryHandleForProcess( |
83 ConsumerType consumer_type, base::ProcessHandle handle) { | 90 ConsumerType consumer_type, base::ProcessHandle handle) { |
84 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
85 return data_fetcher_->GetSharedMemoryHandleForProcess(consumer_type, handle); | 92 return data_fetcher_->GetSharedMemoryHandleForProcess(consumer_type, handle); |
86 } | 93 } |
87 | 94 |
88 void DeviceInertialSensorService::Shutdown() { | 95 void DeviceInertialSensorService::Shutdown() { |
89 if (data_fetcher_) { | 96 if (data_fetcher_) { |
90 data_fetcher_->StopFetchingAllDeviceData(); | 97 data_fetcher_->StopFetchingAllDeviceData(); |
91 data_fetcher_.reset(); | 98 data_fetcher_.reset(); |
92 } | 99 } |
93 is_shutdown_ = true; | 100 is_shutdown_ = true; |
94 } | 101 } |
95 | 102 |
96 void DeviceInertialSensorService::SetDataFetcherForTesting( | 103 void DeviceInertialSensorService::SetDataFetcherForTesting( |
97 DataFetcherSharedMemory* test_data_fetcher) { | 104 DataFetcherSharedMemory* test_data_fetcher) { |
98 if (data_fetcher_) | 105 if (data_fetcher_) |
99 data_fetcher_->StopFetchingAllDeviceData(); | 106 data_fetcher_->StopFetchingAllDeviceData(); |
100 data_fetcher_.reset(test_data_fetcher); | 107 data_fetcher_.reset(test_data_fetcher); |
101 } | 108 } |
102 | 109 |
103 } // namespace content | 110 } // namespace content |
OLD | NEW |