| 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_NETWORK_LOCATION_PROVIDER_H_ | 5 #ifndef DEVICE_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 6 #define DEVICE_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 6 #define DEVICE_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 20 #include "device/geolocation/geolocation_export.h" | 20 #include "device/geolocation/geolocation_export.h" |
| 21 #include "device/geolocation/geoposition.h" | 21 #include "device/geolocation/geoposition.h" |
| 22 #include "device/geolocation/location_provider_base.h" | 22 #include "device/geolocation/location_provider.h" |
| 23 #include "device/geolocation/network_location_request.h" | 23 #include "device/geolocation/network_location_request.h" |
| 24 #include "device/geolocation/wifi_data_provider_manager.h" | 24 #include "device/geolocation/wifi_data_provider_manager.h" |
| 25 | 25 |
| 26 namespace device { | 26 namespace device { |
| 27 class AccessTokenStore; | 27 class AccessTokenStore; |
| 28 | 28 |
| 29 class NetworkLocationProvider : public base::NonThreadSafe, | 29 class NetworkLocationProvider : public base::NonThreadSafe, |
| 30 public LocationProviderBase { | 30 public LocationProvider { |
| 31 public: | 31 public: |
| 32 // Cache of recently resolved locations. Public for tests. | 32 // Cache of recently resolved locations. Public for tests. |
| 33 class DEVICE_GEOLOCATION_EXPORT PositionCache { | 33 class DEVICE_GEOLOCATION_EXPORT PositionCache { |
| 34 public: | 34 public: |
| 35 // The maximum size of the cache of positions. | 35 // The maximum size of the cache of positions. |
| 36 static const size_t kMaximumSize; | 36 static const size_t kMaximumSize; |
| 37 | 37 |
| 38 PositionCache(); | 38 PositionCache(); |
| 39 ~PositionCache(); | 39 ~PositionCache(); |
| 40 | 40 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 NetworkLocationProvider( | 66 NetworkLocationProvider( |
| 67 const scoped_refptr<AccessTokenStore>& access_token_store, | 67 const scoped_refptr<AccessTokenStore>& access_token_store, |
| 68 const scoped_refptr<net::URLRequestContextGetter>& context, | 68 const scoped_refptr<net::URLRequestContextGetter>& context, |
| 69 const GURL& url, | 69 const GURL& url, |
| 70 const base::string16& access_token); | 70 const base::string16& access_token); |
| 71 ~NetworkLocationProvider() override; | 71 ~NetworkLocationProvider() override; |
| 72 | 72 |
| 73 // LocationProvider implementation | 73 // LocationProvider implementation |
| 74 void SetUpdateCallback( |
| 75 const LocationProviderUpdateCallback& callback) override; |
| 74 bool StartProvider(bool high_accuracy) override; | 76 bool StartProvider(bool high_accuracy) override; |
| 75 void StopProvider() override; | 77 void StopProvider() override; |
| 76 const Geoposition& GetPosition() override; | 78 const Geoposition& GetPosition() override; |
| 77 void OnPermissionGranted() override; | 79 void OnPermissionGranted() override; |
| 78 | 80 |
| 79 private: | 81 private: |
| 80 // Satisfies a position request from cache or network. | 82 // Satisfies a position request from cache or network. |
| 81 void RequestPosition(); | 83 void RequestPosition(); |
| 82 | 84 |
| 83 // Gets called when new wifi data is available. | 85 // Gets called when new wifi data is available. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 107 // The timestamp for the latest wifi data update. | 109 // The timestamp for the latest wifi data update. |
| 108 base::Time wifi_timestamp_; | 110 base::Time wifi_timestamp_; |
| 109 | 111 |
| 110 // Cached value loaded from the token store or set by a previous server | 112 // Cached value loaded from the token store or set by a previous server |
| 111 // response, and sent in each subsequent network request. | 113 // response, and sent in each subsequent network request. |
| 112 base::string16 access_token_; | 114 base::string16 access_token_; |
| 113 | 115 |
| 114 // The current best position estimate. | 116 // The current best position estimate. |
| 115 Geoposition position_; | 117 Geoposition position_; |
| 116 | 118 |
| 119 LocationProvider::LocationProviderUpdateCallback |
| 120 location_provider_update_callback_; |
| 121 |
| 117 // Whether permission has been granted for the provider to operate. | 122 // Whether permission has been granted for the provider to operate. |
| 118 bool is_permission_granted_; | 123 bool is_permission_granted_; |
| 119 | 124 |
| 120 bool is_new_data_available_; | 125 bool is_new_data_available_; |
| 121 | 126 |
| 122 // The network location request object, and the url it uses. | 127 // The network location request object, and the url it uses. |
| 123 std::unique_ptr<NetworkLocationRequest> request_; | 128 std::unique_ptr<NetworkLocationRequest> request_; |
| 124 | 129 |
| 125 // The cache of positions. | 130 // The cache of positions. |
| 126 const std::unique_ptr<PositionCache> position_cache_; | 131 const std::unique_ptr<PositionCache> position_cache_; |
| 127 | 132 |
| 128 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; | 133 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; |
| 129 | 134 |
| 130 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); | 135 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); |
| 131 }; | 136 }; |
| 132 | 137 |
| 133 // Factory functions for the various types of location provider to abstract | 138 // Factory functions for the various types of location provider to abstract |
| 134 // over the platform-dependent implementations. | 139 // over the platform-dependent implementations. |
| 135 DEVICE_GEOLOCATION_EXPORT LocationProviderBase* NewNetworkLocationProvider( | 140 DEVICE_GEOLOCATION_EXPORT LocationProvider* NewNetworkLocationProvider( |
| 136 const scoped_refptr<AccessTokenStore>& access_token_store, | 141 const scoped_refptr<AccessTokenStore>& access_token_store, |
| 137 const scoped_refptr<net::URLRequestContextGetter>& context, | 142 const scoped_refptr<net::URLRequestContextGetter>& context, |
| 138 const GURL& url, | 143 const GURL& url, |
| 139 const base::string16& access_token); | 144 const base::string16& access_token); |
| 140 | 145 |
| 141 } // namespace device | 146 } // namespace device |
| 142 | 147 |
| 143 #endif // DEVICE_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 148 #endif // DEVICE_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| OLD | NEW |