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 "components/geolocation/public/interfaces/geolocation.mojom.h" |
6 #include "content/browser/geolocation/geolocation_provider_impl.h" | 7 #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" | 8 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
10 | 9 |
11 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ | 10 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ |
12 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ | 11 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ |
13 | 12 |
14 namespace content { | 13 namespace content { |
15 | 14 |
16 class GeolocationProvider; | 15 class GeolocationProvider; |
17 class GeolocationServiceContext; | 16 class GeolocationServiceContext; |
18 | 17 |
19 // Implements the GeolocationService Mojo interface. | 18 // Implements the GeolocationService Mojo interface. |
20 class GeolocationServiceImpl : public GeolocationService { | 19 class GeolocationServiceImpl : public geolocation::GeolocationService { |
21 public: | 20 public: |
22 // |context| must outlive this object. |update_callback| will be called when | 21 // |context| must outlive this object. |update_callback| will be called when |
23 // location updates are sent, allowing the client to know when the service | 22 // location updates are sent, allowing the client to know when the service |
24 // is being used. | 23 // is being used. |
25 GeolocationServiceImpl(mojo::InterfaceRequest<GeolocationService> request, | 24 GeolocationServiceImpl(mojo::InterfaceRequest<GeolocationService> request, |
26 GeolocationServiceContext* context, | 25 GeolocationServiceContext* context, |
27 const base::Closure& update_callback); | 26 const base::Closure& update_callback); |
28 ~GeolocationServiceImpl() override; | 27 ~GeolocationServiceImpl() override; |
29 | 28 |
30 // Starts listening for updates. | 29 // Starts listening for updates. |
31 void StartListeningForUpdates(); | 30 void StartListeningForUpdates(); |
32 | 31 |
33 // Pauses and resumes sending updates to the client of this instance. | 32 // Pauses and resumes sending updates to the client of this instance. |
34 void PauseUpdates(); | 33 void PauseUpdates(); |
35 void ResumeUpdates(); | 34 void ResumeUpdates(); |
36 | 35 |
37 // Enables and disables geolocation override. | 36 // Enables and disables geolocation override. |
38 void SetOverride(const Geoposition& position); | 37 void SetOverride(const Geoposition& position); |
39 void ClearOverride(); | 38 void ClearOverride(); |
40 | 39 |
41 private: | 40 private: |
42 typedef mojo::Callback<void(MojoGeopositionPtr)> PositionCallback; | 41 typedef mojo::Callback<void(geolocation::GeopositionPtr)> PositionCallback; |
43 | 42 |
44 // GeolocationService: | 43 // GeolocationService: |
45 void SetHighAccuracy(bool high_accuracy) override; | 44 void SetHighAccuracy(bool high_accuracy) override; |
46 void QueryNextPosition(const PositionCallback& callback) override; | 45 void QueryNextPosition(const PositionCallback& callback) override; |
47 | 46 |
48 void OnConnectionError(); | 47 void OnConnectionError(); |
49 | 48 |
50 void OnLocationUpdate(const Geoposition& position); | 49 void OnLocationUpdate(const Geoposition& position); |
51 void ReportCurrentPosition(); | 50 void ReportCurrentPosition(); |
52 | 51 |
53 // The binding between this object and the other end of the pipe. | 52 // The binding between this object and the other end of the pipe. |
54 mojo::Binding<GeolocationService> binding_; | 53 mojo::Binding<GeolocationService> binding_; |
55 | 54 |
56 // Owns this object. | 55 // Owns this object. |
57 GeolocationServiceContext* context_; | 56 GeolocationServiceContext* context_; |
58 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; | 57 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; |
59 | 58 |
60 // Callback that allows the instantiator of this class to be notified on | 59 // Callback that allows the instantiator of this class to be notified on |
61 // position updates. | 60 // position updates. |
62 base::Closure update_callback_; | 61 base::Closure update_callback_; |
63 | 62 |
64 // The callback passed to QueryNextPosition. | 63 // The callback passed to QueryNextPosition. |
65 PositionCallback position_callback_; | 64 PositionCallback position_callback_; |
66 | 65 |
67 // Valid iff SetOverride() has been called and ClearOverride() has not | 66 // Valid iff SetOverride() has been called and ClearOverride() has not |
68 // subsequently been called. | 67 // subsequently been called. |
69 Geoposition position_override_; | 68 Geoposition position_override_; |
70 | 69 |
71 MojoGeoposition current_position_; | 70 geolocation::Geoposition current_position_; |
72 | 71 |
73 // Whether this instance is currently observing location updates with high | 72 // Whether this instance is currently observing location updates with high |
74 // accuracy. | 73 // accuracy. |
75 bool high_accuracy_; | 74 bool high_accuracy_; |
76 | 75 |
77 bool has_position_to_report_; | 76 bool has_position_to_report_; |
78 | 77 |
79 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl); | 78 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl); |
80 }; | 79 }; |
81 | 80 |
82 } // namespace content | 81 } // namespace content |
83 | 82 |
84 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ | 83 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ |
OLD | NEW |