Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ | 5 #ifndef DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ |
| 6 #define DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ | 6 #define DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "device/geolocation/geolocation_export.h" | 16 #include "device/geolocation/geolocation_export.h" |
| 17 #include "device/geolocation/geolocation_provider.h" | 17 #include "device/geolocation/geolocation_provider.h" |
| 18 #include "device/geolocation/geoposition.h" | 18 #include "device/geolocation/geoposition.h" |
| 19 #include "device/geolocation/location_provider.h" | |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 template <typename Type> | 22 template <typename Type> |
| 22 struct DefaultSingletonTraits; | 23 struct DefaultSingletonTraits; |
| 23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace device { | 27 namespace device { |
| 27 class LocationArbitrator; | 28 class LocationArbitrator; |
|
Kevin M
2016/08/10 23:16:19
Not used?
CJ
2016/08/11 22:16:53
Done.
| |
| 28 | 29 |
| 29 class DEVICE_GEOLOCATION_EXPORT GeolocationProviderImpl | 30 class DEVICE_GEOLOCATION_EXPORT GeolocationProviderImpl |
| 30 : public NON_EXPORTED_BASE(GeolocationProvider), | 31 : public NON_EXPORTED_BASE(GeolocationProvider), |
| 31 public base::Thread { | 32 public base::Thread { |
| 32 public: | 33 public: |
| 33 // GeolocationProvider implementation: | 34 // GeolocationProvider implementation: |
| 34 std::unique_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback( | 35 std::unique_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback( |
| 35 const LocationUpdateCallback& callback, | 36 const LocationUpdateCallback& callback, |
| 36 bool enable_high_accuracy) override; | 37 bool enable_high_accuracy) override; |
| 37 void UserDidOptIntoLocationServices() override; | 38 void UserDidOptIntoLocationServices() override; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 49 bool user_did_opt_into_location_services_for_testing() { | 50 bool user_did_opt_into_location_services_for_testing() { |
| 50 return user_did_opt_into_location_services_; | 51 return user_did_opt_into_location_services_; |
| 51 } | 52 } |
| 52 | 53 |
| 53 protected: | 54 protected: |
| 54 friend struct base::DefaultSingletonTraits<GeolocationProviderImpl>; | 55 friend struct base::DefaultSingletonTraits<GeolocationProviderImpl>; |
| 55 GeolocationProviderImpl(); | 56 GeolocationProviderImpl(); |
| 56 ~GeolocationProviderImpl() override; | 57 ~GeolocationProviderImpl() override; |
| 57 | 58 |
| 58 // Useful for injecting mock geolocation arbitrator in tests. | 59 // Useful for injecting mock geolocation arbitrator in tests. |
| 59 // TODO(mvanouwerkerk): Use something like SetArbitratorForTesting instead. | 60 // TODO(mvanouwerkerk): Use something like SetArbitratorForTesting instead. |
|
Wez
2016/08/09 01:17:04
nit: Consider implementing this TODO() while you'r
CJ
2016/08/11 22:06:43
Done.
| |
| 60 virtual std::unique_ptr<LocationArbitrator> CreateArbitrator(); | 61 virtual std::unique_ptr<LocationProvider> CreateArbitrator(); |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 bool OnGeolocationThread() const; | 64 bool OnGeolocationThread() const; |
| 64 | 65 |
| 65 // Start and stop providers as needed when clients are added or removed. | 66 // Start and stop providers as needed when clients are added or removed. |
| 66 void OnClientsChanged(); | 67 void OnClientsChanged(); |
| 67 | 68 |
| 68 // Stops the providers when there are no more registered clients. Note that | 69 // Stops the providers when there are no more registered clients. Note that |
| 69 // once the Geolocation thread is started, it will stay alive (but sitting | 70 // once the Geolocation thread is started, it will stay alive (but sitting |
| 70 // idle without any pending messages). | 71 // idle without any pending messages). |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 87 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_; | 88 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_; |
| 88 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_; | 89 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_; |
| 89 | 90 |
| 90 bool user_did_opt_into_location_services_; | 91 bool user_did_opt_into_location_services_; |
| 91 Geoposition position_; | 92 Geoposition position_; |
| 92 | 93 |
| 93 // True only in testing, where we want to use a custom position. | 94 // True only in testing, where we want to use a custom position. |
| 94 bool ignore_location_updates_; | 95 bool ignore_location_updates_; |
| 95 | 96 |
| 96 // Only to be used on the geolocation thread. | 97 // Only to be used on the geolocation thread. |
| 97 std::unique_ptr<LocationArbitrator> arbitrator_; | 98 std::unique_ptr<LocationProvider> arbitrator_; |
| 98 | 99 |
| 99 // Used to PostTask()s from the geolocation thread to creation thread. | 100 // Used to PostTask()s from the geolocation thread to creation thread. |
| 100 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 101 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 101 | 102 |
| 102 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl); | 103 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl); |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 } // namespace device | 106 } // namespace device |
| 106 | 107 |
| 107 #endif // DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ | 108 #endif // DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ |
| OLD | NEW |