Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/browser/net/http_server_properties_manager.h" | 5 #include "chrome/browser/net/http_server_properties_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/common/chrome_version_info.h" | |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/notification_details.h" | 20 #include "content/public/browser/notification_details.h" |
| 20 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 | 24 |
| 24 namespace chrome_browser_net { | 25 namespace chrome_browser_net { |
| 25 | 26 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 84 io_weak_ptr_factory_.reset(); | 85 io_weak_ptr_factory_.reset(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void HttpServerPropertiesManager::InitializeOnIOThread() { | 88 void HttpServerPropertiesManager::InitializeOnIOThread() { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 89 io_weak_ptr_factory_.reset( | 90 io_weak_ptr_factory_.reset( |
| 90 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 91 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); |
| 91 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl()); | 92 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl()); |
| 92 | 93 |
| 94 std::string client_version; | |
| 95 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
| 96 switch (channel) { | |
| 97 case chrome::VersionInfo::CHANNEL_CANARY: | |
| 98 client_version = "C "; | |
|
ramant (doing other things)
2014/06/04 21:30:36
Should we define an enum vs the first letter of ch
Ryan Hamilton
2014/06/04 22:31:15
We could. On the other hand, the CHLO packet is pa
ramant (doing other things)
2014/06/05 02:51:55
Done.
| |
| 99 break; | |
| 100 case chrome::VersionInfo::CHANNEL_DEV: | |
| 101 client_version = "D "; | |
| 102 break; | |
| 103 case chrome::VersionInfo::CHANNEL_BETA: | |
| 104 client_version = "B "; | |
| 105 break; | |
| 106 case chrome::VersionInfo::CHANNEL_STABLE: | |
| 107 client_version = "S "; | |
| 108 break; | |
| 109 default: | |
| 110 client_version = "U "; | |
| 111 } | |
| 112 chrome::VersionInfo version_info; | |
| 113 client_version.append(version_info.Version()); | |
|
Ryan Hamilton
2014/06/04 22:31:15
This doesn't include Chrome, right? It's just 37.0
ramant (doing other things)
2014/06/05 02:51:55
Done.
| |
| 114 SetClientVersion(client_version); | |
| 115 | |
| 93 io_prefs_update_timer_.reset( | 116 io_prefs_update_timer_.reset( |
| 94 new base::OneShotTimer<HttpServerPropertiesManager>); | 117 new base::OneShotTimer<HttpServerPropertiesManager>); |
| 95 | 118 |
| 96 BrowserThread::PostTask( | 119 BrowserThread::PostTask( |
| 97 BrowserThread::UI, | 120 BrowserThread::UI, |
| 98 FROM_HERE, | 121 FROM_HERE, |
| 99 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI, | 122 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnUI, |
| 100 ui_weak_ptr_)); | 123 ui_weak_ptr_)); |
| 101 } | 124 } |
| 102 | 125 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 | 285 |
| 263 const net::SpdySettingsMap& | 286 const net::SpdySettingsMap& |
| 264 HttpServerPropertiesManager::spdy_settings_map() const { | 287 HttpServerPropertiesManager::spdy_settings_map() const { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 266 return http_server_properties_impl_->spdy_settings_map(); | 289 return http_server_properties_impl_->spdy_settings_map(); |
| 267 } | 290 } |
| 268 | 291 |
| 269 void HttpServerPropertiesManager::SetServerNetworkStats( | 292 void HttpServerPropertiesManager::SetServerNetworkStats( |
| 270 const net::HostPortPair& host_port_pair, | 293 const net::HostPortPair& host_port_pair, |
| 271 NetworkStats stats) { | 294 NetworkStats stats) { |
| 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 272 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | 296 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); |
| 273 } | 297 } |
| 274 | 298 |
| 275 const HttpServerPropertiesManager::NetworkStats* | 299 const HttpServerPropertiesManager::NetworkStats* |
| 276 HttpServerPropertiesManager::GetServerNetworkStats( | 300 HttpServerPropertiesManager::GetServerNetworkStats( |
| 277 const net::HostPortPair& host_port_pair) const { | 301 const net::HostPortPair& host_port_pair) const { |
| 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 278 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | 303 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); |
| 279 } | 304 } |
| 280 | 305 |
| 306 void HttpServerPropertiesManager::SetClientVersion( | |
| 307 const std::string& client_version) { | |
| 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 309 http_server_properties_impl_->SetClientVersion(client_version); | |
| 310 } | |
| 311 | |
| 312 const std::string HttpServerPropertiesManager::GetClientVersion() const { | |
| 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 314 return http_server_properties_impl_->GetClientVersion(); | |
| 315 } | |
| 316 | |
| 281 // | 317 // |
| 282 // Update the HttpServerPropertiesImpl's cache with data from preferences. | 318 // Update the HttpServerPropertiesImpl's cache with data from preferences. |
| 283 // | 319 // |
| 284 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() { | 320 void HttpServerPropertiesManager::ScheduleUpdateCacheOnUI() { |
| 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 286 // Cancel pending updates, if any. | 322 // Cancel pending updates, if any. |
| 287 ui_cache_update_timer_->Stop(); | 323 ui_cache_update_timer_->Stop(); |
| 288 StartCacheUpdateTimerOnUI( | 324 StartCacheUpdateTimerOnUI( |
| 289 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); | 325 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); |
| 290 } | 326 } |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 completion.Run(); | 751 completion.Run(); |
| 716 } | 752 } |
| 717 | 753 |
| 718 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 754 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 755 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 720 if (!setting_prefs_) | 756 if (!setting_prefs_) |
| 721 ScheduleUpdateCacheOnUI(); | 757 ScheduleUpdateCacheOnUI(); |
| 722 } | 758 } |
| 723 | 759 |
| 724 } // namespace chrome_browser_net | 760 } // namespace chrome_browser_net |
| OLD | NEW |