OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "content/browser/geolocation/geolocation_provider_impl.h" | 6 #include "content/browser/geolocation/geolocation_provider_impl.h" |
7 #include "content/common/geolocation_service.mojom.h" | 7 #include "content/common/geolocation_service.mojom.h" |
| 8 #include "content/public/common/mojo_geoposition.mojom.h" |
8 | 9 |
9 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ | 10 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ |
10 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ | 11 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 class GeolocationProvider; | 15 class GeolocationProvider; |
15 class GeolocationServiceContext; | 16 class GeolocationServiceContext; |
16 | 17 |
17 // Implements the GeolocationService Mojo interface. | 18 // Implements the GeolocationService Mojo interface. |
18 class GeolocationServiceImpl : public mojo::InterfaceImpl<GeolocationService> { | 19 class GeolocationServiceImpl : public mojo::InterfaceImpl<GeolocationService> { |
19 public: | 20 public: |
20 // |context| must outlive this object. |update_callback| will be | 21 // |context| must outlive this object. |update_callback| will be called when |
21 // called when location updates are sent. | 22 // location updates are sent, allowing the client to know when the service |
| 23 // is being used. |
22 GeolocationServiceImpl(GeolocationServiceContext* context, | 24 GeolocationServiceImpl(GeolocationServiceContext* context, |
23 const base::Closure& update_callback); | 25 const base::Closure& update_callback); |
24 ~GeolocationServiceImpl() override; | 26 ~GeolocationServiceImpl() override; |
25 | 27 |
26 // Starts listening for updates. | 28 // Starts listening for updates. |
27 void StartListeningForUpdates(); | 29 void StartListeningForUpdates(); |
28 | 30 |
29 // Pauses and resumes sending updates to the client of this instance. | 31 // Pauses and resumes sending updates to the client of this instance. |
30 void PauseUpdates(); | 32 void PauseUpdates(); |
31 void ResumeUpdates(); | 33 void ResumeUpdates(); |
32 | 34 |
33 // Enables and disables geolocation override. | 35 // Enables and disables geolocation override. |
34 void SetOverride(const Geoposition& position); | 36 void SetOverride(const Geoposition& position); |
35 void ClearOverride(); | 37 void ClearOverride(); |
36 | 38 |
37 private: | 39 private: |
| 40 typedef mojo::Callback<void(MojoGeopositionPtr)> PositionCallback; |
| 41 |
38 // GeolocationService: | 42 // GeolocationService: |
39 void SetHighAccuracy(bool high_accuracy) override; | 43 void SetHighAccuracy(bool high_accuracy) override; |
| 44 void QueryNextPosition(const PositionCallback& callback) override; |
40 | 45 |
41 // mojo::InterfaceImpl: | 46 // mojo::InterfaceImpl: |
42 void OnConnectionError() override; | 47 void OnConnectionError() override; |
43 | 48 |
44 void OnLocationUpdate(const Geoposition& position); | 49 void OnLocationUpdate(const Geoposition& position); |
| 50 void ReportCurrentPosition(); |
45 | 51 |
46 // Owns this object. | 52 // Owns this object. |
47 GeolocationServiceContext* context_; | 53 GeolocationServiceContext* context_; |
48 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; | 54 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; |
| 55 |
| 56 // Callback that allows the instantiator of this class to be notified on |
| 57 // position updates. |
49 base::Closure update_callback_; | 58 base::Closure update_callback_; |
50 | 59 |
| 60 // The queue of callbacks passed to QueryNextPosition. |
| 61 std::vector<PositionCallback> position_callbacks_; |
| 62 |
51 // Valid iff SetOverride() has been called and ClearOverride() has not | 63 // Valid iff SetOverride() has been called and ClearOverride() has not |
52 // subsequently been called. | 64 // subsequently been called. |
53 Geoposition position_override_; | 65 Geoposition position_override_; |
54 | 66 |
| 67 MojoGeoposition current_position_; |
| 68 |
55 // Whether this instance is currently observing location updates with high | 69 // Whether this instance is currently observing location updates with high |
56 // accuracy. | 70 // accuracy. |
57 bool high_accuracy_; | 71 bool high_accuracy_; |
58 | 72 |
| 73 bool has_position_to_report_; |
| 74 |
59 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl); | 75 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl); |
60 }; | 76 }; |
61 | 77 |
62 } // namespace content | 78 } // namespace content |
63 | 79 |
64 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ | 80 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ |
OLD | NEW |