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_
15 class GeolocationProvider
;
16 class GeolocationServiceContext
;
18 // Implements the GeolocationService Mojo interface.
19 class GeolocationServiceImpl
: public mojo::InterfaceImpl
<GeolocationService
> {
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
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.
35 // Enables and disables geolocation override.
36 void SetOverride(const Geoposition
& position
);
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();
53 GeolocationServiceContext
* context_
;
54 scoped_ptr
<GeolocationProvider::Subscription
> geolocation_subscription_
;
56 // Callback that allows the instantiator of this class to be notified on
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
73 bool has_position_to_report_
;
75 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl
);
78 } // namespace content
80 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_