OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_orientation/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" |
11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
12 #include "content/common/device_orientation/device_motion_hardware_buffer.h" | 12 #include "content/common/device_sensors/device_motion_hardware_buffer.h" |
13 #include "content/common/device_orientation/device_orientation_hardware_buffer.h
" | 13 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 static size_t GetConsumerSharedMemoryBufferSize(ConsumerType consumer_type) { | 19 static size_t GetConsumerSharedMemoryBufferSize(ConsumerType consumer_type) { |
20 switch (consumer_type) { | 20 switch (consumer_type) { |
21 case CONSUMER_TYPE_MOTION: | 21 case CONSUMER_TYPE_MOTION: |
22 return sizeof(DeviceMotionHardwareBuffer); | 22 return sizeof(DeviceMotionHardwareBuffer); |
23 case CONSUMER_TYPE_ORIENTATION: | 23 case CONSUMER_TYPE_ORIENTATION: |
24 return sizeof(DeviceOrientationHardwareBuffer); | 24 return sizeof(DeviceOrientationHardwareBuffer); |
25 default: | 25 default: |
26 NOTREACHED(); | 26 NOTREACHED(); |
27 } | 27 } |
28 return 0; | 28 return 0; |
29 } | 29 } |
30 | 30 |
31 } | 31 } // namespace |
32 | 32 |
33 class DataFetcherSharedMemoryBase::PollingThread : public base::Thread { | 33 class DataFetcherSharedMemoryBase::PollingThread : public base::Thread { |
34 public: | 34 public: |
35 PollingThread(const char* name, DataFetcherSharedMemoryBase* fetcher); | 35 PollingThread(const char* name, DataFetcherSharedMemoryBase* fetcher); |
36 virtual ~PollingThread(); | 36 virtual ~PollingThread(); |
37 | 37 |
38 void AddConsumer(ConsumerType consumer_type, void* buffer); | 38 void AddConsumer(ConsumerType consumer_type, void* buffer); |
39 void RemoveConsumer(ConsumerType consumer_type); | 39 void RemoveConsumer(ConsumerType consumer_type); |
40 | 40 |
41 unsigned GetConsumersBitmask() const { return consumers_bitmask_; } | 41 unsigned GetConsumersBitmask() const { return consumers_bitmask_; } |
42 bool IsTimerRunning() const { return timer_ ? timer_->IsRunning() : false; } | 42 bool IsTimerRunning() const { return timer_ ? timer_->IsRunning() : false; } |
43 | 43 |
44 private: | 44 private: |
45 | |
46 void DoPoll(); | 45 void DoPoll(); |
47 | 46 |
48 unsigned consumers_bitmask_; | 47 unsigned consumers_bitmask_; |
49 DataFetcherSharedMemoryBase* fetcher_; | 48 DataFetcherSharedMemoryBase* fetcher_; |
50 scoped_ptr<base::RepeatingTimer<PollingThread> > timer_; | 49 scoped_ptr<base::RepeatingTimer<PollingThread> > timer_; |
51 | 50 |
52 DISALLOW_COPY_AND_ASSIGN(PollingThread); | 51 DISALLOW_COPY_AND_ASSIGN(PollingThread); |
53 }; | 52 }; |
54 | 53 |
55 // --- PollingThread methods | 54 // --- PollingThread methods |
(...skipping 26 matching lines...) Expand all Loading... |
82 | 81 |
83 void DataFetcherSharedMemoryBase::PollingThread::RemoveConsumer( | 82 void DataFetcherSharedMemoryBase::PollingThread::RemoveConsumer( |
84 ConsumerType consumer_type) { | 83 ConsumerType consumer_type) { |
85 DCHECK(fetcher_); | 84 DCHECK(fetcher_); |
86 if (!fetcher_->Stop(consumer_type)) | 85 if (!fetcher_->Stop(consumer_type)) |
87 return; | 86 return; |
88 | 87 |
89 consumers_bitmask_ ^= consumer_type; | 88 consumers_bitmask_ ^= consumer_type; |
90 | 89 |
91 if (!consumers_bitmask_) | 90 if (!consumers_bitmask_) |
92 timer_.reset(); // will also stop the timer. | 91 timer_.reset(); // will also stop the timer. |
93 } | 92 } |
94 | 93 |
95 void DataFetcherSharedMemoryBase::PollingThread::DoPoll() { | 94 void DataFetcherSharedMemoryBase::PollingThread::DoPoll() { |
96 DCHECK(fetcher_); | 95 DCHECK(fetcher_); |
97 DCHECK(consumers_bitmask_); | 96 DCHECK(consumers_bitmask_); |
98 fetcher_->Fetch(consumers_bitmask_); | 97 fetcher_->Fetch(consumers_bitmask_); |
99 } | 98 } |
100 | 99 |
101 // --- end of PollingThread methods | 100 // --- end of PollingThread methods |
102 | 101 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { | 235 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { |
237 return polling_thread_ ? polling_thread_->message_loop() : NULL; | 236 return polling_thread_ ? polling_thread_->message_loop() : NULL; |
238 } | 237 } |
239 | 238 |
240 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { | 239 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { |
241 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; | 240 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; |
242 } | 241 } |
243 | 242 |
244 | 243 |
245 } // namespace content | 244 } // namespace content |
OLD | NEW |