Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "modules/geolocation/GeoNotifier.h" | |
| 7 | |
| 8 #include "modules/geolocation/Geolocation.h" | |
| 9 #include "modules/geolocation/PositionCallback.h" | |
| 10 #include "modules/geolocation/PositionError.h" | |
| 11 #include "modules/geolocation/PositionErrorCallback.h" | |
| 12 #include "modules/geolocation/PositionOptions.h" | |
| 13 | |
| 14 namespace WebCore { | |
| 15 | |
| 16 GeoNotifier::GeoNotifier(Geolocation* geolocation, PassOwnPtr<PositionCallback> successCallback, PassOwnPtr<PositionErrorCallback> errorCallback, PositionOption s* options) | |
| 17 // FIXME : m_geolocation sould be removed, it makes circular dependancy. | |
|
Michael van Ouwerkerk
2014/07/15 13:47:08
How do you plan to fix this?
kihong
2014/07/15 15:05:16
"sould -> should" will be changed before landing.
| |
| 18 : m_geolocation(geolocation) | |
| 19 , m_successCallback(successCallback) | |
| 20 , m_errorCallback(errorCallback) | |
| 21 , m_options(options) | |
| 22 , m_timer(this, &GeoNotifier::timerFired) | |
| 23 , m_useCachedPosition(false) | |
| 24 { | |
| 25 ASSERT(m_geolocation); | |
| 26 ASSERT(m_successCallback); | |
| 27 ASSERT(m_options); | |
| 28 } | |
| 29 | |
| 30 void GeoNotifier::trace(Visitor* visitor) | |
| 31 { | |
| 32 visitor->trace(m_geolocation); | |
| 33 visitor->trace(m_options); | |
| 34 visitor->trace(m_fatalError); | |
| 35 } | |
| 36 | |
| 37 void GeoNotifier::setFatalError(PositionError* error) | |
| 38 { | |
| 39 // If a fatal error has already been set, stick with it. This makes sure tha t | |
| 40 // when permission is denied, this is the error reported, as required by the | |
| 41 // spec. | |
| 42 if (m_fatalError) | |
| 43 return; | |
| 44 | |
| 45 m_fatalError = error; | |
| 46 // An existing timer may not have a zero timeout. | |
| 47 m_timer.stop(); | |
| 48 m_timer.startOneShot(0, FROM_HERE); | |
| 49 } | |
| 50 | |
| 51 void GeoNotifier::setUseCachedPosition() | |
| 52 { | |
| 53 m_useCachedPosition = true; | |
| 54 m_timer.startOneShot(0, FROM_HERE); | |
| 55 } | |
| 56 | |
| 57 void GeoNotifier::runSuccessCallback(Geoposition* position) | |
| 58 { | |
| 59 // If we are here and the Geolocation permission is not approved, something has | |
| 60 // gone horribly wrong. | |
| 61 if (!m_geolocation->isAllowed()) | |
| 62 CRASH(); | |
| 63 | |
| 64 m_successCallback->handleEvent(position); | |
| 65 } | |
| 66 | |
| 67 void GeoNotifier::runErrorCallback(PositionError* error) | |
| 68 { | |
| 69 if (m_errorCallback) | |
| 70 m_errorCallback->handleEvent(error); | |
| 71 } | |
| 72 | |
| 73 void GeoNotifier::startTimer() | |
| 74 { | |
| 75 m_timer.startOneShot(m_options->timeout() / 1000.0, FROM_HERE); | |
| 76 } | |
| 77 | |
| 78 void GeoNotifier::stopTimer() | |
| 79 { | |
| 80 m_timer.stop(); | |
| 81 } | |
| 82 | |
| 83 void GeoNotifier::timerFired(Timer<GeoNotifier>*) | |
| 84 { | |
| 85 m_timer.stop(); | |
| 86 | |
| 87 // Test for fatal error first. This is required for the case where the Local Frame is | |
| 88 // disconnected and requests are cancelled. | |
| 89 if (m_fatalError) { | |
| 90 runErrorCallback(m_fatalError.get()); | |
| 91 // This will cause this notifier to be deleted. | |
| 92 m_geolocation->fatalErrorOccurred(this); | |
| 93 return; | |
| 94 } | |
| 95 | |
| 96 if (m_useCachedPosition) { | |
| 97 // Clear the cached position flag in case this is a watch request, which | |
| 98 // will continue to run. | |
| 99 m_useCachedPosition = false; | |
| 100 m_geolocation->requestUsesCachedPosition(this); | |
| 101 return; | |
| 102 } | |
| 103 | |
| 104 if (m_errorCallback) | |
| 105 m_errorCallback->handleEvent(PositionError::create(PositionError::TIMEOU T, "Timeout expired")); | |
| 106 m_geolocation->requestTimedOut(this); | |
| 107 } | |
| 108 | |
| 109 } // namespace WebCore | |
| OLD | NEW |