Fix auto-uninstall of legacy multi-install Chrome Frame.
[chromium-blink-merge.git] / content / renderer / device_sensors / device_sensor_event_pump.cc
blobeed3af27c0349432ffd9ba16acd5d8e4db138191
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
3 // found in the LICENSE file.
5 #include "device_sensor_event_pump.h"
7 #include "base/logging.h"
8 #include "content/public/renderer/render_thread.h"
10 namespace content {
12 // Default interval between successive polls, should take into account the
13 // value of |kInertialSensorIntervalMillis| in
14 // content/browser/device_sensors/inertial_sensor_consts.h.
15 const int DeviceSensorEventPump::kDefaultPumpDelayMillis = 50;
17 int DeviceSensorEventPump::GetDelayMillis() const {
18 return pump_delay_millis_;
21 DeviceSensorEventPump::DeviceSensorEventPump()
22 : pump_delay_millis_(kDefaultPumpDelayMillis),
23 state_(STOPPED) {
26 DeviceSensorEventPump::DeviceSensorEventPump(int pump_delay_millis)
27 : pump_delay_millis_(pump_delay_millis),
28 state_(STOPPED) {
29 DCHECK_GE(pump_delay_millis_, 0);
32 DeviceSensorEventPump::~DeviceSensorEventPump() {
35 bool DeviceSensorEventPump::RequestStart() {
36 DVLOG(2) << "requested start";
38 if (state_ != STOPPED)
39 return false;
41 DCHECK(!timer_.IsRunning());
43 if (SendStartMessage()) {
44 state_ = PENDING_START;
45 return true;
47 return false;
50 bool DeviceSensorEventPump::Stop() {
51 DVLOG(2) << "stop";
53 if (state_ == STOPPED)
54 return true;
56 DCHECK((state_ == PENDING_START && !timer_.IsRunning()) ||
57 (state_ == RUNNING && timer_.IsRunning()));
59 if (timer_.IsRunning())
60 timer_.Stop();
61 SendStopMessage();
62 state_ = STOPPED;
63 return true;
66 void DeviceSensorEventPump::Attach(RenderThread* thread) {
67 if (!thread)
68 return;
69 thread->AddObserver(this);
72 void DeviceSensorEventPump::OnDidStart(base::SharedMemoryHandle handle) {
73 DVLOG(2) << "did start sensor event pump";
75 if (state_ != PENDING_START)
76 return;
78 DCHECK(!timer_.IsRunning());
80 if (InitializeReader(handle)) {
81 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(GetDelayMillis()),
82 this, &DeviceSensorEventPump::FireEvent);
83 state_ = RUNNING;
87 } // namespace content