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 CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ |
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
| 9 #include <memory> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "content/public/browser/geolocation_provider.h" | 17 #include "content/public/browser/geolocation_provider.h" |
18 #include "content/public/common/geoposition.h" | 18 #include "content/public/common/geoposition.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 template<typename Type> struct DefaultSingletonTraits; | 21 template<typename Type> struct DefaultSingletonTraits; |
22 } | 22 } |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 class LocationArbitrator; | 25 class LocationArbitrator; |
26 | 26 |
27 class CONTENT_EXPORT GeolocationProviderImpl | 27 class CONTENT_EXPORT GeolocationProviderImpl |
28 : public NON_EXPORTED_BASE(GeolocationProvider), | 28 : public NON_EXPORTED_BASE(GeolocationProvider), |
29 public base::Thread { | 29 public base::Thread { |
30 public: | 30 public: |
31 // GeolocationProvider implementation: | 31 // GeolocationProvider implementation: |
32 scoped_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback( | 32 std::unique_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback( |
33 const LocationUpdateCallback& callback, | 33 const LocationUpdateCallback& callback, |
34 bool enable_high_accuracy) override; | 34 bool enable_high_accuracy) override; |
35 void UserDidOptIntoLocationServices() override; | 35 void UserDidOptIntoLocationServices() override; |
36 void OverrideLocationForTesting(const Geoposition& position) override; | 36 void OverrideLocationForTesting(const Geoposition& position) override; |
37 | 37 |
38 // Callback from the LocationArbitrator. Public for testing. | 38 // Callback from the LocationArbitrator. Public for testing. |
39 void OnLocationUpdate(const Geoposition& position); | 39 void OnLocationUpdate(const Geoposition& position); |
40 | 40 |
41 // Gets a pointer to the singleton instance of the location relayer, which | 41 // Gets a pointer to the singleton instance of the location relayer, which |
42 // is in turn bound to the browser's global context objects. This must only be | 42 // is in turn bound to the browser's global context objects. This must only be |
43 // called on the UI thread so that the GeolocationProviderImpl is always | 43 // called on the UI thread so that the GeolocationProviderImpl is always |
44 // instantiated on the same thread. Ownership is NOT returned. | 44 // instantiated on the same thread. Ownership is NOT returned. |
45 static GeolocationProviderImpl* GetInstance(); | 45 static GeolocationProviderImpl* GetInstance(); |
46 | 46 |
47 bool user_did_opt_into_location_services_for_testing() { | 47 bool user_did_opt_into_location_services_for_testing() { |
48 return user_did_opt_into_location_services_; | 48 return user_did_opt_into_location_services_; |
49 } | 49 } |
50 | 50 |
51 protected: | 51 protected: |
52 friend struct base::DefaultSingletonTraits<GeolocationProviderImpl>; | 52 friend struct base::DefaultSingletonTraits<GeolocationProviderImpl>; |
53 GeolocationProviderImpl(); | 53 GeolocationProviderImpl(); |
54 ~GeolocationProviderImpl() override; | 54 ~GeolocationProviderImpl() override; |
55 | 55 |
56 // Useful for injecting mock geolocation arbitrator in tests. | 56 // Useful for injecting mock geolocation arbitrator in tests. |
57 // TODO(mvanouwerkerk): Use something like SetArbitratorForTesting instead. | 57 // TODO(mvanouwerkerk): Use something like SetArbitratorForTesting instead. |
58 virtual scoped_ptr<LocationArbitrator> CreateArbitrator(); | 58 virtual std::unique_ptr<LocationArbitrator> CreateArbitrator(); |
59 | 59 |
60 private: | 60 private: |
61 bool OnGeolocationThread() const; | 61 bool OnGeolocationThread() const; |
62 | 62 |
63 // Start and stop providers as needed when clients are added or removed. | 63 // Start and stop providers as needed when clients are added or removed. |
64 void OnClientsChanged(); | 64 void OnClientsChanged(); |
65 | 65 |
66 // Stops the providers when there are no more registered clients. Note that | 66 // Stops the providers when there are no more registered clients. Note that |
67 // once the Geolocation thread is started, it will stay alive (but sitting | 67 // once the Geolocation thread is started, it will stay alive (but sitting |
68 // idle without any pending messages). | 68 // idle without any pending messages). |
(...skipping 16 matching lines...) Expand all Loading... |
85 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_; | 85 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_; |
86 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_; | 86 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_; |
87 | 87 |
88 bool user_did_opt_into_location_services_; | 88 bool user_did_opt_into_location_services_; |
89 Geoposition position_; | 89 Geoposition position_; |
90 | 90 |
91 // True only in testing, where we want to use a custom position. | 91 // True only in testing, where we want to use a custom position. |
92 bool ignore_location_updates_; | 92 bool ignore_location_updates_; |
93 | 93 |
94 // Only to be used on the geolocation thread. | 94 // Only to be used on the geolocation thread. |
95 scoped_ptr<LocationArbitrator> arbitrator_; | 95 std::unique_ptr<LocationArbitrator> arbitrator_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl); | 97 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl); |
98 }; | 98 }; |
99 | 99 |
100 } // namespace content | 100 } // namespace content |
101 | 101 |
102 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ | 102 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_ |
OLD | NEW |