Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 #include "WebDeviceMotionEventPump.h" | |
| 33 | |
| 34 #include <public/Platform.h> | |
| 35 #include <public/WebDeviceMotionData.h> | |
| 36 #include <public/WebDeviceMotionReader.h> | |
| 37 | |
| 38 | |
|
Peter Beverloo
2013/04/09 17:29:53
nit: two blank lines?
timvolodine
2013/04/10 19:06:12
Done.
| |
| 39 namespace WebKit { | |
| 40 | |
| 41 WebDeviceMotionEventPump& WebDeviceMotionEventPump::shared() | |
| 42 { | |
| 43 DEFINE_STATIC_LOCAL(WebDeviceMotionEventPump, webDeviceMotionEventPump, (kPu mpDelaySeconds)); | |
| 44 return webDeviceMotionEventPump; | |
| 45 } | |
| 46 | |
| 47 WebDeviceMotionEventPump::WebDeviceMotionEventPump(double delay_seconds) : | |
| 48 m_delaySeconds(delay_seconds), m_lastFireEventTimeMonotonic(0), m_stopped(tr ue), | |
|
Peter Beverloo
2013/04/09 17:29:53
nit: please have a single initializer per line.
timvolodine
2013/04/10 19:06:12
Done.
| |
| 49 m_lastDeviceMotionData(0), m_pumpTimer(this, &WebDeviceMotionEventPump::fire Event) | |
| 50 { | |
| 51 } | |
| 52 | |
| 53 void WebDeviceMotionEventPump::fireEvent(Timer<WebDeviceMotionEventPump>* timer) | |
|
Peter Beverloo
2013/04/09 17:29:53
The timer is not being used in this method, can we
timvolodine
2013/04/10 19:06:12
I've removed the name, but looks like it's not pos
| |
| 54 { | |
| 55 if (m_stopped) | |
| 56 return; | |
| 57 | |
| 58 m_lastFireEventTimeMonotonic = monotonicallyIncreasingTime(); | |
| 59 WebDeviceMotionReader* reader = WebKit::Platform::current()->deviceMotionRea der(); | |
| 60 WebDeviceMotionData data; | |
|
Peter Beverloo
2013/04/09 17:29:53
Do we need a temporary variable for the reader? We
timvolodine
2013/04/10 19:06:12
added asserts.
| |
| 61 reader->lastDeviceMotionData(data); | |
| 62 m_lastDeviceMotionData = PassRefPtr<WebCore::DeviceMotionData>(data); | |
| 63 | |
| 64 if (shouldFireEvent()) | |
| 65 DeviceMotionController::shared().didChangeDeviceMotion(m_lastDeviceMotio nData.get()); | |
|
Peter Beverloo
2013/04/09 17:29:53
It's a bit odd that we update m_lastFireEventTimeM
timvolodine
2013/04/10 19:06:12
the if (shouldFireEvent()) is meant as an optimiza
| |
| 66 | |
| 67 scheduleFireEvent(); | |
| 68 } | |
| 69 | |
| 70 void WebDeviceMotionEventPump::scheduleFireEvent() | |
| 71 { | |
| 72 if (m_pumpTimer.isActive()) | |
| 73 return; | |
| 74 double scheduleDelay = std::max<double>(m_delaySeconds - (monotonicallyIncre asingTime() - m_lastFireEventTimeMonotonic), 0); | |
|
Peter Beverloo
2013/04/09 17:29:53
nit: newline above this for readability.
Peter Beverloo
2013/04/09 17:29:53
This also assumes we'll fire at 10Hz for Device Mo
timvolodine
2013/04/10 19:06:12
Done.
timvolodine
2013/04/10 19:06:12
we can change the delay value as we want, but for
| |
| 75 m_pumpTimer.startOneShot(scheduleDelay); | |
| 76 } | |
| 77 | |
| 78 WebCore::DeviceMotionData* WebDeviceMotionEventPump::lastDeviceMotionData() | |
|
Peter Beverloo
2013/04/09 17:29:53
The pointer ownership situation is a bit unclear h
timvolodine
2013/04/10 19:06:12
ok, done.
| |
| 79 { | |
| 80 return m_lastDeviceMotionData.get(); | |
| 81 } | |
| 82 | |
| 83 bool WebDeviceMotionEventPump::shouldFireEvent() | |
| 84 { | |
| 85 // TODO(timvolodine): motion event should be fired only when values are diff erent from the values | |
|
Peter Beverloo
2013/04/09 17:29:53
nit: Blink style uses unattribute FIXMEs.
timvolodine
2013/04/10 19:06:12
Done.
| |
| 86 // of the previously fired event. | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 void WebDeviceMotionEventPump::start() | |
| 91 { | |
| 92 WebDeviceMotionReader* reader = WebKit::Platform::current()->deviceMotionRea der(); | |
|
Peter Beverloo
2013/04/09 17:29:53
Needs a NULL check.
timvolodine
2013/04/10 19:06:12
Done.
| |
| 93 reader->startUpdating(); | |
| 94 m_stopped = false; | |
| 95 scheduleFireEvent(); | |
| 96 } | |
| 97 | |
| 98 void WebDeviceMotionEventPump::stop() | |
| 99 { | |
| 100 WebDeviceMotionReader* reader = WebKit::Platform::current()->deviceMotionRea der(); | |
|
Peter Beverloo
2013/04/09 17:29:53
Needs a NULL check.
timvolodine
2013/04/10 19:06:12
Done.
| |
| 101 reader->stopUpdating(); | |
| 102 m_stopped = true; | |
| 103 } | |
| 104 | |
| 105 } // namespace WebKit | |
| OLD | NEW |