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/data_fetcher_shared_memory_base.h" | 5 #include "content/browser/device_sensors/data_fetcher_shared_memory_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" |
9 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
10 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
11 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
12 #include "content/common/device_sensors/device_light_hardware_buffer.h" | 14 #include "content/common/device_sensors/device_light_hardware_buffer.h" |
13 #include "content/common/device_sensors/device_motion_hardware_buffer.h" | 15 #include "content/common/device_sensors/device_motion_hardware_buffer.h" |
14 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" | 16 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
18 namespace { | 20 namespace { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 if (started_consumers_ & consumer_type) | 124 if (started_consumers_ & consumer_type) |
123 return true; | 125 return true; |
124 | 126 |
125 void* buffer = GetSharedMemoryBuffer(consumer_type); | 127 void* buffer = GetSharedMemoryBuffer(consumer_type); |
126 if (!buffer) | 128 if (!buffer) |
127 return false; | 129 return false; |
128 | 130 |
129 if (GetType() != FETCHER_TYPE_DEFAULT) { | 131 if (GetType() != FETCHER_TYPE_DEFAULT) { |
130 if (!InitAndStartPollingThreadIfNecessary()) | 132 if (!InitAndStartPollingThreadIfNecessary()) |
131 return false; | 133 return false; |
132 polling_thread_->message_loop()->PostTask( | 134 polling_thread_->task_runner()->PostTask( |
133 FROM_HERE, | 135 FROM_HERE, base::Bind(&PollingThread::AddConsumer, |
134 base::Bind(&PollingThread::AddConsumer, | 136 base::Unretained(polling_thread_.get()), |
135 base::Unretained(polling_thread_.get()), | 137 consumer_type, buffer)); |
136 consumer_type, buffer)); | |
137 } else { | 138 } else { |
138 if (!Start(consumer_type, buffer)) | 139 if (!Start(consumer_type, buffer)) |
139 return false; | 140 return false; |
140 } | 141 } |
141 | 142 |
142 started_consumers_ |= consumer_type; | 143 started_consumers_ |= consumer_type; |
143 | 144 |
144 return true; | 145 return true; |
145 } | 146 } |
146 | 147 |
147 bool DataFetcherSharedMemoryBase::StopFetchingDeviceData( | 148 bool DataFetcherSharedMemoryBase::StopFetchingDeviceData( |
148 ConsumerType consumer_type) { | 149 ConsumerType consumer_type) { |
149 if (!(started_consumers_ & consumer_type)) | 150 if (!(started_consumers_ & consumer_type)) |
150 return true; | 151 return true; |
151 | 152 |
152 if (GetType() != FETCHER_TYPE_DEFAULT) { | 153 if (GetType() != FETCHER_TYPE_DEFAULT) { |
153 polling_thread_->message_loop()->PostTask( | 154 polling_thread_->task_runner()->PostTask( |
154 FROM_HERE, | 155 FROM_HERE, |
155 base::Bind(&PollingThread::RemoveConsumer, | 156 base::Bind(&PollingThread::RemoveConsumer, |
156 base::Unretained(polling_thread_.get()), | 157 base::Unretained(polling_thread_.get()), consumer_type)); |
157 consumer_type)); | |
158 } else { | 158 } else { |
159 if (!Stop(consumer_type)) | 159 if (!Stop(consumer_type)) |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 started_consumers_ ^= consumer_type; | 163 started_consumers_ ^= consumer_type; |
164 | 164 |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 242 |
243 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { | 243 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { |
244 return polling_thread_ ? polling_thread_->message_loop() : nullptr; | 244 return polling_thread_ ? polling_thread_->message_loop() : nullptr; |
245 } | 245 } |
246 | 246 |
247 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { | 247 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { |
248 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; | 248 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; |
249 } | 249 } |
250 | 250 |
251 } // namespace content | 251 } // namespace content |
OLD | NEW |