| OLD | NEW |
| (Empty) | |
| 1 #include "ChaosCoordinates.h" |
| 2 #include "ChaosGeolocation.h" |
| 3 |
| 4 #include "base/logging.h" |
| 5 //#include "views/controls/button/radio_button.h" |
| 6 //#include "views/view.h" |
| 7 //#include "views/window/dialog_delegate.h" |
| 8 |
| 9 #include <math.h> |
| 10 |
| 11 namespace WebCore { |
| 12 |
| 13 class ChaosGeolocationExact : public ChaosGeolocationImpl { |
| 14 public: |
| 15 ChaosGeolocationExact() : timer_(NULL) { |
| 16 timer_ = new Timer<ChaosGeolocationExact>(this, |
| 17 &ChaosGeolocationExact::timerFired); |
| 18 timer_->startRepeating(1); |
| 19 } |
| 20 ChaosCoordinates *coords() const { |
| 21 return new ChaosCoordinates(1.234, 2.345, .00001); |
| 22 } |
| 23 std::string describe() const { |
| 24 return "exact geolocation"; |
| 25 } |
| 26 private: |
| 27 void timerFired(Timer<ChaosGeolocationExact> *timer) { |
| 28 DLOG(WARNING) << "tick!"; |
| 29 } |
| 30 |
| 31 // FIXME: make this ref-counted, or something. |
| 32 Timer<ChaosGeolocationExact> *timer_; |
| 33 }; |
| 34 |
| 35 |
| 36 class ChaosGeolocationCity : public ChaosGeolocationImpl { |
| 37 ChaosGeolocationImpl *source_; |
| 38 static const double ACCURACY = .1; |
| 39 |
| 40 static double round(double x) { |
| 41 return x - fmod(x, ACCURACY); |
| 42 } |
| 43 public: |
| 44 ChaosGeolocationCity(ChaosGeolocationImpl *source) : source_(source) { |
| 45 } |
| 46 ChaosCoordinates *coords() const { |
| 47 ChaosCoordinates *sc = source_->coords(); |
| 48 ChaosCoordinates *mc = new ChaosCoordinates(round(sc->latitude()), |
| 49 round(sc->longitude()), |
| 50 ACCURACY); |
| 51 delete sc; |
| 52 return mc; |
| 53 } |
| 54 std::string describe() const { |
| 55 return "city-level geoloication using " + source_->describe(); |
| 56 } |
| 57 }; |
| 58 |
| 59 /* NOT WORKING! |
| 60 class ChooseGeolocationProviderView : public views::View, |
| 61 public views::DialogDelegate { |
| 62 public: |
| 63 ChooseGeolocationProviderView() : exact_(NULL), city_(NULL) { |
| 64 } |
| 65 private: |
| 66 views::RadioButton *exact_; |
| 67 views::RadioButton *city_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(ChooseGeolocationProviderView); |
| 70 }; |
| 71 */ |
| 72 |
| 73 class ChaosGeolocationPowerbox { |
| 74 public: |
| 75 ChaosGeolocationImpl *choose() { |
| 76 ChaosGeolocationImpl *choice; |
| 77 |
| 78 // chooser_ = new ChooseGeolocationProviderView(); |
| 79 |
| 80 if ((time(NULL)&1) == 1) |
| 81 choice = new ChaosGeolocationExact(); |
| 82 else |
| 83 choice = new ChaosGeolocationCity(new ChaosGeolocationExact()); |
| 84 DLOG(WARNING) << "Chose geolocation: " << choice->describe(); |
| 85 return choice; |
| 86 } |
| 87 private: |
| 88 // ChooseGeolocationProviderView *chooser_; |
| 89 }; |
| 90 |
| 91 static ChaosGeolocationPowerbox powerbox; |
| 92 |
| 93 ChaosGeolocation::ChaosGeolocation() : impl_(0) { |
| 94 } |
| 95 |
| 96 ChaosGeoposition *ChaosGeolocation::lastPosition() { |
| 97 } |
| 98 |
| 99 void ChaosGeolocation::getCurrentPosition(PassRefPtr<ChaosPositionCallback> cb)
{ |
| 100 oneShots_.add(GeoNotifier::create(cb)); |
| 101 } |
| 102 |
| 103 |
| 104 int ChaosGeolocation::watchPosition(PassRefPtr<ChaosPositionCallback> cb) { |
| 105 static int nextWatchId = 1; // Do not start at zero, can't use it |
| 106 // in a map since it is reserved to |
| 107 // mean "empty". |
| 108 |
| 109 watchers_.set(nextWatchId++, GeoNotifier::create(cb)); |
| 110 } |
| 111 |
| 112 void ChaosGeolocation::clearWatch(long watchId) { |
| 113 watchers_.remove(watchId); |
| 114 } |
| 115 |
| 116 /* |
| 117 ChaosCoordinates *ChaosGeolocation::coords() { |
| 118 if (!impl) |
| 119 impl = powerbox.choose(); |
| 120 return impl->coords(); |
| 121 } |
| 122 */ |
| 123 |
| 124 ChaosGeolocation::GeoNotifier::GeoNotifier(PassRefPtr<ChaosPositionCallback> suc
cessCallback) |
| 125 : successCallback_(successCallback), |
| 126 timer_(this, &ChaosGeolocation::GeoNotifier::timerFired) { |
| 127 startTimer(); |
| 128 } |
| 129 |
| 130 void ChaosGeolocation::GeoNotifier::startTimer() { |
| 131 timer_.startRepeating(1); |
| 132 } |
| 133 |
| 134 void ChaosGeolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*) { |
| 135 DLOG(WARNING) << "tock!"; |
| 136 } |
| 137 |
| 138 } // namespace WebCore |
| OLD | NEW |