1197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// Copyright 2014 The Chromium Authors. All rights reserved.
2197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// Use of this source code is governed by a BSD-style license that can be
3197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch// found in the LICENSE file.
4197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
5197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#ifndef GeoNotifier_h
6197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#define GeoNotifier_h
7197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
8c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "modules/geolocation/PositionCallback.h"
9c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)#include "modules/geolocation/PositionErrorCallback.h"
10197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "platform/Timer.h"
11197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "platform/heap/Handle.h"
12197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
13c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
14197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
15197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass Geolocation;
16197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass Geoposition;
17197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass PositionError;
18197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass PositionOptions;
19197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
20197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass GeoNotifier : public GarbageCollectedFinalized<GeoNotifier> {
21197021e6b966cfb06891637935ef33fff06433d1Ben Murdochpublic:
227242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    static GeoNotifier* create(Geolocation* geolocation, PositionCallback* positionCallback, PositionErrorCallback* positionErrorCallback, PositionOptions* options)
23197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    {
24197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return new GeoNotifier(geolocation, positionCallback, positionErrorCallback, options);
25197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    }
26197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void trace(Visitor*);
27197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
28197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    PositionOptions* options() const { return m_options.get(); };
29197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
30197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // Sets the given error as the fatal error if there isn't one yet.
31197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // Starts the timer with an interval of 0.
32197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void setFatalError(PositionError*);
33197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
34197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool useCachedPosition() const { return m_useCachedPosition; }
35197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
36197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // Tells the notifier to use a cached position and starts its timer with
37197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // an interval of 0.
38197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void setUseCachedPosition();
39197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
40197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void runSuccessCallback(Geoposition*);
41197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void runErrorCallback(PositionError*);
42197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
43197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void startTimer();
44197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void stopTimer();
45197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
46197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // Runs the error callback if there is a fatal error. Otherwise, if a
47197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // cached position must be used, registers itself for receiving one.
48197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // Otherwise, the notifier has expired, and its error callback is run.
49197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    void timerFired(Timer<GeoNotifier>*);
50197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
51197021e6b966cfb06891637935ef33fff06433d1Ben Murdochprivate:
527242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    GeoNotifier(Geolocation*, PositionCallback*, PositionErrorCallback*, PositionOptions*);
53197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
54197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    Member<Geolocation> m_geolocation;
557242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    Member<PositionCallback> m_successCallback;
567242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci    Member<PositionErrorCallback> m_errorCallback;
57197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    Member<PositionOptions> m_options;
58197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    Timer<GeoNotifier> m_timer;
59197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    Member<PositionError> m_fatalError;
60197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    bool m_useCachedPosition;
61197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch};
62197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
63c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
64197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
65197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#endif // GeoNotifier_h
66