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