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 // All calls made from BlimpLocationProvider involving |delegate_| must be | |
| 18 // posted using |delegate_task_runner_|. | |
|
Wez
2016/09/13 20:19:07
nit: This is part of the Delegate contract, so you
CJ
2016/09/13 23:34:02
Done.
| |
| 17 class BlimpLocationProvider : public device::LocationProvider { | 19 class BlimpLocationProvider : public device::LocationProvider { |
| 18 public: | 20 public: |
| 19 // A delegate that implements a subset of LocationProvider's functions. | 21 // A delegate that implements a subset of LocationProvider's functions. |
| 22 // All methods will be executed on |delegate_task_runner_|. | |
| 20 class Delegate { | 23 class Delegate { |
| 21 public: | 24 public: |
| 22 using GeopositionReceivedCallback = | 25 using GeopositionReceivedCallback = |
| 23 base::Callback<void(const device::Geoposition&)>; | 26 base::Callback<void(const device::Geoposition&)>; |
| 24 | 27 |
| 25 virtual ~Delegate() {} | 28 virtual ~Delegate() {} |
| 26 | 29 |
| 27 virtual void RequestAccuracy( | 30 virtual void RequestAccuracy( |
| 28 GeolocationSetInterestLevelMessage::Level level) = 0; | 31 GeolocationSetInterestLevelMessage::Level level) = 0; |
| 29 virtual void OnPermissionGranted() = 0; | 32 virtual void OnPermissionGranted() = 0; |
| 30 virtual void SetUpdateCallback( | 33 virtual void SetUpdateCallback( |
| 31 const GeopositionReceivedCallback& callback) = 0; | 34 const GeopositionReceivedCallback& callback) = 0; |
| 32 }; | 35 }; |
| 33 | 36 |
| 34 explicit BlimpLocationProvider(base::WeakPtr<Delegate> delegate); | 37 BlimpLocationProvider( |
| 38 base::WeakPtr<Delegate> delegate, | |
| 39 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner); | |
|
Wez
2016/09/13 20:19:07
nit: Strictly a SequencedTaskRunner is sufficient
CJ
2016/09/13 23:34:02
Are you saying remove the scoped_refptr part?
Wez
2016/09/16 00:40:16
So, I'm saying you should accept a scoped_refptr<S
CJ
2016/09/16 22:55:53
Done.
| |
| 35 ~BlimpLocationProvider() override; | 40 ~BlimpLocationProvider() override; |
| 36 | 41 |
| 37 // device::LocationProvider implementation. | 42 // device::LocationProvider implementation. |
| 38 bool StartProvider(bool high_accuracy) override; | 43 bool StartProvider(bool high_accuracy) override; |
| 39 void StopProvider() override; | 44 void StopProvider() override; |
| 40 const device::Geoposition& GetPosition() override; | 45 const device::Geoposition& GetPosition() override; |
| 41 void OnPermissionGranted() override; | 46 void OnPermissionGranted() override; |
| 42 void SetUpdateCallback( | 47 void SetUpdateCallback( |
| 43 const LocationProviderUpdateCallback& callback) override; | 48 const LocationProviderUpdateCallback& callback) override; |
| 44 | 49 |
| 45 private: | 50 private: |
| 46 // This delegate handles a subset of the LocationProvider functionality. | 51 // This delegate handles a subset of the LocationProvider functionality. |
| 47 base::WeakPtr<Delegate> delegate_; | 52 base::WeakPtr<Delegate> delegate_; |
| 48 | 53 |
| 54 scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_; | |
| 55 | |
| 49 device::Geoposition cached_position_; | 56 device::Geoposition cached_position_; |
| 50 | 57 |
| 51 // True if a successful StartProvider call has occured. | 58 // True if a successful StartProvider call has occured. |
| 52 bool is_started_; | 59 bool is_started_; |
| 53 | 60 |
| 54 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider); | 61 DISALLOW_COPY_AND_ASSIGN(BlimpLocationProvider); |
| 55 }; | 62 }; |
| 56 | 63 |
| 57 } // namespace engine | 64 } // namespace engine |
| 58 } // namespace blimp | 65 } // namespace blimp |
| 59 | 66 |
| 60 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ | 67 #endif // BLIMP_ENGINE_FEATURE_GEOLOCATION_BLIMP_LOCATION_PROVIDER_H_ |
| OLD | NEW |