Chromium Code Reviews| 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" |
|
Michael van Ouwerkerk
2015/11/11 11:20:56
nit: this can be forward declared. It is also incl
Sam McNally
2015/11/13 00:49:59
Done.
| |
| 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. |
| 23 // location updates are sent, allowing the client to know when the service | 21 GeolocationServiceImpl(GeolocationServiceContext* context, |
| 24 // is being used. | 22 RenderFrameHost* render_frame_host); |
| 25 GeolocationServiceImpl(mojo::InterfaceRequest<GeolocationService> request, | |
| 26 GeolocationServiceContext* context, | |
| 27 const base::Closure& update_callback); | |
| 28 ~GeolocationServiceImpl() override; | 23 ~GeolocationServiceImpl() override; |
| 29 | 24 |
| 30 // Starts listening for updates. | 25 // Starts listening for updates. |
| 31 void StartListeningForUpdates(); | 26 void StartListeningForUpdates(); |
| 32 | 27 |
| 33 // Pauses and resumes sending updates to the client of this instance. | 28 // Pauses and resumes sending updates to the client of this instance. |
| 34 void PauseUpdates(); | 29 void PauseUpdates(); |
| 35 void ResumeUpdates(); | 30 void ResumeUpdates(); |
| 36 | 31 |
| 37 // Enables and disables geolocation override. | 32 // Enables and disables geolocation override. |
| 38 void SetOverride(const Geoposition& position); | 33 void OnOverrideSet(); |
| 39 void ClearOverride(); | 34 void ClearOverride(); |
| 40 | 35 |
| 41 private: | 36 private: |
| 42 typedef mojo::Callback<void(MojoGeopositionPtr)> PositionCallback; | 37 using PositionCallback = QueryNextPositionCallback; |
| 43 | 38 |
| 44 // GeolocationService: | 39 // GeolocationService: |
| 45 void SetHighAccuracy(bool high_accuracy) override; | 40 void SetHighAccuracy(bool high_accuracy) override; |
| 46 void QueryNextPosition(const PositionCallback& callback) override; | 41 void QueryNextPosition(const PositionCallback& callback) override; |
| 47 | 42 |
| 48 void OnConnectionError(); | |
| 49 | |
| 50 void OnLocationUpdate(const Geoposition& position); | 43 void OnLocationUpdate(const Geoposition& position); |
| 51 void ReportCurrentPosition(); | 44 void ReportCurrentPosition(); |
| 52 | 45 |
| 53 // The binding between this object and the other end of the pipe. | 46 void ReportPermissionUsage(); |
| 54 mojo::Binding<GeolocationService> binding_; | |
| 55 | 47 |
| 56 // Owns this object. | 48 // Owns this object. |
| 57 GeolocationServiceContext* context_; | 49 GeolocationServiceContext* const context_; |
| 50 const int render_process_id_; | |
| 51 const int render_frame_id_; | |
| 58 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; | 52 scoped_ptr<GeolocationProvider::Subscription> geolocation_subscription_; |
| 59 | 53 |
| 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. | 54 // The callback passed to QueryNextPosition. |
| 65 PositionCallback position_callback_; | 55 PositionCallback position_callback_; |
| 66 | 56 |
| 67 // Valid iff SetOverride() has been called and ClearOverride() has not | 57 MojoGeopositionPtr current_position_; |
| 68 // subsequently been called. | |
| 69 Geoposition position_override_; | |
| 70 | |
| 71 MojoGeoposition current_position_; | |
| 72 | 58 |
| 73 // Whether this instance is currently observing location updates with high | 59 // Whether this instance is currently observing location updates with high |
| 74 // accuracy. | 60 // accuracy. |
| 75 bool high_accuracy_; | 61 bool high_accuracy_; |
| 76 | 62 |
| 77 bool has_position_to_report_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl); | 63 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceImpl); |
| 80 }; | 64 }; |
| 81 | 65 |
| 82 } // namespace content | 66 } // namespace content |
| 83 | 67 |
| 84 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ | 68 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_IMPL_H_ |
| OLD | NEW |