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 #ifndef GeoNotifier_h 6 #define GeoNotifier_h 7 8 #include "modules/geolocation/PositionCallback.h" 9 #include "modules/geolocation/PositionErrorCallback.h" 10 #include "platform/Timer.h" 11 #include "platform/heap/Handle.h" 12 13 namespace blink { 14 15 class Geolocation; 16 class Geoposition; 17 class PositionError; 18 class PositionOptions; 19 20 class GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> { 21 public: create(Geolocation * geolocation,PositionCallback * positionCallback,PositionErrorCallback * positionErrorCallback,PositionOptions * options)22 static GeoNotifier* create(Geolocation* geolocation, PositionCallback* positionCallback, PositionErrorCallback* positionErrorCallback, PositionOptions* options) 23 { 24 return new GeoNotifier(geolocation, positionCallback, positionErrorCallback, options); 25 } 26 void trace(Visitor*); 27 options()28 PositionOptions* options() const { return m_options.get(); }; 29 30 // Sets the given error as the fatal error if there isn't one yet. 31 // Starts the timer with an interval of 0. 32 void setFatalError(PositionError*); 33 useCachedPosition()34 bool useCachedPosition() const { return m_useCachedPosition; } 35 36 // Tells the notifier to use a cached position and starts its timer with 37 // an interval of 0. 38 void setUseCachedPosition(); 39 40 void runSuccessCallback(Geoposition*); 41 void runErrorCallback(PositionError*); 42 43 void startTimer(); 44 void stopTimer(); 45 46 // Runs the error callback if there is a fatal error. Otherwise, if a 47 // cached position must be used, registers itself for receiving one. 48 // Otherwise, the notifier has expired, and its error callback is run. 49 void timerFired(Timer<GeoNotifier>*); 50 51 private: 52 GeoNotifier(Geolocation*, PositionCallback*, PositionErrorCallback*, PositionOptions*); 53 54 Member<Geolocation> m_geolocation; 55 Member<PositionCallback> m_successCallback; 56 Member<PositionErrorCallback> m_errorCallback; 57 Member<PositionOptions> m_options; 58 Timer<GeoNotifier> m_timer; 59 Member<PositionError> m_fatalError; 60 bool m_useCachedPosition; 61 }; 62 63 } // namespace blink 64 65 #endif // GeoNotifier_h 66