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"
9 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
11 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_
12 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_
16 class GeolocationProvider
;
17 class GeolocationServiceContext
;
19 // Implements the GeolocationService Mojo interface.
20 class GeolocationServiceImpl
: public GeolocationService
{
22 // |context| must outlive this object. |update_callback| will be called when
23 // location updates are sent, allowing the client to know when the service
25 GeolocationServiceImpl(mojo::InterfaceRequest
<GeolocationService
> request
,
26 GeolocationServiceContext
* context
,
27 const base::Closure
& update_callback
);
28 ~GeolocationServiceImpl() override
;
30 // Starts listening for updates.
31 void StartListeningForUpdates();
33 // Pauses and resumes sending updates to the client of this instance.
37 // Enables and disables geolocation override.
38 void SetOverride(const Geoposition
& position
);
42 typedef mojo::Callback
<void(MojoGeopositionPtr
)> PositionCallback
;
44 // GeolocationService:
45 void SetHighAccuracy(bool high_accuracy
) override
;
46 void QueryNextPosition(const PositionCallback
& callback
) override
;
48 void OnConnectionError();
50 void OnLocationUpdate(const Geoposition
& position
);
51 void ReportCurrentPosition();
53 // The binding between this object and the other end of the pipe.
54 mojo::Binding
<GeolocationService
> binding_
;
57 GeolocationServiceContext
* context_
;
58 scoped_ptr
<GeolocationProvider::Subscription
> geolocation_subscription_
;
60 // Callback that allows the instantiator of this class to be notified on
62 base::Closure update_callback_
;
64 // The callback passed to QueryNextPosition.
65 PositionCallback position_callback_
;
67 // Valid iff SetOverride() has been called and ClearOverride() has not
68 // subsequently been called.
69 Geoposition position_override_
;
71 MojoGeoposition current_position_
;
73 // Whether this instance is currently observing location updates with high
77 bool has_position_to_report_
;
79 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl
);
82 } // namespace content
84 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_