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"
10 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
12 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_
13 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_
17 class GeolocationProvider
;
18 class GeolocationServiceContext
;
20 // Implements the GeolocationService Mojo interface.
21 class GeolocationServiceImpl
: public GeolocationService
,
22 public mojo::ErrorHandler
{
24 // |context| must outlive this object. |update_callback| will be called when
25 // location updates are sent, allowing the client to know when the service
27 GeolocationServiceImpl(mojo::InterfaceRequest
<GeolocationService
> request
,
28 GeolocationServiceContext
* context
,
29 const base::Closure
& update_callback
);
30 ~GeolocationServiceImpl() override
;
32 // Starts listening for updates.
33 void StartListeningForUpdates();
35 // Pauses and resumes sending updates to the client of this instance.
39 // Enables and disables geolocation override.
40 void SetOverride(const Geoposition
& position
);
44 typedef mojo::Callback
<void(MojoGeopositionPtr
)> PositionCallback
;
46 // GeolocationService:
47 void SetHighAccuracy(bool high_accuracy
) override
;
48 void QueryNextPosition(const PositionCallback
& callback
) override
;
50 // mojo::ErrorHandler:
51 void OnConnectionError() override
;
53 void OnLocationUpdate(const Geoposition
& position
);
54 void ReportCurrentPosition();
56 // The binding between this object and the other end of the pipe.
57 mojo::Binding
<GeolocationService
> binding_
;
60 GeolocationServiceContext
* context_
;
61 scoped_ptr
<GeolocationProvider::Subscription
> geolocation_subscription_
;
63 // Callback that allows the instantiator of this class to be notified on
65 base::Closure update_callback_
;
67 // The callback passed to QueryNextPosition.
68 PositionCallback position_callback_
;
70 // Valid iff SetOverride() has been called and ClearOverride() has not
71 // subsequently been called.
72 Geoposition position_override_
;
74 MojoGeoposition current_position_
;
76 // Whether this instance is currently observing location updates with high
80 bool has_position_to_report_
;
82 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl
);
85 } // namespace content
87 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_