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