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 #include "net/http/http_server_properties_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 const char kUsedQuicKey[] = "used_quic"; | 58 const char kUsedQuicKey[] = "used_quic"; |
59 const char kAddressKey[] = "address"; | 59 const char kAddressKey[] = "address"; |
60 const char kAlternativeServiceKey[] = "alternative_service"; | 60 const char kAlternativeServiceKey[] = "alternative_service"; |
61 const char kProtocolKey[] = "protocol_str"; | 61 const char kProtocolKey[] = "protocol_str"; |
62 const char kHostKey[] = "host"; | 62 const char kHostKey[] = "host"; |
63 const char kPortKey[] = "port"; | 63 const char kPortKey[] = "port"; |
64 const char kExpirationKey[] = "expiration"; | 64 const char kExpirationKey[] = "expiration"; |
65 const char kNetworkStatsKey[] = "network_stats"; | 65 const char kNetworkStatsKey[] = "network_stats"; |
66 const char kSrttKey[] = "srtt"; | 66 const char kSrttKey[] = "srtt"; |
67 | 67 |
| 68 std::unique_ptr<base::Value> NetLogCallback( |
| 69 const base::DictionaryValue& http_server_properties_dict, |
| 70 NetLogCaptureMode capture_mode) { |
| 71 return base::WrapUnique<base::DictionaryValue>( |
| 72 http_server_properties_dict.DeepCopy()); |
| 73 } |
| 74 |
68 } // namespace | 75 } // namespace |
69 | 76 |
70 //////////////////////////////////////////////////////////////////////////////// | 77 //////////////////////////////////////////////////////////////////////////////// |
71 // HttpServerPropertiesManager | 78 // HttpServerPropertiesManager |
72 | 79 |
73 HttpServerPropertiesManager::PrefDelegate::~PrefDelegate() {} | 80 HttpServerPropertiesManager::PrefDelegate::~PrefDelegate() {} |
74 | 81 |
75 HttpServerPropertiesManager::HttpServerPropertiesManager( | 82 HttpServerPropertiesManager::HttpServerPropertiesManager( |
76 PrefDelegate* pref_delegate, | 83 PrefDelegate* pref_delegate, |
77 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, | 84 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, |
78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) | 85 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 86 NetLog* net_log) |
79 : pref_task_runner_(std::move(pref_task_runner)), | 87 : pref_task_runner_(std::move(pref_task_runner)), |
80 pref_delegate_(pref_delegate), | 88 pref_delegate_(pref_delegate), |
81 setting_prefs_(false), | 89 setting_prefs_(false), |
82 is_initialized_(false), | 90 is_initialized_(false), |
83 network_task_runner_(std::move(network_task_runner)) { | 91 network_task_runner_(std::move(network_task_runner)), |
| 92 net_log_( |
| 93 NetLogWithSource::Make(net_log, |
| 94 NetLogSourceType::HTTP_SERVER_PROPERTIES)) { |
84 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence()); | 95 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence()); |
85 DCHECK(pref_delegate_); | 96 DCHECK(pref_delegate_); |
86 pref_weak_ptr_factory_.reset( | 97 pref_weak_ptr_factory_.reset( |
87 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 98 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); |
88 pref_weak_ptr_ = pref_weak_ptr_factory_->GetWeakPtr(); | 99 pref_weak_ptr_ = pref_weak_ptr_factory_->GetWeakPtr(); |
89 pref_cache_update_timer_.reset(new base::OneShotTimer); | 100 pref_cache_update_timer_.reset(new base::OneShotTimer); |
90 pref_cache_update_timer_->SetTaskRunner(pref_task_runner_); | 101 pref_cache_update_timer_->SetTaskRunner(pref_task_runner_); |
91 pref_delegate_->StartListeningForUpdates( | 102 pref_delegate_->StartListeningForUpdates( |
92 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, | 103 base::Bind(&HttpServerPropertiesManager::OnHttpServerPropertiesChanged, |
93 base::Unretained(this))); | 104 base::Unretained(this))); |
94 } | 105 } |
95 | 106 |
96 HttpServerPropertiesManager::~HttpServerPropertiesManager() { | 107 HttpServerPropertiesManager::~HttpServerPropertiesManager() { |
97 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); | 108 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
98 network_weak_ptr_factory_.reset(); | 109 network_weak_ptr_factory_.reset(); |
99 } | 110 } |
100 | 111 |
101 void HttpServerPropertiesManager::InitializeOnNetworkSequence() { | 112 void HttpServerPropertiesManager::InitializeOnNetworkSequence() { |
102 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); | 113 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
| 114 net_log_.BeginEvent(NetLogEventType::HTTP_SERVER_PROPERTIES_INITIALIZATION); |
103 | 115 |
104 network_weak_ptr_factory_.reset( | 116 network_weak_ptr_factory_.reset( |
105 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 117 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); |
106 http_server_properties_impl_.reset(new HttpServerPropertiesImpl()); | 118 http_server_properties_impl_.reset(new HttpServerPropertiesImpl()); |
107 | 119 |
108 network_prefs_update_timer_.reset(new base::OneShotTimer); | 120 network_prefs_update_timer_.reset(new base::OneShotTimer); |
109 network_prefs_update_timer_->SetTaskRunner(network_task_runner_); | 121 network_prefs_update_timer_->SetTaskRunner(network_task_runner_); |
110 // UpdateCacheFromPrefsOnPrefSequence() will post a task to network thread to | 122 // UpdateCacheFromPrefsOnPrefSequence() will post a task to network thread to |
111 // update server properties. SetInitialized() will be run after that task is | 123 // update server properties. SetInitialized() will be run after that task is |
112 // run as |network_task_runner_| is single threaded. | 124 // run as |network_task_runner_| is single threaded. |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 // The preferences can only be read on the pref thread. | 420 // The preferences can only be read on the pref thread. |
409 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence()); | 421 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence()); |
410 | 422 |
411 if (!pref_delegate_->HasServerProperties()) | 423 if (!pref_delegate_->HasServerProperties()) |
412 return; | 424 return; |
413 | 425 |
414 bool detected_corrupted_prefs = false; | 426 bool detected_corrupted_prefs = false; |
415 const base::DictionaryValue& http_server_properties_dict = | 427 const base::DictionaryValue& http_server_properties_dict = |
416 pref_delegate_->GetServerProperties(); | 428 pref_delegate_->GetServerProperties(); |
417 | 429 |
| 430 net_log_.AddEvent(NetLogEventType::HTTP_SERVER_PROPERTIES_UPDATE_CACHE, |
| 431 base::Bind(&NetLogCallback, http_server_properties_dict)); |
418 int version = kMissingVersion; | 432 int version = kMissingVersion; |
419 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(kVersionKey, | 433 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(kVersionKey, |
420 &version)) { | 434 &version)) { |
421 DVLOG(1) << "Missing version. Clearing all properties."; | 435 DVLOG(1) << "Missing version. Clearing all properties."; |
422 return; | 436 return; |
423 } | 437 } |
424 | 438 |
425 const base::DictionaryValue* servers_dict = nullptr; | 439 const base::DictionaryValue* servers_dict = nullptr; |
426 const base::ListValue* servers_list = nullptr; | 440 const base::ListValue* servers_list = nullptr; |
427 if (version < 4) { | 441 if (version < 4) { |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 | 1059 |
1046 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict); | 1060 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict); |
1047 | 1061 |
1048 SaveQuicServerInfoMapToServerPrefs(quic_server_info_map, | 1062 SaveQuicServerInfoMapToServerPrefs(quic_server_info_map, |
1049 &http_server_properties_dict); | 1063 &http_server_properties_dict); |
1050 | 1064 |
1051 setting_prefs_ = true; | 1065 setting_prefs_ = true; |
1052 pref_delegate_->SetServerProperties(http_server_properties_dict); | 1066 pref_delegate_->SetServerProperties(http_server_properties_dict); |
1053 setting_prefs_ = false; | 1067 setting_prefs_ = false; |
1054 | 1068 |
| 1069 net_log_.AddEvent(NetLogEventType::HTTP_SERVER_PROPERTIES_UPDATE_PREFS, |
| 1070 base::Bind(&NetLogCallback, http_server_properties_dict)); |
1055 // Note that |completion| will be fired after we have written everything to | 1071 // Note that |completion| will be fired after we have written everything to |
1056 // the Preferences, but likely before these changes are serialized to disk. | 1072 // the Preferences, but likely before these changes are serialized to disk. |
1057 // This is not a problem though, as JSONPrefStore guarantees that this will | 1073 // This is not a problem though, as JSONPrefStore guarantees that this will |
1058 // happen, pretty soon, and even in the case we shut down immediately. | 1074 // happen, pretty soon, and even in the case we shut down immediately. |
1059 if (!completion.is_null()) | 1075 if (!completion.is_null()) |
1060 completion.Run(); | 1076 completion.Run(); |
1061 } | 1077 } |
1062 | 1078 |
1063 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( | 1079 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( |
1064 const AlternativeServiceInfoVector* alternative_service_info_vector, | 1080 const AlternativeServiceInfoVector* alternative_service_info_vector, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 | 1162 |
1147 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 1163 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
1148 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence()); | 1164 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence()); |
1149 if (!setting_prefs_) | 1165 if (!setting_prefs_) |
1150 ScheduleUpdateCacheOnPrefThread(); | 1166 ScheduleUpdateCacheOnPrefThread(); |
1151 } | 1167 } |
1152 | 1168 |
1153 void HttpServerPropertiesManager::SetInitialized() { | 1169 void HttpServerPropertiesManager::SetInitialized() { |
1154 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); | 1170 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
1155 is_initialized_ = true; | 1171 is_initialized_ = true; |
| 1172 net_log_.EndEvent(NetLogEventType::HTTP_SERVER_PROPERTIES_INITIALIZATION); |
1156 } | 1173 } |
1157 | 1174 |
1158 } // namespace net | 1175 } // namespace net |
OLD | NEW |