| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GeoNotifier_h | 5 #ifndef GeoNotifier_h |
| 6 #define GeoNotifier_h | 6 #define GeoNotifier_h |
| 7 | 7 |
| 8 #include "modules/geolocation/PositionCallback.h" | 8 #include "modules/geolocation/PositionCallback.h" |
| 9 #include "modules/geolocation/PositionErrorCallback.h" | 9 #include "modules/geolocation/PositionErrorCallback.h" |
| 10 #include "modules/geolocation/PositionOptions.h" | 10 #include "modules/geolocation/PositionOptions.h" |
| 11 #include "platform/Timer.h" | 11 #include "platform/Timer.h" |
| 12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class Geolocation; | 16 class Geolocation; |
| 17 class Geoposition; | 17 class Position; |
| 18 class PositionError; | 18 class PositionError; |
| 19 | 19 |
| 20 class GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> { | 20 class GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> { |
| 21 public: | 21 public: |
| 22 static GeoNotifier* Create(Geolocation* geolocation, | 22 static GeoNotifier* Create(Geolocation* geolocation, |
| 23 PositionCallback* position_callback, | 23 PositionCallback* position_callback, |
| 24 PositionErrorCallback* position_error_callback, | 24 PositionErrorCallback* position_error_callback, |
| 25 const PositionOptions& options) { | 25 const PositionOptions& options) { |
| 26 return new GeoNotifier(geolocation, position_callback, | 26 return new GeoNotifier(geolocation, position_callback, |
| 27 position_error_callback, options); | 27 position_error_callback, options); |
| 28 } | 28 } |
| 29 DECLARE_TRACE(); | 29 DECLARE_TRACE(); |
| 30 | 30 |
| 31 const PositionOptions& Options() const { return options_; } | 31 const PositionOptions& Options() const { return options_; } |
| 32 | 32 |
| 33 // Sets the given error as the fatal error if there isn't one yet. | 33 // Sets the given error as the fatal error if there isn't one yet. |
| 34 // Starts the timer with an interval of 0. | 34 // Starts the timer with an interval of 0. |
| 35 void SetFatalError(PositionError*); | 35 void SetFatalError(PositionError*); |
| 36 | 36 |
| 37 bool UseCachedPosition() const { return use_cached_position_; } | 37 bool UseCachedPosition() const { return use_cached_position_; } |
| 38 | 38 |
| 39 // Tells the notifier to use a cached position and starts its timer with | 39 // Tells the notifier to use a cached position and starts its timer with |
| 40 // an interval of 0. | 40 // an interval of 0. |
| 41 void SetUseCachedPosition(); | 41 void SetUseCachedPosition(); |
| 42 | 42 |
| 43 void RunSuccessCallback(Geoposition*); | 43 void RunSuccessCallback(Position*); |
| 44 void RunErrorCallback(PositionError*); | 44 void RunErrorCallback(PositionError*); |
| 45 | 45 |
| 46 void StartTimer(); | 46 void StartTimer(); |
| 47 void StopTimer(); | 47 void StopTimer(); |
| 48 | 48 |
| 49 // Runs the error callback if there is a fatal error. Otherwise, if a | 49 // Runs the error callback if there is a fatal error. Otherwise, if a |
| 50 // cached position must be used, registers itself for receiving one. | 50 // cached position must be used, registers itself for receiving one. |
| 51 // Otherwise, the notifier has expired, and its error callback is run. | 51 // Otherwise, the notifier has expired, and its error callback is run. |
| 52 void TimerFired(TimerBase*); | 52 void TimerFired(TimerBase*); |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 GeoNotifier(Geolocation*, | 55 GeoNotifier(Geolocation*, |
| 56 PositionCallback*, | 56 PositionCallback*, |
| 57 PositionErrorCallback*, | 57 PositionErrorCallback*, |
| 58 const PositionOptions&); | 58 const PositionOptions&); |
| 59 | 59 |
| 60 Member<Geolocation> geolocation_; | 60 Member<Geolocation> geolocation_; |
| 61 Member<PositionCallback> success_callback_; | 61 Member<PositionCallback> success_callback_; |
| 62 Member<PositionErrorCallback> error_callback_; | 62 Member<PositionErrorCallback> error_callback_; |
| 63 const PositionOptions options_; | 63 const PositionOptions options_; |
| 64 Timer<GeoNotifier> timer_; | 64 Timer<GeoNotifier> timer_; |
| 65 Member<PositionError> fatal_error_; | 65 Member<PositionError> fatal_error_; |
| 66 bool use_cached_position_; | 66 bool use_cached_position_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 } // namespace blink | 69 } // namespace blink |
| 70 | 70 |
| 71 #endif // GeoNotifier_h | 71 #endif // GeoNotifier_h |
| OLD | NEW |