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