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

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

Issue 14678012: Implement the content/renderer and content/browser part of the Device Motion API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added unit test for device_motion_event_pump Created 7 years, 7 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 (c) 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_motion_event_pump.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h"
11 #include "base/shared_memory.h"
12 #include "device_motion_shared_memory_reader.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionData .h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebDeviceMotionList ener.h"
15
16 namespace content {
17
18 const double DeviceMotionEventPump::kPumpDelayMillis = 40;
19
20 DeviceMotionEventPump::DeviceMotionEventPump()
21 : listener_(0) {
22 }
23
24 DeviceMotionEventPump::~DeviceMotionEventPump() {
25 }
26
27 void DeviceMotionEventPump::setListener(
28 WebKit::WebDeviceMotionListener* listener) {
29 listener_ = listener;
30 listener_ ? startFetchingDeviceMotion() : stopFetchingDeviceMotion();
31 }
32
33 void DeviceMotionEventPump::setDeviceMotionReader(
34 DeviceMotionSharedMemoryReader* reader) {
35 reader_.reset(reader);
36 }
37
38 void DeviceMotionEventPump::startFetchingDeviceMotion() {
39 DVLOG(2) << "start fetching device motion";
40 if (timer_.IsRunning())
41 return;
42
43 if (!reader_.get())
44 setDeviceMotionReader(new DeviceMotionSharedMemoryReader);
45
46 reader_->startUpdating();
47 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kPumpDelayMillis),
48 this, &DeviceMotionEventPump::fireEvent);
darin (slow to review) 2013/05/29 06:41:53 nit: fix indentation
timvolodine 2013/05/29 18:59:06 Done.
49 }
50
51 void DeviceMotionEventPump::stopFetchingDeviceMotion() {
52 DVLOG(2) << "stop fetching device motion";
53 if (timer_.IsRunning()) {
54 timer_.Stop();
55 reader_->stopUpdating();
56 }
57 }
58
59 void DeviceMotionEventPump::fireEvent() {
60 DCHECK(listener_);
61 WebKit::WebDeviceMotionData data;
62 if (reader_->latestDeviceMotionData(data))
63 listener_->didChangeDeviceMotion(data);
64 }
65
66 void DeviceMotionEventPump::didChangeDeviceMotion(
67 const WebKit::WebDeviceMotionData& data) {
68 NOTIMPLEMENTED();
darin (slow to review) 2013/05/29 06:41:53 add a comment? why is DeviceMotionEventPump exten
timvolodine 2013/05/29 18:59:06 actually the listener interface is no longer relev
69 }
70
71 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698