OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ | 5 #ifndef NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ |
6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ | 6 #define NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/time/default_tick_clock.h" | |
18 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "net/base/host_port_pair.h" | 21 #include "net/base/host_port_pair.h" |
21 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
22 #include "net/http/http_server_properties.h" | 23 #include "net/http/http_server_properties.h" |
23 #include "net/http/http_server_properties_impl.h" | 24 #include "net/http/http_server_properties_impl.h" |
24 #include "net/log/net_log_with_source.h" | 25 #include "net/log/net_log_with_source.h" |
25 | 26 |
26 namespace base { | 27 namespace base { |
27 class SingleThreadTaskRunner; | 28 class SingleThreadTaskRunner; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // | 87 // |
87 // Ownership of the PrefDelegate pointer is taken by this class. This is | 88 // Ownership of the PrefDelegate pointer is taken by this class. This is |
88 // passed as a raw pointer rather than a scoped_refptr currently because | 89 // passed as a raw pointer rather than a scoped_refptr currently because |
89 // the test uses gmock and it doesn't forward move semantics properly. | 90 // the test uses gmock and it doesn't forward move semantics properly. |
90 // | 91 // |
91 // There are two SingleThreadTaskRunners: | 92 // There are two SingleThreadTaskRunners: |
92 // |pref_task_runner| should be bound with the pref thread and is used to post | 93 // |pref_task_runner| should be bound with the pref thread and is used to post |
93 // cache update to the pref thread; | 94 // cache update to the pref thread; |
94 // |network_task_runner| should be bound with the network thread and is used | 95 // |network_task_runner| should be bound with the network thread and is used |
95 // to post pref update to the cache thread. | 96 // to post pref update to the cache thread. |
97 // | |
98 // |clock| is used for setting expiration times and scheduling the | |
99 // expiration of broken alternative services. It must not be null. | |
96 HttpServerPropertiesManager( | 100 HttpServerPropertiesManager( |
97 PrefDelegate* pref_delegate, | 101 PrefDelegate* pref_delegate, |
98 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, | 102 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, |
103 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
104 NetLog* net_log, | |
105 base::TickClock* clock); | |
106 | |
107 // Default clock will be used. | |
108 HttpServerPropertiesManager( | |
109 PrefDelegate* pref_delegate, | |
110 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, | |
99 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | 111 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
100 NetLog* net_log); | 112 NetLog* net_log); |
101 ~HttpServerPropertiesManager() override; | 113 ~HttpServerPropertiesManager() override; |
102 | 114 |
103 // Initialize on Network thread. | 115 // Initialize on Network thread. |
104 void InitializeOnNetworkSequence(); | 116 void InitializeOnNetworkSequence(); |
105 | 117 |
106 // Prepare for shutdown. Must be called on the Pref thread before destruction. | 118 // Prepare for shutdown. Must be called on the Pref thread before destruction. |
107 void ShutdownOnPrefSequence(); | 119 void ShutdownOnPrefSequence(); |
108 | 120 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 virtual void UpdateCacheFromPrefsOnPrefSequence(); | 218 virtual void UpdateCacheFromPrefsOnPrefSequence(); |
207 | 219 |
208 // Starts the update of cached prefs in |http_server_properties_impl_| on the | 220 // Starts the update of cached prefs in |http_server_properties_impl_| on the |
209 // network thread. Protected for testing. | 221 // network thread. Protected for testing. |
210 void UpdateCacheFromPrefsOnNetworkSequence( | 222 void UpdateCacheFromPrefsOnNetworkSequence( |
211 std::unique_ptr<SpdyServersMap> spdy_servers_map, | 223 std::unique_ptr<SpdyServersMap> spdy_servers_map, |
212 std::unique_ptr<AlternativeServiceMap> alternative_service_map, | 224 std::unique_ptr<AlternativeServiceMap> alternative_service_map, |
213 std::unique_ptr<IPAddress> last_quic_address, | 225 std::unique_ptr<IPAddress> last_quic_address, |
214 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map, | 226 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map, |
215 std::unique_ptr<QuicServerInfoMap> quic_server_info_map, | 227 std::unique_ptr<QuicServerInfoMap> quic_server_info_map, |
228 std::unique_ptr<BrokenAlternativeServiceList> | |
229 broken_alternative_service_list, | |
230 std::unique_ptr<RecentlyBrokenAlternativeServices> | |
231 recently_broken_alternative_services, | |
216 bool detected_corrupted_prefs); | 232 bool detected_corrupted_prefs); |
217 | 233 |
218 // These are used to delay updating the preferences when cached data in | 234 // These are used to delay updating the preferences when cached data in |
219 // |http_server_properties_impl_| is changing, and execute only one update per | 235 // |http_server_properties_impl_| is changing, and execute only one update per |
220 // simultaneous spdy_servers or spdy_settings or alternative_service changes. | 236 // simultaneous spdy_servers or spdy_settings or alternative_service changes. |
221 // |location| specifies where this method is called from. Virtual for testing. | 237 // |location| specifies where this method is called from. Virtual for testing. |
222 virtual void ScheduleUpdatePrefsOnNetworkSequence(Location location); | 238 virtual void ScheduleUpdatePrefsOnNetworkSequence(Location location); |
223 | 239 |
224 // Update prefs::kHttpServerProperties in preferences with the cached data | 240 // Update prefs::kHttpServerProperties in preferences with the cached data |
225 // from |http_server_properties_impl_|. This gets the data on network thread | 241 // from |http_server_properties_impl_|. This gets the data on network thread |
226 // and posts a task (UpdatePrefsOnPrefThread) to update preferences on pref | 242 // and posts a task (UpdatePrefsOnPrefThread) to update preferences on pref |
227 // thread. | 243 // thread. |
228 void UpdatePrefsFromCacheOnNetworkSequence(); | 244 void UpdatePrefsFromCacheOnNetworkSequence(); |
229 | 245 |
230 // Same as above, but fires an optional |completion| callback on pref thread | 246 // Same as above, but fires an optional |completion| callback on pref thread |
231 // when finished. Virtual for testing. | 247 // when finished. Virtual for testing. |
232 virtual void UpdatePrefsFromCacheOnNetworkSequence( | 248 virtual void UpdatePrefsFromCacheOnNetworkSequence( |
233 const base::Closure& completion); | 249 const base::Closure& completion); |
234 | 250 |
235 // Update prefs::kHttpServerProperties preferences on pref thread. Executes an | 251 // Update prefs::kHttpServerProperties preferences on pref thread. Executes an |
236 // optional |completion| callback when finished. Protected for testing. | 252 // optional |completion| callback when finished. Protected for testing. |
237 void UpdatePrefsOnPrefThread( | 253 void UpdatePrefsOnPrefThread( |
238 std::unique_ptr<std::vector<std::string>> spdy_servers, | 254 std::unique_ptr<std::vector<std::string>> spdy_servers, |
239 std::unique_ptr<AlternativeServiceMap> alternative_service_map, | 255 std::unique_ptr<AlternativeServiceMap> alternative_service_map, |
240 std::unique_ptr<IPAddress> last_quic_address, | 256 std::unique_ptr<IPAddress> last_quic_address, |
241 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map, | 257 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map, |
242 std::unique_ptr<QuicServerInfoMap> quic_server_info_map, | 258 std::unique_ptr<QuicServerInfoMap> quic_server_info_map, |
259 std::unique_ptr<BrokenAlternativeServiceList> | |
260 broken_alternative_service_list, | |
261 std::unique_ptr<RecentlyBrokenAlternativeServices> | |
262 recently_broken_alternative_services, | |
243 const base::Closure& completion); | 263 const base::Closure& completion); |
244 | 264 |
245 private: | 265 private: |
246 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, | 266 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, |
247 AddToAlternativeServiceMap); | 267 AddToAlternativeServiceMap); |
248 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, | 268 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, |
249 DoNotLoadAltSvcForInsecureOrigins); | 269 DoNotLoadAltSvcForInsecureOrigins); |
250 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, | 270 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, |
251 DoNotLoadExpiredAlternativeService); | 271 DoNotLoadExpiredAlternativeService); |
252 void OnHttpServerPropertiesChanged(); | 272 void OnHttpServerPropertiesChanged(); |
253 | 273 |
254 bool AddServersData(const base::DictionaryValue& server_dict, | 274 bool AddServersData(const base::DictionaryValue& server_dict, |
255 SpdyServersMap* spdy_servers_map, | 275 SpdyServersMap* spdy_servers_map, |
256 AlternativeServiceMap* alternative_service_map, | 276 AlternativeServiceMap* alternative_service_map, |
257 ServerNetworkStatsMap* network_stats_map, | 277 ServerNetworkStatsMap* network_stats_map, |
258 int version); | 278 int version); |
259 bool ParseAlternativeServiceDict( | 279 bool ParseAlternativeServiceDict(const base::DictionaryValue& dict, |
260 const base::DictionaryValue& alternative_service_dict, | 280 bool host_required, |
281 const std::string& parsing_under, | |
282 AlternativeService* alternative_service); | |
283 bool ParseAlternativeServiceInfoExpiration( | |
284 const base::DictionaryValue& dict, | |
261 const std::string& server_str, | 285 const std::string& server_str, |
262 AlternativeServiceInfo* alternative_service_info); | 286 AlternativeServiceInfo* alternative_service_info); |
263 bool AddToAlternativeServiceMap( | 287 bool AddToAlternativeServiceMap( |
264 const url::SchemeHostPort& server, | 288 const url::SchemeHostPort& server, |
265 const base::DictionaryValue& server_dict, | 289 const base::DictionaryValue& server_dict, |
266 AlternativeServiceMap* alternative_service_map); | 290 AlternativeServiceMap* alternative_service_map); |
267 bool ReadSupportsQuic(const base::DictionaryValue& server_dict, | 291 bool ReadSupportsQuic(const base::DictionaryValue& server_dict, |
268 IPAddress* last_quic_address); | 292 IPAddress* last_quic_address); |
269 bool AddToNetworkStatsMap(const url::SchemeHostPort& server, | 293 bool AddToNetworkStatsMap(const url::SchemeHostPort& server, |
270 const base::DictionaryValue& server_dict, | 294 const base::DictionaryValue& server_dict, |
271 ServerNetworkStatsMap* network_stats_map); | 295 ServerNetworkStatsMap* network_stats_map); |
272 bool AddToQuicServerInfoMap(const base::DictionaryValue& server_dict, | 296 bool AddToQuicServerInfoMap(const base::DictionaryValue& server_dict, |
273 QuicServerInfoMap* quic_server_info_map); | 297 QuicServerInfoMap* quic_server_info_map); |
274 | 298 bool AddToBrokenAlternativeServices( |
299 const base::DictionaryValue& broken_alt_svc_entry_dict, | |
300 BrokenAlternativeServiceList* broken_alternative_service_list, | |
301 RecentlyBrokenAlternativeServices* recently_broken_alternative_services); | |
275 void SaveAlternativeServiceToServerPrefs( | 302 void SaveAlternativeServiceToServerPrefs( |
276 const AlternativeServiceInfoVector& alternative_service_info_vector, | 303 const AlternativeServiceInfoVector& alternative_service_info_vector, |
277 base::DictionaryValue* server_pref_dict); | 304 base::DictionaryValue* server_pref_dict); |
278 void SaveSupportsQuicToPrefs( | 305 void SaveSupportsQuicToPrefs( |
279 const IPAddress& last_quic_address, | 306 const IPAddress& last_quic_address, |
280 base::DictionaryValue* http_server_properties_dict); | 307 base::DictionaryValue* http_server_properties_dict); |
281 void SaveNetworkStatsToServerPrefs( | 308 void SaveNetworkStatsToServerPrefs( |
282 const ServerNetworkStats& server_network_stats, | 309 const ServerNetworkStats& server_network_stats, |
283 base::DictionaryValue* server_pref_dict); | 310 base::DictionaryValue* server_pref_dict); |
284 void SaveQuicServerInfoMapToServerPrefs( | 311 void SaveQuicServerInfoMapToServerPrefs( |
285 const QuicServerInfoMap& quic_server_info_map, | 312 const QuicServerInfoMap& quic_server_info_map, |
286 base::DictionaryValue* http_server_properties_dict); | 313 base::DictionaryValue* http_server_properties_dict); |
314 void SaveBrokenAlternativeServicesToPrefs( | |
315 const BrokenAlternativeServiceList* broken_alternative_service_list, | |
316 const RecentlyBrokenAlternativeServices* | |
317 recently_broken_alternative_services, | |
318 base::DictionaryValue* http_server_properties_dict); | |
319 | |
287 void SetInitialized(); | 320 void SetInitialized(); |
288 | 321 |
322 base::DefaultTickClock default_clock_; | |
Ryan Hamilton
2017/07/06 16:48:22
Do we really need a default clock in both the impl
wangyix1
2017/07/06 18:04:29
I put a default clock in impl since it's instantia
Ryan Hamilton
2017/07/06 18:36:19
Ah, I see. Yuck :(
| |
323 | |
289 // ----------- | 324 // ----------- |
290 // Pref thread | 325 // Pref thread |
291 // ----------- | 326 // ----------- |
292 | 327 |
293 const scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; | 328 const scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; |
294 | 329 |
295 base::WeakPtr<HttpServerPropertiesManager> pref_weak_ptr_; | 330 base::WeakPtr<HttpServerPropertiesManager> pref_weak_ptr_; |
296 | 331 |
297 // Used to post cache update tasks. | 332 // Used to post cache update tasks. |
298 std::unique_ptr<base::OneShotTimer> pref_cache_update_timer_; | 333 std::unique_ptr<base::OneShotTimer> pref_cache_update_timer_; |
299 | 334 |
300 std::unique_ptr<PrefDelegate> pref_delegate_; | 335 std::unique_ptr<PrefDelegate> pref_delegate_; |
301 bool setting_prefs_; | 336 bool setting_prefs_; |
302 | 337 |
338 base::TickClock* clock_; // Unowned | |
339 | |
303 // -------------- | 340 // -------------- |
304 // Network thread | 341 // Network thread |
305 // -------------- | 342 // -------------- |
306 | 343 |
307 // Whether InitializeOnNetworkSequence() has completed. | 344 // Whether InitializeOnNetworkSequence() has completed. |
308 bool is_initialized_; | 345 bool is_initialized_; |
309 | 346 |
310 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 347 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
311 | 348 |
312 // Used to post |prefs::kHttpServerProperties| pref update tasks. | 349 // Used to post |prefs::kHttpServerProperties| pref update tasks. |
(...skipping 10 matching lines...) Expand all Loading... | |
323 network_weak_ptr_factory_; | 360 network_weak_ptr_factory_; |
324 | 361 |
325 const NetLogWithSource net_log_; | 362 const NetLogWithSource net_log_; |
326 | 363 |
327 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager); | 364 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager); |
328 }; | 365 }; |
329 | 366 |
330 } // namespace net | 367 } // namespace net |
331 | 368 |
332 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ | 369 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ |
OLD | NEW |