Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: content/renderer/device_orientation/device_sensor_event_pump.cc

Issue 20707002: Implement Device Orientation using shared memory in content/renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "device_sensor_event_pump.h"
6
7 #include "base/logging.h"
8 #include "content/public/renderer/render_thread.h"
9
10 namespace content {
11
12 int DeviceSensorEventPump::GetDelayMillis() const {
13 return pump_delay_millis_;
14 }
15
16 DeviceSensorEventPump::DeviceSensorEventPump()
17 : pump_delay_millis_(kDefaultPumpDelayMillis),
18 state_(STOPPED) {
19 }
20
21 DeviceSensorEventPump::DeviceSensorEventPump(int pump_delay_millis)
22 : pump_delay_millis_(pump_delay_millis),
23 state_(STOPPED) {
24 DCHECK(pump_delay_millis_ > 0);
25 }
26
27 DeviceSensorEventPump::~DeviceSensorEventPump() {
28 }
29
30 bool DeviceSensorEventPump::RequestStart() {
31 DVLOG(2) << "requested start";
32
33 if (state_ != STOPPED)
34 return false;
35
36 DCHECK(!timer_.IsRunning());
37
38 if (SendStartMessage()) {
39 state_ = PENDING_START;
40 return true;
41 }
42 return false;
43 }
44
45 bool DeviceSensorEventPump::Stop() {
46 DVLOG(2) << "stop";
47
48 if (state_ == STOPPED)
49 return true;
50
51 DCHECK((state_ == PENDING_START && !timer_.IsRunning()) ||
52 (state_ == RUNNING && timer_.IsRunning()));
53
54 if (timer_.IsRunning())
55 timer_.Stop();
56 SendStopMessage();
57 state_ = STOPPED;
58 return true;
59 }
60
61 void DeviceSensorEventPump::Attach(RenderThread* thread) {
62 if (!thread)
63 return;
64 thread->AddObserver(this);
65 }
66
67 void DeviceSensorEventPump::OnDidStart(base::SharedMemoryHandle handle) {
68 DVLOG(2) << "did start sensor event pump";
69
70 if (state_ != PENDING_START)
71 return;
72
73 DCHECK(!timer_.IsRunning());
74
75 if (InitializeReader(handle)) {
76 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(GetDelayMillis()),
77 this, &DeviceSensorEventPump::FireEvent);
78 state_ = RUNNING;
79 }
80 }
81
82 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698