| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 bool DataFetcherSharedMemoryBase::StartFetchingDeviceData( | 127 bool DataFetcherSharedMemoryBase::StartFetchingDeviceData( |
| 128 ConsumerType consumer_type) { | 128 ConsumerType consumer_type) { |
| 129 if (started_consumers_ & consumer_type) | 129 if (started_consumers_ & consumer_type) |
| 130 return true; | 130 return true; |
| 131 | 131 |
| 132 void* buffer = GetSharedMemoryBuffer(consumer_type); | 132 void* buffer = GetSharedMemoryBuffer(consumer_type); |
| 133 if (!buffer) | 133 if (!buffer) |
| 134 return false; | 134 return false; |
| 135 | 135 |
| 136 size_t buffer_size = GetConsumerSharedMemoryBufferSize(consumer_type); |
| 137 // buffer size should be strictly positive because buffer is non-zero. |
| 138 DCHECK(buffer_size > 0); |
| 139 // make sure to clear any potentially stale values in the memory buffer. |
| 140 memset(buffer, 0, buffer_size); |
| 141 |
| 136 if (GetType() != FETCHER_TYPE_DEFAULT) { | 142 if (GetType() != FETCHER_TYPE_DEFAULT) { |
| 137 if (!InitAndStartPollingThreadIfNecessary()) | 143 if (!InitAndStartPollingThreadIfNecessary()) |
| 138 return false; | 144 return false; |
| 139 polling_thread_->task_runner()->PostTask( | 145 polling_thread_->task_runner()->PostTask( |
| 140 FROM_HERE, base::Bind(&PollingThread::AddConsumer, | 146 FROM_HERE, base::Bind(&PollingThread::AddConsumer, |
| 141 base::Unretained(polling_thread_.get()), | 147 base::Unretained(polling_thread_.get()), |
| 142 consumer_type, buffer)); | 148 consumer_type, buffer)); |
| 143 } else { | 149 } else { |
| 144 if (!Start(consumer_type, buffer)) | 150 if (!Start(consumer_type, buffer)) |
| 145 return false; | 151 return false; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 254 |
| 249 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { | 255 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { |
| 250 return polling_thread_ ? polling_thread_->message_loop() : nullptr; | 256 return polling_thread_ ? polling_thread_->message_loop() : nullptr; |
| 251 } | 257 } |
| 252 | 258 |
| 253 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { | 259 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { |
| 254 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; | 260 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; |
| 255 } | 261 } |
| 256 | 262 |
| 257 } // namespace content | 263 } // namespace content |
| OLD | NEW |