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 | 28 |
29 class DEVICE_GEOLOCATION_EXPORT GeolocationProviderImpl | 29 class DEVICE_GEOLOCATION_EXPORT GeolocationProviderImpl |
30 : public NON_EXPORTED_BASE(GeolocationProvider), | 30 : public NON_EXPORTED_BASE(GeolocationProvider), |
31 public base::Thread { | 31 public base::Thread { |
32 public: | 32 public: |
33 // GeolocationProvider implementation: | 33 // GeolocationProvider implementation: |
34 std::unique_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback( | 34 std::unique_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback( |
35 const LocationUpdateCallback& callback, | 35 const LocationUpdateCallback& callback, |
36 bool enable_high_accuracy) override; | 36 bool enable_high_accuracy) override; |
37 void UserDidOptIntoLocationServices() override; | 37 void UserDidOptIntoLocationServices() override; |
38 void OverrideLocationForTesting(const Geoposition& position) override; | 38 void OverrideLocationForTesting(const Geoposition& position) override; |
39 | 39 |
40 // Callback from the LocationArbitrator. Public for testing. | 40 // Callback from the LocationArbitrator. Public for testing. |
41 void OnLocationUpdate(const Geoposition& position); | 41 void OnLocationUpdate(const Geoposition& position); |
42 | 42 |
43 // Gets a pointer to the singleton instance of the location relayer, which | 43 // Gets a pointer to the singleton instance of the location relayer, which |
44 // is in turn bound to the browser's global context objects. This must only be | 44 // is in turn bound to the browser's global context objects. This must only be |
45 // called on the UI thread so that the GeolocationProviderImpl is always | 45 // called on the UI thread so that the GeolocationProviderImpl is always |
46 // instantiated on the same thread. Ownership is NOT returned. | 46 // instantiated on the same thread. Ownership is NOT returned. |
47 static GeolocationProviderImpl* GetInstance(); | 47 static GeolocationProviderImpl* GetInstance(); |
48 | 48 |
49 bool user_did_opt_into_location_services_for_testing() { | 49 bool user_did_opt_into_location_services_for_testing() { |
50 return user_did_opt_into_location_services_; | 50 return user_did_opt_into_location_services_; |
51 } | 51 } |
52 | 52 |
53 // Useful for injecting mock geolocation arbitrator in tests. | |
Wez
2016/08/12 00:33:44
nit: This comment is not super helpful - caller ca
CJ
2016/08/12 20:22:46
Done.
| |
54 void SetArbitratorForTesting(LocationProvider* arbitrator); | |
Wez
2016/08/12 00:33:44
Use unique_ptr<> here, so that it's clear that the
CJ
2016/08/12 20:22:46
Done.
| |
55 | |
53 protected: | 56 protected: |
Wez
2016/08/12 00:33:44
You can merge this with the private section, below
CJ
2016/08/12 20:22:46
Done.
| |
54 friend struct base::DefaultSingletonTraits<GeolocationProviderImpl>; | 57 friend struct base::DefaultSingletonTraits<GeolocationProviderImpl>; |
55 GeolocationProviderImpl(); | 58 GeolocationProviderImpl(); |
56 ~GeolocationProviderImpl() override; | 59 ~GeolocationProviderImpl() override; |
57 | 60 |
58 // Useful for injecting mock geolocation arbitrator in tests. | 61 // Only to be used on the geolocation thread. |
59 // TODO(mvanouwerkerk): Use something like SetArbitratorForTesting instead. | 62 std::unique_ptr<LocationProvider> arbitrator_; |
Wez
2016/08/12 00:33:44
Move this down to sit alongisde the other data mem
CJ
2016/08/12 20:22:46
Done.
| |
60 virtual std::unique_ptr<LocationArbitrator> CreateArbitrator(); | |
61 | 63 |
62 private: | 64 private: |
63 bool OnGeolocationThread() const; | 65 bool OnGeolocationThread() const; |
64 | 66 |
65 // Start and stop providers as needed when clients are added or removed. | 67 // Start and stop providers as needed when clients are added or removed. |
66 void OnClientsChanged(); | 68 void OnClientsChanged(); |
67 | 69 |
68 // Stops the providers when there are no more registered clients. Note that | 70 // 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 | 71 // once the Geolocation thread is started, it will stay alive (but sitting |
70 // idle without any pending messages). | 72 // idle without any pending messages). |
(...skipping 15 matching lines...) Expand all Loading... | |
86 | 88 |
87 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_; | 89 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_; |
88 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_; | 90 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_; |
89 | 91 |
90 bool user_did_opt_into_location_services_; | 92 bool user_did_opt_into_location_services_; |
91 Geoposition position_; | 93 Geoposition position_; |
92 | 94 |
93 // True only in testing, where we want to use a custom position. | 95 // True only in testing, where we want to use a custom position. |
94 bool ignore_location_updates_; | 96 bool ignore_location_updates_; |
95 | 97 |
96 // Only to be used on the geolocation thread. | |
97 std::unique_ptr<LocationArbitrator> arbitrator_; | |
98 | |
99 // Used to PostTask()s from the geolocation thread to creation thread. | 98 // Used to PostTask()s from the geolocation thread to creation thread. |
100 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 99 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
101 | 100 |
102 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl); | 101 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl); |
103 }; | 102 }; |
104 | 103 |
105 } // namespace device | 104 } // namespace device |
106 | 105 |
107 #endif // DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ | 106 #endif // DEVICE_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ |
OLD | NEW |