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/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void RemoveConsumer(ConsumerType consumer_type); | 44 void RemoveConsumer(ConsumerType consumer_type); |
45 | 45 |
46 unsigned GetConsumersBitmask() const { return consumers_bitmask_; } | 46 unsigned GetConsumersBitmask() const { return consumers_bitmask_; } |
47 bool IsTimerRunning() const { return timer_ ? timer_->IsRunning() : false; } | 47 bool IsTimerRunning() const { return timer_ ? timer_->IsRunning() : false; } |
48 | 48 |
49 private: | 49 private: |
50 void DoPoll(); | 50 void DoPoll(); |
51 | 51 |
52 unsigned consumers_bitmask_; | 52 unsigned consumers_bitmask_; |
53 DataFetcherSharedMemoryBase* fetcher_; | 53 DataFetcherSharedMemoryBase* fetcher_; |
54 scoped_ptr<base::RepeatingTimer<PollingThread> > timer_; | 54 scoped_ptr<base::RepeatingTimer> timer_; |
55 | 55 |
56 DISALLOW_COPY_AND_ASSIGN(PollingThread); | 56 DISALLOW_COPY_AND_ASSIGN(PollingThread); |
57 }; | 57 }; |
58 | 58 |
59 // --- PollingThread methods | 59 // --- PollingThread methods |
60 | 60 |
61 DataFetcherSharedMemoryBase::PollingThread::PollingThread( | 61 DataFetcherSharedMemoryBase::PollingThread::PollingThread( |
62 const char* name, DataFetcherSharedMemoryBase* fetcher) | 62 const char* name, DataFetcherSharedMemoryBase* fetcher) |
63 : base::Thread(name), | 63 : base::Thread(name), |
64 consumers_bitmask_(0), | 64 consumers_bitmask_(0), |
65 fetcher_(fetcher) { | 65 fetcher_(fetcher) { |
66 } | 66 } |
67 | 67 |
68 DataFetcherSharedMemoryBase::PollingThread::~PollingThread() { | 68 DataFetcherSharedMemoryBase::PollingThread::~PollingThread() { |
69 } | 69 } |
70 | 70 |
71 void DataFetcherSharedMemoryBase::PollingThread::AddConsumer( | 71 void DataFetcherSharedMemoryBase::PollingThread::AddConsumer( |
72 ConsumerType consumer_type, void* buffer) { | 72 ConsumerType consumer_type, void* buffer) { |
73 DCHECK(fetcher_); | 73 DCHECK(fetcher_); |
74 if (!fetcher_->Start(consumer_type, buffer)) | 74 if (!fetcher_->Start(consumer_type, buffer)) |
75 return; | 75 return; |
76 | 76 |
77 consumers_bitmask_ |= consumer_type; | 77 consumers_bitmask_ |= consumer_type; |
78 | 78 |
79 if (!timer_ && fetcher_->GetType() == FETCHER_TYPE_POLLING_CALLBACK) { | 79 if (!timer_ && fetcher_->GetType() == FETCHER_TYPE_POLLING_CALLBACK) { |
80 timer_.reset(new base::RepeatingTimer<PollingThread>()); | 80 timer_.reset(new base::RepeatingTimer()); |
81 timer_->Start(FROM_HERE, | 81 timer_->Start(FROM_HERE, |
82 fetcher_->GetInterval(), | 82 fetcher_->GetInterval(), |
83 this, &PollingThread::DoPoll); | 83 this, &PollingThread::DoPoll); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 void DataFetcherSharedMemoryBase::PollingThread::RemoveConsumer( | 87 void DataFetcherSharedMemoryBase::PollingThread::RemoveConsumer( |
88 ConsumerType consumer_type) { | 88 ConsumerType consumer_type) { |
89 DCHECK(fetcher_); | 89 DCHECK(fetcher_); |
90 if (!fetcher_->Stop(consumer_type)) | 90 if (!fetcher_->Stop(consumer_type)) |
(...skipping 151 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 |