OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <cmath> | 5 #include <cmath> |
6 #include <set> | 6 #include <set> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" |
10 #include "base/task.h" | 11 #include "base/task.h" |
11 #include "chrome/browser/browser_thread.h" | 12 #include "base/thread.h" |
12 #include "chrome/browser/device_orientation/orientation.h" | 13 #include "chrome/browser/device_orientation/orientation.h" |
13 #include "chrome/browser/device_orientation/provider_impl.h" | 14 #include "chrome/browser/device_orientation/provider_impl.h" |
14 | 15 |
15 namespace device_orientation { | 16 namespace device_orientation { |
16 | 17 |
17 ProviderImpl::ProviderImpl(const DataFetcherFactory factories[]) | 18 ProviderImpl::ProviderImpl(const DataFetcherFactory factories[]) |
18 : creator_loop_(MessageLoop::current()), | 19 : creator_loop_(MessageLoop::current()), |
19 ALLOW_THIS_IN_INITIALIZER_LIST(do_poll_method_factory_(this)) { | 20 ALLOW_THIS_IN_INITIALIZER_LIST(do_poll_method_factory_(this)) { |
20 for (const DataFetcherFactory* fp = factories; *fp; ++fp) | 21 for (const DataFetcherFactory* fp = factories; *fp; ++fp) |
21 factories_.push_back(*fp); | 22 factories_.push_back(*fp); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 144 |
144 void ProviderImpl::ScheduleDoPoll() { | 145 void ProviderImpl::ScheduleDoPoll() { |
145 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); | 146 DCHECK(MessageLoop::current() == polling_thread_->message_loop()); |
146 | 147 |
147 Task* task = do_poll_method_factory_.NewRunnableMethod(&ProviderImpl::DoPoll); | 148 Task* task = do_poll_method_factory_.NewRunnableMethod(&ProviderImpl::DoPoll); |
148 MessageLoop* polling_loop = polling_thread_->message_loop(); | 149 MessageLoop* polling_loop = polling_thread_->message_loop(); |
149 polling_loop->PostDelayedTask(FROM_HERE, task, SamplingIntervalMs()); | 150 polling_loop->PostDelayedTask(FROM_HERE, task, SamplingIntervalMs()); |
150 } | 151 } |
151 | 152 |
152 namespace { | 153 namespace { |
| 154 |
153 bool IsElementSignificantlyDifferent(bool can_provide_element1, | 155 bool IsElementSignificantlyDifferent(bool can_provide_element1, |
154 bool can_provide_element2, | 156 bool can_provide_element2, |
155 double element1, | 157 double element1, |
156 double element2) { | 158 double element2) { |
157 const double kThreshold = 0.1; | 159 const double kThreshold = 0.1; |
158 | 160 |
159 if (can_provide_element1 != can_provide_element2) | 161 if (can_provide_element1 != can_provide_element2) |
160 return true; | 162 return true; |
161 if (can_provide_element1 && | 163 if (can_provide_element1 && |
162 std::fabs(element1 - element2) >= kThreshold) | 164 std::fabs(element1 - element2) >= kThreshold) |
163 return true; | 165 return true; |
164 return false; | 166 return false; |
165 } | 167 } |
166 } // namespace | 168 } // namespace |
167 | 169 |
168 // Returns true if two orientations are considered different enough that | 170 // Returns true if two orientations are considered different enough that |
169 // observers should be notified of the new orientation. | 171 // observers should be notified of the new orientation. |
170 bool ProviderImpl::SignificantlyDifferent(const Orientation& o1, | 172 bool ProviderImpl::SignificantlyDifferent(const Orientation& o1, |
171 const Orientation& o2) { | 173 const Orientation& o2) { |
172 return IsElementSignificantlyDifferent(o1.can_provide_alpha_, | 174 return IsElementSignificantlyDifferent(o1.can_provide_alpha_, |
173 o2.can_provide_alpha_, | 175 o2.can_provide_alpha_, |
174 o1.alpha_, | 176 o1.alpha_, |
175 o2.alpha_) || | 177 o2.alpha_) || |
176 IsElementSignificantlyDifferent(o1.can_provide_beta_, | 178 IsElementSignificantlyDifferent(o1.can_provide_beta_, |
(...skipping 12 matching lines...) Expand all Loading... |
189 | 191 |
190 int fetcher_interval = data_fetcher_->MinSamplingIntervalMs(); | 192 int fetcher_interval = data_fetcher_->MinSamplingIntervalMs(); |
191 | 193 |
192 if (fetcher_interval > kDesiredSamplingIntervalMs) | 194 if (fetcher_interval > kDesiredSamplingIntervalMs) |
193 return fetcher_interval; | 195 return fetcher_interval; |
194 else | 196 else |
195 return kDesiredSamplingIntervalMs; | 197 return kDesiredSamplingIntervalMs; |
196 } | 198 } |
197 | 199 |
198 } // namespace device_orientation | 200 } // namespace device_orientation |
OLD | NEW |