Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / geolocation / geolocation_service_impl.h
blob9887b2f2b4ae8b3f6b39cd1318e38e54f1126de2
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.
5 #include "base/memory/scoped_ptr.h"
6 #include "content/browser/geolocation/geolocation_provider_impl.h"
7 #include "content/common/geolocation_service.mojom.h"
8 #include "content/public/common/mojo_geoposition.mojom.h"
10 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_
11 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_
13 namespace content {
15 class GeolocationProvider;
16 class GeolocationServiceContext;
18 // Implements the GeolocationService Mojo interface.
19 class GeolocationServiceImpl : public mojo::InterfaceImpl<GeolocationService> {
20 public:
21 // |context| must outlive this object. |update_callback| will be called when
22 // location updates are sent, allowing the client to know when the service
23 // is being used.
24 GeolocationServiceImpl(GeolocationServiceContext* context,
25 const base::Closure& update_callback);
26 ~GeolocationServiceImpl() override;
28 // Starts listening for updates.
29 void StartListeningForUpdates();
31 // Pauses and resumes sending updates to the client of this instance.
32 void PauseUpdates();
33 void ResumeUpdates();
35 // Enables and disables geolocation override.
36 void SetOverride(const Geoposition& position);
37 void ClearOverride();
39 private:
40 typedef mojo::Callback<void(MojoGeopositionPtr)> PositionCallback;
42 // GeolocationService:
43 void SetHighAccuracy(bool high_accuracy) override;
44 void QueryNextPosition(const PositionCallback& callback) override;
46 // mojo::InterfaceImpl:
47 void OnConnectionError() override;
49 void OnLocationUpdate(const Geoposition& position);
50 void ReportCurrentPosition();
52 // Owns this object.
53 GeolocationServiceContext* context_;
54 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_;
56 // Callback that allows the instantiator of this class to be notified on
57 // position updates.
58 base::Closure update_callback_;
60 // The callback passed to QueryNextPosition.
61 PositionCallback position_callback_;
63 // Valid iff SetOverride() has been called and ClearOverride() has not
64 // subsequently been called.
65 Geoposition position_override_;
67 MojoGeoposition current_position_;
69 // Whether this instance is currently observing location updates with high
70 // accuracy.
71 bool high_accuracy_;
73 bool has_position_to_report_;
75 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl);
78 } // namespace content
80 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_