Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: content/browser/geolocation/network_location_provider.h

Issue 2129313002: Geolocation cleanup: corrects uses of content::AccessTokenStore* and net::URLRequestContextGetter* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed StartTestStepFromClientThread() Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 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 "content/browser/geolocation/location_provider_base.h" 20 #include "content/browser/geolocation/location_provider_base.h"
21 #include "content/browser/geolocation/network_location_request.h" 21 #include "content/browser/geolocation/network_location_request.h"
22 #include "content/browser/geolocation/wifi_data_provider_manager.h" 22 #include "content/browser/geolocation/wifi_data_provider_manager.h"
23 #include "content/common/content_export.h" 23 #include "content/common/content_export.h"
24 #include "content/public/common/geoposition.h" 24 #include "content/public/common/geoposition.h"
25 25
26 namespace content { 26 namespace content {
27 class AccessTokenStore; 27 class AccessTokenStore;
28 28
29 29 class NetworkLocationProvider : public base::NonThreadSafe,
30 class NetworkLocationProvider 30 public LocationProviderBase {
31 : public base::NonThreadSafe,
32 public LocationProviderBase {
33 public: 31 public:
34 // Cache of recently resolved locations. Public for tests. 32 // Cache of recently resolved locations. Public for tests.
35 class CONTENT_EXPORT PositionCache { 33 class CONTENT_EXPORT PositionCache {
36 public: 34 public:
37 // The maximum size of the cache of positions. 35 // The maximum size of the cache of positions.
38 static const size_t kMaximumSize; 36 static const size_t kMaximumSize;
39 37
40 PositionCache(); 38 PositionCache();
41 ~PositionCache(); 39 ~PositionCache();
42 40
(...skipping 17 matching lines...) Expand all
60 58
61 // The cache of positions. This is stored as a map keyed on a string that 59 // The cache of positions. This is stored as a map keyed on a string that
62 // represents a set of data, and a list to provide 60 // represents a set of data, and a list to provide
63 // least-recently-added eviction. 61 // least-recently-added eviction.
64 typedef std::map<base::string16, Geoposition> CacheMap; 62 typedef std::map<base::string16, Geoposition> CacheMap;
65 CacheMap cache_; 63 CacheMap cache_;
66 typedef std::list<CacheMap::iterator> CacheAgeList; 64 typedef std::list<CacheMap::iterator> CacheAgeList;
67 CacheAgeList cache_age_list_; // Oldest first. 65 CacheAgeList cache_age_list_; // Oldest first.
68 }; 66 };
69 67
70 NetworkLocationProvider(AccessTokenStore* access_token_store, 68 NetworkLocationProvider(
71 net::URLRequestContextGetter* context, 69 const scoped_refptr<AccessTokenStore>& access_token_store,
72 const GURL& url, 70 const scoped_refptr<net::URLRequestContextGetter>& context,
73 const base::string16& access_token); 71 const GURL& url,
72 const base::string16& access_token);
74 ~NetworkLocationProvider() override; 73 ~NetworkLocationProvider() override;
75 74
76 // LocationProvider implementation 75 // LocationProvider implementation
77 bool StartProvider(bool high_accuracy) override; 76 bool StartProvider(bool high_accuracy) override;
78 void StopProvider() override; 77 void StopProvider() override;
79 void GetPosition(Geoposition* position) override; 78 void GetPosition(Geoposition* position) override;
80 void RequestRefresh() override; 79 void RequestRefresh() override;
81 void OnPermissionGranted() override; 80 void OnPermissionGranted() override;
82 81
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 // Gets called when new wifi data is available. 86 // Gets called when new wifi data is available.
88 void OnWifiDataUpdate(); 87 void OnWifiDataUpdate();
89 88
90 // Internal helper used by OnWifiDataUpdate. 89 // Internal helper used by OnWifiDataUpdate.
91 void OnWifiDataUpdated(); 90 void OnWifiDataUpdated();
92 91
93 bool IsStarted() const; 92 bool IsStarted() const;
94 93
95 void OnLocationResponse(const Geoposition& position, 94 void OnLocationResponse(const Geoposition& position,
96 bool server_error, 95 bool server_error,
97 const base::string16& access_token, 96 const base::string16& access_token,
98 const WifiData& wifi_data); 97 const WifiData& wifi_data);
99 98
100 scoped_refptr<AccessTokenStore> access_token_store_; 99 const scoped_refptr<AccessTokenStore> access_token_store_;
101 100
102 // The wifi data provider, acquired via global factories. 101 // The wifi data provider, acquired via global factories.
103 WifiDataProviderManager* wifi_data_provider_manager_; 102 WifiDataProviderManager* wifi_data_provider_manager_;
104 103
105 WifiDataProviderManager::WifiDataUpdateCallback wifi_data_update_callback_; 104 WifiDataProviderManager::WifiDataUpdateCallback wifi_data_update_callback_;
106 105
107 // The wifi data and a flag to indicate if the data set is complete. 106 // The wifi data and a flag to indicate if the data set is complete.
108 WifiData wifi_data_; 107 WifiData wifi_data_;
109 bool is_wifi_data_complete_; 108 bool is_wifi_data_complete_;
110 109
111 // The timestamp for the latest wifi data update. 110 // The timestamp for the latest wifi data update.
112 base::Time wifi_timestamp_; 111 base::Time wifi_timestamp_;
113 112
114 // Cached value loaded from the token store or set by a previous server 113 // Cached value loaded from the token store or set by a previous server
115 // response, and sent in each subsequent network request. 114 // response, and sent in each subsequent network request.
116 base::string16 access_token_; 115 base::string16 access_token_;
117 116
118 // The current best position estimate. 117 // The current best position estimate.
119 Geoposition position_; 118 Geoposition position_;
120 119
121 // Whether permission has been granted for the provider to operate. 120 // Whether permission has been granted for the provider to operate.
122 bool is_permission_granted_; 121 bool is_permission_granted_;
123 122
124 bool is_new_data_available_; 123 bool is_new_data_available_;
125 124
126 // The network location request object, and the url it uses. 125 // The network location request object, and the url it uses.
127 std::unique_ptr<NetworkLocationRequest> request_; 126 std::unique_ptr<NetworkLocationRequest> request_;
128 127
129 // The cache of positions. 128 // The cache of positions.
130 std::unique_ptr<PositionCache> position_cache_; 129 const std::unique_ptr<PositionCache> position_cache_;
131 130
132 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_; 131 base::WeakPtrFactory<NetworkLocationProvider> weak_factory_;
133 132
134 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider); 133 DISALLOW_COPY_AND_ASSIGN(NetworkLocationProvider);
135 }; 134 };
136 135
137 // Factory functions for the various types of location provider to abstract 136 // Factory functions for the various types of location provider to abstract
138 // over the platform-dependent implementations. 137 // over the platform-dependent implementations.
139 CONTENT_EXPORT LocationProviderBase* NewNetworkLocationProvider( 138 CONTENT_EXPORT LocationProviderBase* NewNetworkLocationProvider(
140 AccessTokenStore* access_token_store, 139 const scoped_refptr<AccessTokenStore>& access_token_store,
141 net::URLRequestContextGetter* context, 140 const scoped_refptr<net::URLRequestContextGetter>& context,
142 const GURL& url, 141 const GURL& url,
143 const base::string16& access_token); 142 const base::string16& access_token);
144 143
145 } // namespace content 144 } // namespace content
146 145
147 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_ 146 #endif // CONTENT_BROWSER_GEOLOCATION_NETWORK_LOCATION_PROVIDER_H_
OLDNEW
« no previous file with comments | « content/browser/geolocation/location_provider_android.cc ('k') | content/browser/geolocation/network_location_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698