| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 #ifndef BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ | 5 #ifndef BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ |
| 6 #define BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ | 6 #define BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "blimp/common/proto/geolocation.pb.h" |
| 8 #include "content/public/browser/location_provider.h" | 10 #include "content/public/browser/location_provider.h" |
| 9 #include "content/public/common/geoposition.h" | 11 #include "content/public/common/geoposition.h" |
| 10 | 12 |
| 11 namespace blimp { | 13 namespace blimp { |
| 12 namespace engine { | 14 namespace engine { |
| 13 | 15 |
| 14 // Location provider for Blimp using the device's provider over the network. | 16 // Location provider for Blimp using the device's provider over the network. |
| 15 class BlimpLocationProvider : public content::LocationProvider { | 17 class BlimpLocationProvider : public content::LocationProvider { |
| 16 public: | 18 public: |
| 17 BlimpLocationProvider(); | 19 // A delegate that implements a subset of LocationProvider's functions. |
| 20 class Delegate { |
| 21 public: |
| 22 using GeopositionReceivedCallback = |
| 23 base::Callback<void(const content::Geoposition&)>; |
| 24 |
| 25 virtual ~Delegate() {} |
| 26 |
| 27 virtual void RequestAccuracy( |
| 28 GeolocationSetInterestLevelMessage::Level level) = 0; |
| 29 virtual void RequestRefresh() = 0; |
| 30 virtual void SetUpdateCallback( |
| 31 const GeopositionReceivedCallback& callback) = 0; |
| 32 }; |
| 33 |
| 34 explicit BlimpLocationProvider(base::WeakPtr<Delegate> delegate); |
| 18 ~BlimpLocationProvider() override; | 35 ~BlimpLocationProvider() override; |
| 19 | 36 |
| 20 // content::LocationProvider implementation. | 37 // content::LocationProvider implementation. |
| 21 bool StartProvider(bool high_accuracy) override; | 38 bool StartProvider(bool high_accuracy) override; |
| 22 void StopProvider() override; | 39 void StopProvider() override; |
| 23 void GetPosition(content::Geoposition* position) override; | 40 void GetPosition(content::Geoposition* position) override; |
| 24 void RequestRefresh() override; | 41 void RequestRefresh() override; |
| 25 void OnPermissionGranted() override; | 42 void OnPermissionGranted() override; |
| 26 | |
| 27 private: | |
| 28 void NotifyCallback(const content::Geoposition& position); | |
| 29 void OnLocationResponse(const content::Geoposition& position); | |
| 30 void SetUpdateCallback( | 43 void SetUpdateCallback( |
| 31 const LocationProviderUpdateCallback& callback) override; | 44 const LocationProviderUpdateCallback& callback) override; |
| 32 | 45 |
| 33 LocationProviderUpdateCallback callback_; | 46 private: |
| 47 // This delegate handles a subset of the LocationProvider functionality. |
| 48 base::WeakPtr<Delegate> delegate_; |
| 34 | 49 |
| 35 content::Geoposition position_; | 50 content::Geoposition cached_position_; |
| 51 |
| 52 // True if a successful StartProvider call has occured. |
| 53 bool is_started_; |
| 36 | 54 |
| 37 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider); | 55 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider); |
| 38 }; | 56 }; |
| 39 | 57 |
| 40 } // namespace engine | 58 } // namespace engine |
| 41 } // namespace blimp | 59 } // namespace blimp |
| 42 | 60 |
| 43 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ | 61 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ |
| OLD | NEW |