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 | 25 |
25 namespace base { | 26 namespace base { |
26 class SingleThreadTaskRunner; | 27 class SingleThreadTaskRunner; |
28 class TickClock; | |
27 } | 29 } |
28 | 30 |
29 namespace net { | 31 namespace net { |
30 | 32 |
31 class IPAddress; | 33 class IPAddress; |
32 | 34 |
33 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
34 // HttpServerPropertiesManager | 36 // HttpServerPropertiesManager |
35 | 37 |
36 // The manager for creating and updating an HttpServerProperties (for example it | 38 // The manager for creating and updating an HttpServerProperties (for example it |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // | 87 // |
86 // 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 |
87 // 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 |
88 // 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. |
89 // | 91 // |
90 // There are two SingleThreadTaskRunners: | 92 // There are two SingleThreadTaskRunners: |
91 // |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 |
92 // cache update to the pref thread; | 94 // cache update to the pref thread; |
93 // |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 |
94 // 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. | |
100 HttpServerPropertiesManager( | |
101 PrefDelegate* pref_delegate, | |
102 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, | |
103 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
104 base::TickClock* clock); | |
105 | |
106 // Default clock will be used. | |
95 HttpServerPropertiesManager( | 107 HttpServerPropertiesManager( |
96 PrefDelegate* pref_delegate, | 108 PrefDelegate* pref_delegate, |
97 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, | 109 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, |
98 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); | 110 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); |
111 | |
99 ~HttpServerPropertiesManager() override; | 112 ~HttpServerPropertiesManager() override; |
100 | 113 |
101 // Initialize on Network thread. | 114 // Initialize on Network thread. |
102 void InitializeOnNetworkSequence(); | 115 void InitializeOnNetworkSequence(); |
103 | 116 |
104 // Prepare for shutdown. Must be called on the Pref thread before destruction. | 117 // Prepare for shutdown. Must be called on the Pref thread before destruction. |
105 void ShutdownOnPrefSequence(); | 118 void ShutdownOnPrefSequence(); |
106 | 119 |
107 // Helper function for unit tests to set the version in the dictionary. | 120 // Helper function for unit tests to set the version in the dictionary. |
108 static void SetVersion(base::DictionaryValue* http_server_properties_dict, | 121 static void SetVersion(base::DictionaryValue* http_server_properties_dict, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 virtual void UpdateCacheFromPrefsOnPrefSequence(); | 217 virtual void UpdateCacheFromPrefsOnPrefSequence(); |
205 | 218 |
206 // Starts the update of cached prefs in |http_server_properties_impl_| on the | 219 // Starts the update of cached prefs in |http_server_properties_impl_| on the |
207 // network thread. Protected for testing. | 220 // network thread. Protected for testing. |
208 void UpdateCacheFromPrefsOnNetworkSequence( | 221 void UpdateCacheFromPrefsOnNetworkSequence( |
209 std::vector<std::string>* spdy_servers, | 222 std::vector<std::string>* spdy_servers, |
210 AlternativeServiceMap* alternative_service_map, | 223 AlternativeServiceMap* alternative_service_map, |
211 IPAddress* last_quic_address, | 224 IPAddress* last_quic_address, |
212 ServerNetworkStatsMap* server_network_stats_map, | 225 ServerNetworkStatsMap* server_network_stats_map, |
213 QuicServerInfoMap* quic_server_info_map, | 226 QuicServerInfoMap* quic_server_info_map, |
227 std::unique_ptr<BrokenAlternativeServiceList> | |
228 broken_alternative_service_list, | |
229 std::unique_ptr<RecentlyBrokenAlternativeServices> | |
230 recently_broken_alternative_services, | |
Zhongyi Shi
2017/06/16 04:17:09
Can we just use raw pointers here? Is there any st
wangyix1
2017/06/16 18:41:15
Acknowledged.
| |
214 bool detected_corrupted_prefs); | 231 bool detected_corrupted_prefs); |
215 | 232 |
216 // These are used to delay updating the preferences when cached data in | 233 // These are used to delay updating the preferences when cached data in |
217 // |http_server_properties_impl_| is changing, and execute only one update per | 234 // |http_server_properties_impl_| is changing, and execute only one update per |
218 // simultaneous spdy_servers or spdy_settings or alternative_service changes. | 235 // simultaneous spdy_servers or spdy_settings or alternative_service changes. |
219 // |location| specifies where this method is called from. Virtual for testing. | 236 // |location| specifies where this method is called from. Virtual for testing. |
220 virtual void ScheduleUpdatePrefsOnNetworkSequence(Location location); | 237 virtual void ScheduleUpdatePrefsOnNetworkSequence(Location location); |
221 | 238 |
222 // Update prefs::kHttpServerProperties in preferences with the cached data | 239 // Update prefs::kHttpServerProperties in preferences with the cached data |
223 // from |http_server_properties_impl_|. This gets the data on network thread | 240 // from |http_server_properties_impl_|. This gets the data on network thread |
224 // and posts a task (UpdatePrefsOnPrefThread) to update preferences on pref | 241 // and posts a task (UpdatePrefsOnPrefThread) to update preferences on pref |
225 // thread. | 242 // thread. |
226 void UpdatePrefsFromCacheOnNetworkSequence(); | 243 void UpdatePrefsFromCacheOnNetworkSequence(); |
227 | 244 |
228 // Same as above, but fires an optional |completion| callback on pref thread | 245 // Same as above, but fires an optional |completion| callback on pref thread |
229 // when finished. Virtual for testing. | 246 // when finished. Virtual for testing. |
230 virtual void UpdatePrefsFromCacheOnNetworkSequence( | 247 virtual void UpdatePrefsFromCacheOnNetworkSequence( |
231 const base::Closure& completion); | 248 const base::Closure& completion); |
232 | 249 |
233 // Update prefs::kHttpServerProperties preferences on pref thread. Executes an | 250 // Update prefs::kHttpServerProperties preferences on pref thread. Executes an |
234 // optional |completion| callback when finished. Protected for testing. | 251 // optional |completion| callback when finished. Protected for testing. |
235 void UpdatePrefsOnPrefThread(base::ListValue* spdy_server_list, | 252 void UpdatePrefsOnPrefThread( |
236 AlternativeServiceMap* alternative_service_map, | 253 base::ListValue* spdy_server_list, |
237 IPAddress* last_quic_address, | 254 AlternativeServiceMap* alternative_service_map, |
238 ServerNetworkStatsMap* server_network_stats_map, | 255 IPAddress* last_quic_address, |
239 QuicServerInfoMap* quic_server_info_map, | 256 ServerNetworkStatsMap* server_network_stats_map, |
240 const base::Closure& completion); | 257 QuicServerInfoMap* quic_server_info_map, |
258 BrokenAlternativeServiceList* broken_alternative_service_list, | |
259 RecentlyBrokenAlternativeServices* recently_broken_alternative_services, | |
260 const base::Closure& completion); | |
241 | 261 |
242 private: | 262 private: |
243 typedef std::vector<std::string> ServerList; | 263 typedef std::vector<std::string> ServerList; |
244 | 264 |
245 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, | 265 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, |
246 AddToAlternativeServiceMap); | 266 AddToAlternativeServiceMap); |
247 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, | 267 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, |
248 DoNotLoadAltSvcForInsecureOrigins); | 268 DoNotLoadAltSvcForInsecureOrigins); |
249 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, | 269 FRIEND_TEST_ALL_PREFIXES(HttpServerPropertiesManagerTest, |
250 DoNotLoadExpiredAlternativeService); | 270 DoNotLoadExpiredAlternativeService); |
(...skipping 12 matching lines...) Expand all Loading... | |
263 const url::SchemeHostPort& server, | 283 const url::SchemeHostPort& server, |
264 const base::DictionaryValue& server_dict, | 284 const base::DictionaryValue& server_dict, |
265 AlternativeServiceMap* alternative_service_map); | 285 AlternativeServiceMap* alternative_service_map); |
266 bool ReadSupportsQuic(const base::DictionaryValue& server_dict, | 286 bool ReadSupportsQuic(const base::DictionaryValue& server_dict, |
267 IPAddress* last_quic_address); | 287 IPAddress* last_quic_address); |
268 bool AddToNetworkStatsMap(const url::SchemeHostPort& server, | 288 bool AddToNetworkStatsMap(const url::SchemeHostPort& server, |
269 const base::DictionaryValue& server_dict, | 289 const base::DictionaryValue& server_dict, |
270 ServerNetworkStatsMap* network_stats_map); | 290 ServerNetworkStatsMap* network_stats_map); |
271 bool AddToQuicServerInfoMap(const base::DictionaryValue& server_dict, | 291 bool AddToQuicServerInfoMap(const base::DictionaryValue& server_dict, |
272 QuicServerInfoMap* quic_server_info_map); | 292 QuicServerInfoMap* quic_server_info_map); |
293 bool ExtractBrokenAlternativeServiceData( | |
Zhongyi Shi
2017/06/16 04:17:09
nit: %s/ExtractBrokenAlternativeServiceData/AddToB
wangyix1
2017/06/16 18:41:15
Acknowledged.
| |
294 const base::DictionaryValue* broken_alternative_service_dict, | |
295 AlternativeService* alternative_service, | |
296 base::TimeTicks* expiration_time_ticks); | |
297 bool AddRecentlyBrokenAlternativeServiceData( | |
Zhongyi Shi
2017/06/16 04:17:09
nit: %s/AddRecentlyBrokenAlternativeServiceData/Ad
wangyix1
2017/06/16 18:41:15
Done.
| |
298 const base::DictionaryValue* recently_broken_alternative_service_dict, | |
299 RecentlyBrokenAlternativeServices* recently_broken_alternative_services); | |
273 | 300 |
274 void SaveAlternativeServiceToServerPrefs( | 301 void SaveAlternativeServiceToServerPrefs( |
275 const AlternativeServiceInfoVector* alternative_service_info_vector, | 302 const AlternativeServiceInfoVector* alternative_service_info_vector, |
276 base::DictionaryValue* server_pref_dict); | 303 base::DictionaryValue* server_pref_dict); |
277 void SaveSupportsQuicToPrefs( | 304 void SaveSupportsQuicToPrefs( |
278 const IPAddress* last_quic_address, | 305 const IPAddress* last_quic_address, |
279 base::DictionaryValue* http_server_properties_dict); | 306 base::DictionaryValue* http_server_properties_dict); |
280 void SaveNetworkStatsToServerPrefs( | 307 void SaveNetworkStatsToServerPrefs( |
281 const ServerNetworkStats* server_network_stats, | 308 const ServerNetworkStats* server_network_stats, |
282 base::DictionaryValue* server_pref_dict); | 309 base::DictionaryValue* server_pref_dict); |
283 void SaveQuicServerInfoMapToServerPrefs( | 310 void SaveQuicServerInfoMapToServerPrefs( |
284 QuicServerInfoMap* quic_server_info_map, | 311 QuicServerInfoMap* quic_server_info_map, |
285 base::DictionaryValue* http_server_properties_dict); | 312 base::DictionaryValue* http_server_properties_dict); |
313 void SaveBrokenAlternativeServiceListToPrefs( | |
314 const BrokenAlternativeServiceList* broken_alternative_service_list, | |
315 base::DictionaryValue* http_server_properties_dict); | |
316 void SaveRecentlyBrokenAlternativeServicesToPrefs( | |
317 const RecentlyBrokenAlternativeServices* | |
318 recently_broken_alternative_services, | |
319 base::DictionaryValue* http_server_properties_dict); | |
286 void SetInitialized(); | 320 void SetInitialized(); |
287 | 321 |
322 base::DefaultTickClock default_clock_; | |
323 | |
288 // ----------- | 324 // ----------- |
289 // Pref thread | 325 // Pref thread |
290 // ----------- | 326 // ----------- |
291 | 327 |
292 const scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; | 328 const scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; |
293 | 329 |
294 base::WeakPtr<HttpServerPropertiesManager> pref_weak_ptr_; | 330 base::WeakPtr<HttpServerPropertiesManager> pref_weak_ptr_; |
295 | 331 |
296 // Used to post cache update tasks. | 332 // Used to post cache update tasks. |
297 std::unique_ptr<base::OneShotTimer> pref_cache_update_timer_; | 333 std::unique_ptr<base::OneShotTimer> pref_cache_update_timer_; |
298 | 334 |
299 std::unique_ptr<PrefDelegate> pref_delegate_; | 335 std::unique_ptr<PrefDelegate> pref_delegate_; |
300 bool setting_prefs_; | 336 bool setting_prefs_; |
301 | 337 |
338 base::TickClock* clock_; // Unowned | |
339 | |
302 // -------------- | 340 // -------------- |
303 // Network thread | 341 // Network thread |
304 // -------------- | 342 // -------------- |
305 | 343 |
306 // Whether InitializeOnNetworkSequence() has completed. | 344 // Whether InitializeOnNetworkSequence() has completed. |
307 bool is_initialized_; | 345 bool is_initialized_; |
308 | 346 |
309 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 347 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
310 | 348 |
311 // Used to post |prefs::kHttpServerProperties| pref update tasks. | 349 // Used to post |prefs::kHttpServerProperties| pref update tasks. |
312 std::unique_ptr<base::OneShotTimer> network_prefs_update_timer_; | 350 std::unique_ptr<base::OneShotTimer> network_prefs_update_timer_; |
313 | 351 |
314 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties_impl_; | 352 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties_impl_; |
315 | 353 |
316 // Used to get |weak_ptr_| to self on the pref thread. | 354 // Used to get |weak_ptr_| to self on the pref thread. |
317 std::unique_ptr<base::WeakPtrFactory<HttpServerPropertiesManager>> | 355 std::unique_ptr<base::WeakPtrFactory<HttpServerPropertiesManager>> |
318 pref_weak_ptr_factory_; | 356 pref_weak_ptr_factory_; |
319 | 357 |
320 // Used to get |weak_ptr_| to self on the network thread. | 358 // Used to get |weak_ptr_| to self on the network thread. |
321 std::unique_ptr<base::WeakPtrFactory<HttpServerPropertiesManager>> | 359 std::unique_ptr<base::WeakPtrFactory<HttpServerPropertiesManager>> |
322 network_weak_ptr_factory_; | 360 network_weak_ptr_factory_; |
323 | 361 |
324 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager); | 362 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManager); |
325 }; | 363 }; |
326 | 364 |
327 } // namespace net | 365 } // namespace net |
328 | 366 |
329 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ | 367 #endif // NET_HTTP_HTTP_SERVER_PROPERTIES_MANAGER_H_ |
OLD | NEW |