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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 fetcher_->Fetch(consumers_bitmask_); | 97 fetcher_->Fetch(consumers_bitmask_); |
98 } | 98 } |
99 | 99 |
100 // --- end of PollingThread methods | 100 // --- end of PollingThread methods |
101 | 101 |
102 DataFetcherSharedMemoryBase::DataFetcherSharedMemoryBase() | 102 DataFetcherSharedMemoryBase::DataFetcherSharedMemoryBase() |
103 : started_consumers_(0) { | 103 : started_consumers_(0) { |
104 } | 104 } |
105 | 105 |
106 DataFetcherSharedMemoryBase::~DataFetcherSharedMemoryBase() { | 106 DataFetcherSharedMemoryBase::~DataFetcherSharedMemoryBase() { |
107 StopFetchingDeviceData(CONSUMER_TYPE_MOTION); | 107 DCHECK_EQ(0u, started_consumers_); |
108 StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION); | |
109 | 108 |
110 // make sure polling thread stops asap. | 109 // make sure polling thread stops asap. |
111 if (polling_thread_) | 110 if (polling_thread_) |
112 polling_thread_->Stop(); | 111 polling_thread_->Stop(); |
113 | 112 |
114 STLDeleteContainerPairSecondPointers(shared_memory_map_.begin(), | 113 STLDeleteContainerPairSecondPointers(shared_memory_map_.begin(), |
115 shared_memory_map_.end()); | 114 shared_memory_map_.end()); |
116 } | 115 } |
117 | 116 |
118 bool DataFetcherSharedMemoryBase::StartFetchingDeviceData( | 117 bool DataFetcherSharedMemoryBase::StartFetchingDeviceData( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } else { | 155 } else { |
157 if (!Stop(consumer_type)) | 156 if (!Stop(consumer_type)) |
158 return false; | 157 return false; |
159 } | 158 } |
160 | 159 |
161 started_consumers_ ^= consumer_type; | 160 started_consumers_ ^= consumer_type; |
162 | 161 |
163 return true; | 162 return true; |
164 } | 163 } |
165 | 164 |
| 165 void DataFetcherSharedMemoryBase::StopFetchingAllDeviceData() { |
| 166 StopFetchingDeviceData(CONSUMER_TYPE_MOTION); |
| 167 StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION); |
| 168 } |
| 169 |
166 base::SharedMemoryHandle | 170 base::SharedMemoryHandle |
167 DataFetcherSharedMemoryBase::GetSharedMemoryHandleForProcess( | 171 DataFetcherSharedMemoryBase::GetSharedMemoryHandleForProcess( |
168 ConsumerType consumer_type, base::ProcessHandle process) { | 172 ConsumerType consumer_type, base::ProcessHandle process) { |
169 SharedMemoryMap::const_iterator it = shared_memory_map_.find(consumer_type); | 173 SharedMemoryMap::const_iterator it = shared_memory_map_.find(consumer_type); |
170 if (it == shared_memory_map_.end()) | 174 if (it == shared_memory_map_.end()) |
171 return base::SharedMemory::NULLHandle(); | 175 return base::SharedMemory::NULLHandle(); |
172 | 176 |
173 base::SharedMemoryHandle renderer_handle; | 177 base::SharedMemoryHandle renderer_handle; |
174 it->second->ShareToProcess(process, &renderer_handle); | 178 it->second->ShareToProcess(process, &renderer_handle); |
175 return renderer_handle; | 179 return renderer_handle; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 237 } |
234 | 238 |
235 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { | 239 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { |
236 return polling_thread_ ? polling_thread_->message_loop() : NULL; | 240 return polling_thread_ ? polling_thread_->message_loop() : NULL; |
237 } | 241 } |
238 | 242 |
239 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { | 243 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { |
240 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; | 244 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; |
241 } | 245 } |
242 | 246 |
243 | |
244 } // namespace content | 247 } // namespace content |
OLD | NEW |