| 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 "device_sensor_event_pump.h" | 5 #include "device_sensor_event_pump.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/public/renderer/render_thread.h" | 8 #include "content/public/renderer/render_thread.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 | 11 |
| 12 // Default interval between successive polls, should take into account the | 12 // Default interval between successive polls, should take into account the |
| 13 // value of |kInertialSensorIntervalMillis| in | 13 // value of |kInertialSensorIntervalMillis| in |
| 14 // content/browser/device_orientation/inertial_sensor_consts.h. | 14 // content/browser/device_sensors/inertial_sensor_consts.h. |
| 15 const int DeviceSensorEventPump::kDefaultPumpDelayMillis = 50; | 15 const int DeviceSensorEventPump::kDefaultPumpDelayMillis = 50; |
| 16 | 16 |
| 17 int DeviceSensorEventPump::GetDelayMillis() const { | 17 int DeviceSensorEventPump::GetDelayMillis() const { |
| 18 return pump_delay_millis_; | 18 return pump_delay_millis_; |
| 19 } | 19 } |
| 20 | 20 |
| 21 DeviceSensorEventPump::DeviceSensorEventPump() | 21 DeviceSensorEventPump::DeviceSensorEventPump() |
| 22 : pump_delay_millis_(kDefaultPumpDelayMillis), | 22 : pump_delay_millis_(kDefaultPumpDelayMillis), |
| 23 state_(STOPPED) { | 23 state_(STOPPED) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 DeviceSensorEventPump::DeviceSensorEventPump(int pump_delay_millis) | 26 DeviceSensorEventPump::DeviceSensorEventPump(int pump_delay_millis) |
| 27 : pump_delay_millis_(pump_delay_millis), | 27 : pump_delay_millis_(pump_delay_millis), |
| 28 state_(STOPPED) { | 28 state_(STOPPED) { |
| 29 DCHECK(pump_delay_millis_ > 0); | 29 DCHECK_GE(pump_delay_millis_, 0); |
| 30 } | 30 } |
| 31 | 31 |
| 32 DeviceSensorEventPump::~DeviceSensorEventPump() { | 32 DeviceSensorEventPump::~DeviceSensorEventPump() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool DeviceSensorEventPump::RequestStart() { | 35 bool DeviceSensorEventPump::RequestStart() { |
| 36 DVLOG(2) << "requested start"; | 36 DVLOG(2) << "requested start"; |
| 37 | 37 |
| 38 if (state_ != STOPPED) | 38 if (state_ != STOPPED) |
| 39 return false; | 39 return false; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 DCHECK(!timer_.IsRunning()); | 78 DCHECK(!timer_.IsRunning()); |
| 79 | 79 |
| 80 if (InitializeReader(handle)) { | 80 if (InitializeReader(handle)) { |
| 81 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(GetDelayMillis()), | 81 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(GetDelayMillis()), |
| 82 this, &DeviceSensorEventPump::FireEvent); | 82 this, &DeviceSensorEventPump::FireEvent); |
| 83 state_ = RUNNING; | 83 state_ = RUNNING; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 } // namespace content | 87 } // namespace content |
| OLD | NEW |