| 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_NETWORK_LOCATION_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 6 #define CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "content/browser/geolocation/device_data_provider.h" | 17 #include "content/browser/geolocation/device_data_provider.h" |
| 18 #include "content/browser/geolocation/location_provider.h" | 18 #include "content/browser/geolocation/location_provider.h" |
| 19 #include "content/browser/geolocation/network_location_request.h" | 19 #include "content/browser/geolocation/network_location_request.h" |
| 20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 21 #include "content/public/common/geoposition.h" | 21 #include "content/public/common/geoposition.h" |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 class AccessTokenStore; | 24 class AccessTokenStore; |
| 25 } | 25 } |
| 26 | 26 |
| 27 class NetworkLocationProvider | 27 class NetworkLocationProvider |
| 28 : public LocationProviderBase, | 28 : public LocationProviderBase, |
| 29 public RadioDataProvider::ListenerInterface, | |
| 30 public WifiDataProvider::ListenerInterface, | 29 public WifiDataProvider::ListenerInterface, |
| 31 public NetworkLocationRequest::ListenerInterface { | 30 public NetworkLocationRequest::ListenerInterface { |
| 32 public: | 31 public: |
| 33 // Cache of recently resolved locations. Public for tests. | 32 // Cache of recently resolved locations. Public for tests. |
| 34 class CONTENT_EXPORT PositionCache { | 33 class CONTENT_EXPORT PositionCache { |
| 35 public: | 34 public: |
| 36 // The maximum size of the cache of positions for previously requested | 35 // The maximum size of the cache of positions for previously requested |
| 37 // device data. | 36 // device data. |
| 38 static const size_t kMaximumSize; | 37 static const size_t kMaximumSize; |
| 39 | 38 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 private: | 82 private: |
| 84 // Satisfies a position request from cache or network. | 83 // Satisfies a position request from cache or network. |
| 85 void RequestPosition(); | 84 void RequestPosition(); |
| 86 | 85 |
| 87 // Internal helper used by DeviceDataUpdateAvailable | 86 // Internal helper used by DeviceDataUpdateAvailable |
| 88 void OnDeviceDataUpdated(); | 87 void OnDeviceDataUpdated(); |
| 89 | 88 |
| 90 bool IsStarted() const; | 89 bool IsStarted() const; |
| 91 | 90 |
| 92 // DeviceDataProvider::ListenerInterface implementation. | 91 // DeviceDataProvider::ListenerInterface implementation. |
| 93 virtual void DeviceDataUpdateAvailable(RadioDataProvider* provider) OVERRIDE; | |
| 94 virtual void DeviceDataUpdateAvailable(WifiDataProvider* provider) OVERRIDE; | 92 virtual void DeviceDataUpdateAvailable(WifiDataProvider* provider) OVERRIDE; |
| 95 | 93 |
| 96 // NetworkLocationRequest::ListenerInterface implementation. | 94 // NetworkLocationRequest::ListenerInterface implementation. |
| 97 virtual void LocationResponseAvailable(const content::Geoposition& position, | 95 virtual void LocationResponseAvailable(const content::Geoposition& position, |
| 98 bool server_error, | 96 bool server_error, |
| 99 const string16& access_token, | 97 const string16& access_token, |
| 100 const RadioData& radio_data, | |
| 101 const WifiData& wifi_data) OVERRIDE; | 98 const WifiData& wifi_data) OVERRIDE; |
| 102 | 99 |
| 103 scoped_refptr<content::AccessTokenStore> access_token_store_; | 100 scoped_refptr<content::AccessTokenStore> access_token_store_; |
| 104 | 101 |
| 105 // The device data providers, acquired via global factories. | 102 // The wifi data provider, acquired via global factories. |
| 106 RadioDataProvider* radio_data_provider_; | |
| 107 WifiDataProvider* wifi_data_provider_; | 103 WifiDataProvider* wifi_data_provider_; |
| 108 | 104 |
| 109 // The radio and wifi data, flags to indicate if each data set is complete. | 105 // The wifi data, flags to indicate if the data set is complete. |
| 110 RadioData radio_data_; | |
| 111 WifiData wifi_data_; | 106 WifiData wifi_data_; |
| 112 bool is_radio_data_complete_; | |
| 113 bool is_wifi_data_complete_; | 107 bool is_wifi_data_complete_; |
| 114 | 108 |
| 115 // The timestamp for the latest device data update. | 109 // The timestamp for the latest device data update. |
| 116 base::Time device_data_updated_timestamp_; | 110 base::Time device_data_updated_timestamp_; |
| 117 | 111 |
| 118 // 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 |
| 119 // response, and sent in each subsequent network request. | 113 // response, and sent in each subsequent network request. |
| 120 string16 access_token_; | 114 string16 access_token_; |
| 121 | 115 |
| 122 // The current best position estimate. | 116 // The current best position estimate. |
| 123 content::Geoposition position_; | 117 content::Geoposition position_; |
| 124 | 118 |
| 125 // Whether permission has been granted for the provider to operate. | 119 // Whether permission has been granted for the provider to operate. |
| 126 bool is_permission_granted_; | 120 bool is_permission_granted_; |
| 127 | 121 |
| 128 bool is_new_data_available_; | 122 bool is_new_data_available_; |
| 129 | 123 |
| 130 // The network location request object, and the url it uses. | 124 // The network location request object, and the url it uses. |
| 131 scoped_ptr<NetworkLocationRequest> request_; | 125 scoped_ptr<NetworkLocationRequest> request_; |
| 132 | 126 |
| 133 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; | 127 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; |
| 134 // The cache of positions. | 128 // The cache of positions. |
| 135 scoped_ptr<PositionCache> position_cache_; | 129 scoped_ptr<PositionCache> position_cache_; |
| 136 | 130 |
| 137 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); | 131 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); |
| 138 }; | 132 }; |
| 139 | 133 |
| 140 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ | 134 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ |
| OLD | NEW |