Chromium Code Reviews| 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" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "blimp/common/proto/geolocation.pb.h" | 9 #include "blimp/common/proto/geolocation.pb.h" |
| 10 #include "device/geolocation/geoposition.h" | 10 #include "device/geolocation/geoposition.h" |
| 11 #include "device/geolocation/location_provider.h" | 11 #include "device/geolocation/location_provider.h" |
| 12 | 12 |
| 13 namespace blimp { | 13 namespace blimp { |
| 14 namespace engine { | 14 namespace engine { |
| 15 | 15 |
| 16 // 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. |
| 17 class BlimpLocationProvider : public device::LocationProvider { | 17 class BlimpLocationProvider : public device::LocationProvider { |
| 18 public: | 18 public: |
| 19 // A delegate that implements a subset of LocationProvider's functions. | 19 // A delegate that implements a subset of LocationProvider's functions. |
| 20 // All methods will be executed on |delegate_task_runner_|. | |
| 20 class Delegate { | 21 class Delegate { |
| 21 public: | 22 public: |
| 22 using GeopositionReceivedCallback = | 23 using GeopositionReceivedCallback = |
| 23 base::Callback<void(const device::Geoposition&)>; | 24 base::Callback<void(const device::Geoposition&)>; |
| 24 | |
| 25 virtual ~Delegate() {} | 25 virtual ~Delegate() {} |
| 26 | 26 |
| 27 virtual void RequestAccuracy( | 27 virtual void RequestAccuracy( |
| 28 GeolocationSetInterestLevelMessage::Level level) = 0; | 28 GeolocationSetInterestLevelMessage::Level level) = 0; |
| 29 virtual void OnPermissionGranted() = 0; | 29 virtual void OnPermissionGranted() = 0; |
| 30 virtual void SetUpdateCallback( | 30 virtual void SetUpdateCallback( |
| 31 const GeopositionReceivedCallback& callback) = 0; | 31 const GeopositionReceivedCallback& callback) = 0; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 explicit BlimpLocationProvider(base::WeakPtr<Delegate> delegate); | 34 BlimpLocationProvider( |
| 35 base::WeakPtr<Delegate> delegate, | |
| 36 scoped_refptr<base::SequencedTaskRunner> delegate_task_runner); | |
| 35 ~BlimpLocationProvider() override; | 37 ~BlimpLocationProvider() override; |
| 36 | 38 |
| 37 // device::LocationProvider implementation. | 39 // device::LocationProvider implementation. |
| 38 bool StartProvider(bool high_accuracy) override; | 40 bool StartProvider(bool high_accuracy) override; |
| 39 void StopProvider() override; | 41 void StopProvider() override; |
| 40 const device::Geoposition& GetPosition() override; | 42 const device::Geoposition& GetPosition() override; |
| 41 void OnPermissionGranted() override; | 43 void OnPermissionGranted() override; |
| 42 void SetUpdateCallback( | 44 void SetUpdateCallback( |
| 43 const LocationProviderUpdateCallback& callback) override; | 45 const LocationProviderUpdateCallback& callback) override; |
| 44 | 46 |
| 47 void OnLocationUpdate(const device::Geoposition& geoposition); | |
|
Wez
2016/10/07 21:42:46
This should be private, since it's an internal imp
CJ
2016/10/08 00:05:55
Done.
| |
| 48 | |
| 45 private: | 49 private: |
| 46 // This delegate handles a subset of the LocationProvider functionality. | 50 // This delegate handles a subset of the LocationProvider functionality. |
| 47 base::WeakPtr<Delegate> delegate_; | 51 base::WeakPtr<Delegate> delegate_; |
| 48 | 52 |
| 53 scoped_refptr<base::SequencedTaskRunner> delegate_task_runner_; | |
| 49 device::Geoposition cached_position_; | 54 device::Geoposition cached_position_; |
| 50 | 55 |
| 51 // True if a successful StartProvider call has occured. | 56 // True if a successful StartProvider call has occured. |
| 52 bool is_started_; | 57 bool is_started_; |
| 53 | 58 |
| 59 LocationProviderUpdateCallback location_update_callback_; | |
| 60 | |
| 61 base::WeakPtrFactory<BlimpLocationProvider> weak_factory_; | |
| 62 | |
| 54 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider); | 63 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider); |
| 55 }; | 64 }; |
| 56 | 65 |
| 57 } // namespace engine | 66 } // namespace engine |
| 58 } // namespace blimp | 67 } // namespace blimp |
| 59 | 68 |
| 60 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ | 69 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ |
| OLD | NEW |