Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Unified Diff: webkit/chaos/ChaosGeolocation.cpp

Issue 149391: Chaos Demo Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/chaos/ChaosGeolocation.h ('k') | webkit/chaos/ChaosGeolocation.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/chaos/ChaosGeolocation.cpp
===================================================================
--- webkit/chaos/ChaosGeolocation.cpp (revision 0)
+++ webkit/chaos/ChaosGeolocation.cpp (revision 0)
@@ -0,0 +1,138 @@
+#include "ChaosCoordinates.h"
+#include "ChaosGeolocation.h"
+
+#include "base/logging.h"
+//#include "views/controls/button/radio_button.h"
+//#include "views/view.h"
+//#include "views/window/dialog_delegate.h"
+
+#include <math.h>
+
+namespace WebCore {
+
+class ChaosGeolocationExact : public ChaosGeolocationImpl {
+ public:
+ ChaosGeolocationExact() : timer_(NULL) {
+ timer_ = new Timer<ChaosGeolocationExact>(this,
+ &ChaosGeolocationExact::timerFired);
+ timer_->startRepeating(1);
+ }
+ ChaosCoordinates *coords() const {
+ return new ChaosCoordinates(1.234, 2.345, .00001);
+ }
+ std::string describe() const {
+ return "exact geolocation";
+ }
+ private:
+ void timerFired(Timer<ChaosGeolocationExact> *timer) {
+ DLOG(WARNING) << "tick!";
+ }
+
+ // FIXME: make this ref-counted, or something.
+ Timer<ChaosGeolocationExact> *timer_;
+};
+
+
+class ChaosGeolocationCity : public ChaosGeolocationImpl {
+ ChaosGeolocationImpl *source_;
+ static const double ACCURACY = .1;
+
+ static double round(double x) {
+ return x - fmod(x, ACCURACY);
+ }
+ public:
+ ChaosGeolocationCity(ChaosGeolocationImpl *source) : source_(source) {
+ }
+ ChaosCoordinates *coords() const {
+ ChaosCoordinates *sc = source_->coords();
+ ChaosCoordinates *mc = new ChaosCoordinates(round(sc->latitude()),
+ round(sc->longitude()),
+ ACCURACY);
+ delete sc;
+ return mc;
+ }
+ std::string describe() const {
+ return "city-level geoloication using " + source_->describe();
+ }
+};
+
+/* NOT WORKING!
+class ChooseGeolocationProviderView : public views::View,
+ public views::DialogDelegate {
+ public:
+ ChooseGeolocationProviderView() : exact_(NULL), city_(NULL) {
+ }
+ private:
+ views::RadioButton *exact_;
+ views::RadioButton *city_;
+
+ DISALLOW_COPY_AND_ASSIGN(ChooseGeolocationProviderView);
+};
+*/
+
+class ChaosGeolocationPowerbox {
+ public:
+ ChaosGeolocationImpl *choose() {
+ ChaosGeolocationImpl *choice;
+
+ // chooser_ = new ChooseGeolocationProviderView();
+
+ if ((time(NULL)&1) == 1)
+ choice = new ChaosGeolocationExact();
+ else
+ choice = new ChaosGeolocationCity(new ChaosGeolocationExact());
+ DLOG(WARNING) << "Chose geolocation: " << choice->describe();
+ return choice;
+ }
+ private:
+ // ChooseGeolocationProviderView *chooser_;
+};
+
+static ChaosGeolocationPowerbox powerbox;
+
+ChaosGeolocation::ChaosGeolocation() : impl_(0) {
+}
+
+ChaosGeoposition *ChaosGeolocation::lastPosition() {
+}
+
+void ChaosGeolocation::getCurrentPosition(PassRefPtr<ChaosPositionCallback> cb) {
+ oneShots_.add(GeoNotifier::create(cb));
+}
+
+
+int ChaosGeolocation::watchPosition(PassRefPtr<ChaosPositionCallback> cb) {
+ static int nextWatchId = 1; // Do not start at zero, can't use it
+ // in a map since it is reserved to
+ // mean "empty".
+
+ watchers_.set(nextWatchId++, GeoNotifier::create(cb));
+}
+
+void ChaosGeolocation::clearWatch(long watchId) {
+ watchers_.remove(watchId);
+}
+
+/*
+ChaosCoordinates *ChaosGeolocation::coords() {
+ if (!impl)
+ impl = powerbox.choose();
+ return impl->coords();
+}
+*/
+
+ChaosGeolocation::GeoNotifier::GeoNotifier(PassRefPtr<ChaosPositionCallback> successCallback)
+ : successCallback_(successCallback),
+ timer_(this, &ChaosGeolocation::GeoNotifier::timerFired) {
+ startTimer();
+}
+
+void ChaosGeolocation::GeoNotifier::startTimer() {
+ timer_.startRepeating(1);
+}
+
+void ChaosGeolocation::GeoNotifier::timerFired(Timer<GeoNotifier>*) {
+ DLOG(WARNING) << "tock!";
+}
+
+} // namespace WebCore
Property changes on: webkit/chaos/ChaosGeolocation.cpp
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « webkit/chaos/ChaosGeolocation.h ('k') | webkit/chaos/ChaosGeolocation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698