OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile_impl_io_data.h" | 5 #include "chrome/browser/profiles/profile_impl_io_data.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
13 #include "chrome/browser/net/chrome_net_log.h" | 13 #include "chrome/browser/net/chrome_net_log.h" |
14 #include "chrome/browser/net/chrome_network_delegate.h" | 14 #include "chrome/browser/net/chrome_network_delegate.h" |
15 #include "chrome/browser/net/connect_interceptor.h" | 15 #include "chrome/browser/net/connect_interceptor.h" |
| 16 #include "chrome/browser/net/http_server_properties_manager.h" |
16 #include "chrome/browser/net/predictor.h" | 17 #include "chrome/browser/net/predictor.h" |
17 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h" | 18 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h" |
18 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 19 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
19 #include "chrome/browser/prefs/pref_member.h" | 20 #include "chrome/browser/prefs/pref_member.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "content/browser/browser_thread.h" | 26 #include "content/browser/browser_thread.h" |
26 #include "content/browser/resource_context.h" | 27 #include "content/browser/resource_context.h" |
27 #include "net/base/origin_bound_cert_service.h" | 28 #include "net/base/origin_bound_cert_service.h" |
28 #include "net/ftp/ftp_network_layer.h" | 29 #include "net/ftp/ftp_network_layer.h" |
29 #include "net/http/http_cache.h" | 30 #include "net/http/http_cache.h" |
30 #include "net/url_request/url_request_job_factory.h" | 31 #include "net/url_request/url_request_job_factory.h" |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 void DeleteTransportSecurityStateSinceOnIOThread( | 35 void ClearNetworkingHistorySinceOnIOThread( |
35 ProfileImplIOData* io_data, base::Time time) { | 36 ProfileImplIOData* io_data, base::Time time) { |
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
37 io_data->transport_security_state()->DeleteSince(time); | 38 io_data->transport_security_state()->DeleteSince(time); |
| 39 io_data->http_server_properties()->DeleteAll(); |
38 } | 40 } |
39 | 41 |
40 } // namespace | 42 } // namespace |
41 | 43 |
42 ProfileImplIOData::Handle::Handle(Profile* profile) | 44 ProfileImplIOData::Handle::Handle(Profile* profile) |
43 : io_data_(new ProfileImplIOData), | 45 : io_data_(new ProfileImplIOData), |
44 profile_(profile), | 46 profile_(profile), |
45 initialized_(false) { | 47 initialized_(false) { |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
47 DCHECK(profile); | 49 DCHECK(profile); |
(...skipping 16 matching lines...) Expand all Loading... |
64 } | 66 } |
65 | 67 |
66 // Clean up all isolated app request contexts. | 68 // Clean up all isolated app request contexts. |
67 for (ChromeURLRequestContextGetterMap::iterator iter = | 69 for (ChromeURLRequestContextGetterMap::iterator iter = |
68 app_request_context_getter_map_.begin(); | 70 app_request_context_getter_map_.begin(); |
69 iter != app_request_context_getter_map_.end(); | 71 iter != app_request_context_getter_map_.end(); |
70 ++iter) { | 72 ++iter) { |
71 iter->second->CleanupOnUIThread(); | 73 iter->second->CleanupOnUIThread(); |
72 } | 74 } |
73 | 75 |
| 76 if (io_data_->http_server_properties_manager_.get()) |
| 77 io_data_->http_server_properties_manager_->ShutdownOnUIThread(); |
74 io_data_->ShutdownOnUIThread(); | 78 io_data_->ShutdownOnUIThread(); |
75 } | 79 } |
76 | 80 |
77 void ProfileImplIOData::Handle::Init( | 81 void ProfileImplIOData::Handle::Init( |
78 const FilePath& cookie_path, | 82 const FilePath& cookie_path, |
79 const FilePath& origin_bound_cert_path, | 83 const FilePath& origin_bound_cert_path, |
80 const FilePath& cache_path, | 84 const FilePath& cache_path, |
81 int cache_max_size, | 85 int cache_max_size, |
82 const FilePath& media_cache_path, | 86 const FilePath& media_cache_path, |
83 int media_cache_max_size, | 87 int media_cache_max_size, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 183 |
180 | 184 |
181 ChromeURLRequestContextGetter* context = | 185 ChromeURLRequestContextGetter* context = |
182 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 186 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
183 profile_, io_data_, app_id); | 187 profile_, io_data_, app_id); |
184 app_request_context_getter_map_[app_id] = context; | 188 app_request_context_getter_map_[app_id] = context; |
185 | 189 |
186 return context; | 190 return context; |
187 } | 191 } |
188 | 192 |
189 void ProfileImplIOData::Handle::DeleteTransportSecurityStateSince( | 193 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( |
190 base::Time time) { | 194 base::Time time) { |
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
192 LazyInitialize(); | 196 LazyInitialize(); |
193 | 197 |
194 BrowserThread::PostTask( | 198 BrowserThread::PostTask( |
195 BrowserThread::IO, FROM_HERE, | 199 BrowserThread::IO, FROM_HERE, |
196 base::Bind( | 200 base::Bind( |
197 &DeleteTransportSecurityStateSinceOnIOThread, | 201 &ClearNetworkingHistorySinceOnIOThread, |
198 io_data_, | 202 io_data_, |
199 time)); | 203 time)); |
200 } | 204 } |
201 | 205 |
202 void ProfileImplIOData::Handle::LazyInitialize() const { | 206 void ProfileImplIOData::Handle::LazyInitialize() const { |
203 if (!initialized_) { | 207 if (!initialized_) { |
204 io_data_->InitializeOnUIThread(profile_); | 208 io_data_->InitializeOnUIThread(profile_); |
| 209 PrefService* pref_service = profile_->GetPrefs(); |
| 210 io_data_->http_server_properties_manager_.reset( |
| 211 new chrome_browser_net::HttpServerPropertiesManager(pref_service)); |
205 ChromeNetworkDelegate::InitializeReferrersEnabled( | 212 ChromeNetworkDelegate::InitializeReferrersEnabled( |
206 io_data_->enable_referrers(), profile_->GetPrefs()); | 213 io_data_->enable_referrers(), pref_service); |
207 io_data_->clear_local_state_on_exit()->Init( | 214 io_data_->clear_local_state_on_exit()->Init( |
208 prefs::kClearSiteDataOnExit, profile_->GetPrefs(), NULL); | 215 prefs::kClearSiteDataOnExit, pref_service, NULL); |
209 io_data_->clear_local_state_on_exit()->MoveToThread(BrowserThread::IO); | 216 io_data_->clear_local_state_on_exit()->MoveToThread(BrowserThread::IO); |
210 #if defined(ENABLE_SAFE_BROWSING) | 217 #if defined(ENABLE_SAFE_BROWSING) |
211 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, | 218 io_data_->safe_browsing_enabled()->Init(prefs::kSafeBrowsingEnabled, |
212 profile_->GetPrefs(), NULL); | 219 pref_service, NULL); |
213 io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO); | 220 io_data_->safe_browsing_enabled()->MoveToThread(BrowserThread::IO); |
214 #endif | 221 #endif |
215 initialized_ = true; | 222 initialized_ = true; |
216 } | 223 } |
217 } | 224 } |
218 | 225 |
219 ProfileImplIOData::LazyParams::LazyParams() | 226 ProfileImplIOData::LazyParams::LazyParams() |
220 : cache_max_size(0), | 227 : cache_max_size(0), |
221 media_cache_max_size(0) {} | 228 media_cache_max_size(0) {} |
222 ProfileImplIOData::LazyParams::~LazyParams() {} | 229 ProfileImplIOData::LazyParams::~LazyParams() {} |
(...skipping 18 matching lines...) Expand all Loading... |
241 bool record_mode = chrome::kRecordModeEnabled && | 248 bool record_mode = chrome::kRecordModeEnabled && |
242 command_line.HasSwitch(switches::kRecordMode); | 249 command_line.HasSwitch(switches::kRecordMode); |
243 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 250 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
244 | 251 |
245 // Initialize context members. | 252 // Initialize context members. |
246 | 253 |
247 ApplyProfileParamsToContext(main_context); | 254 ApplyProfileParamsToContext(main_context); |
248 ApplyProfileParamsToContext(media_request_context_); | 255 ApplyProfileParamsToContext(media_request_context_); |
249 ApplyProfileParamsToContext(extensions_context); | 256 ApplyProfileParamsToContext(extensions_context); |
250 | 257 |
| 258 if (http_server_properties_manager_.get()) |
| 259 http_server_properties_manager_->InitializeOnIOThread(); |
| 260 |
251 main_context->set_transport_security_state(transport_security_state()); | 261 main_context->set_transport_security_state(transport_security_state()); |
252 media_request_context_->set_transport_security_state( | 262 media_request_context_->set_transport_security_state( |
253 transport_security_state()); | 263 transport_security_state()); |
254 extensions_context->set_transport_security_state(transport_security_state()); | 264 extensions_context->set_transport_security_state(transport_security_state()); |
255 | 265 |
256 main_context->set_net_log(io_thread->net_log()); | 266 main_context->set_net_log(io_thread->net_log()); |
257 media_request_context_->set_net_log(io_thread->net_log()); | 267 media_request_context_->set_net_log(io_thread->net_log()); |
258 extensions_context->set_net_log(io_thread->net_log()); | 268 extensions_context->set_net_log(io_thread->net_log()); |
259 | 269 |
260 main_context->set_network_delegate(network_delegate()); | 270 main_context->set_network_delegate(network_delegate()); |
261 media_request_context_->set_network_delegate(network_delegate()); | 271 media_request_context_->set_network_delegate(network_delegate()); |
262 | 272 |
| 273 main_context->set_http_server_properties(http_server_properties()); |
| 274 media_request_context_->set_http_server_properties(http_server_properties()); |
| 275 |
263 main_context->set_host_resolver( | 276 main_context->set_host_resolver( |
264 io_thread_globals->host_resolver.get()); | 277 io_thread_globals->host_resolver.get()); |
265 media_request_context_->set_host_resolver( | 278 media_request_context_->set_host_resolver( |
266 io_thread_globals->host_resolver.get()); | 279 io_thread_globals->host_resolver.get()); |
267 main_context->set_cert_verifier( | 280 main_context->set_cert_verifier( |
268 io_thread_globals->cert_verifier.get()); | 281 io_thread_globals->cert_verifier.get()); |
269 media_request_context_->set_cert_verifier( | 282 media_request_context_->set_cert_verifier( |
270 io_thread_globals->cert_verifier.get()); | 283 io_thread_globals->cert_verifier.get()); |
271 main_context->set_dnsrr_resolver( | 284 main_context->set_dnsrr_resolver( |
272 io_thread_globals->dnsrr_resolver.get()); | 285 io_thread_globals->dnsrr_resolver.get()); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 net::HttpCache* main_cache = new net::HttpCache( | 359 net::HttpCache* main_cache = new net::HttpCache( |
347 main_context->host_resolver(), | 360 main_context->host_resolver(), |
348 main_context->cert_verifier(), | 361 main_context->cert_verifier(), |
349 main_context->origin_bound_cert_service(), | 362 main_context->origin_bound_cert_service(), |
350 main_context->dnsrr_resolver(), | 363 main_context->dnsrr_resolver(), |
351 main_context->dns_cert_checker(), | 364 main_context->dns_cert_checker(), |
352 main_context->proxy_service(), | 365 main_context->proxy_service(), |
353 main_context->ssl_config_service(), | 366 main_context->ssl_config_service(), |
354 main_context->http_auth_handler_factory(), | 367 main_context->http_auth_handler_factory(), |
355 main_context->network_delegate(), | 368 main_context->network_delegate(), |
| 369 main_context->http_server_properties(), |
356 main_context->net_log(), | 370 main_context->net_log(), |
357 main_backend); | 371 main_backend); |
358 | 372 |
359 net::HttpCache::DefaultBackend* media_backend = | 373 net::HttpCache::DefaultBackend* media_backend = |
360 new net::HttpCache::DefaultBackend( | 374 new net::HttpCache::DefaultBackend( |
361 net::MEDIA_CACHE, lazy_params_->media_cache_path, | 375 net::MEDIA_CACHE, lazy_params_->media_cache_path, |
362 lazy_params_->media_cache_max_size, | 376 lazy_params_->media_cache_max_size, |
363 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 377 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
364 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); | 378 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); |
365 net::HttpCache* media_cache = | 379 net::HttpCache* media_cache = |
(...skipping 18 matching lines...) Expand all Loading... |
384 main_context->set_job_factory(job_factory()); | 398 main_context->set_job_factory(job_factory()); |
385 media_request_context_->set_job_factory(job_factory()); | 399 media_request_context_->set_job_factory(job_factory()); |
386 extensions_context->set_job_factory(job_factory()); | 400 extensions_context->set_job_factory(job_factory()); |
387 | 401 |
388 job_factory()->AddInterceptor( | 402 job_factory()->AddInterceptor( |
389 new chrome_browser_net::ConnectInterceptor(predictor_.get())); | 403 new chrome_browser_net::ConnectInterceptor(predictor_.get())); |
390 | 404 |
391 lazy_params_.reset(); | 405 lazy_params_.reset(); |
392 } | 406 } |
393 | 407 |
| 408 net::HttpServerProperties* ProfileImplIOData::http_server_properties() const { |
| 409 return http_server_properties_manager_.get(); |
| 410 } |
| 411 |
394 scoped_refptr<ChromeURLRequestContext> | 412 scoped_refptr<ChromeURLRequestContext> |
395 ProfileImplIOData::InitializeAppRequestContext( | 413 ProfileImplIOData::InitializeAppRequestContext( |
396 scoped_refptr<ChromeURLRequestContext> main_context, | 414 scoped_refptr<ChromeURLRequestContext> main_context, |
397 const std::string& app_id) const { | 415 const std::string& app_id) const { |
398 AppRequestContext* context = new AppRequestContext; | 416 AppRequestContext* context = new AppRequestContext; |
399 | 417 |
400 // Copy most state from the main context. | 418 // Copy most state from the main context. |
401 context->CopyFrom(main_context); | 419 context->CopyFrom(main_context); |
402 | 420 |
403 FilePath app_path = app_path_.AppendASCII(app_id); | 421 FilePath app_path = app_path_.AppendASCII(app_id); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 scoped_refptr<ChromeURLRequestContext> | 480 scoped_refptr<ChromeURLRequestContext> |
463 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 481 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
464 scoped_refptr<ChromeURLRequestContext> main_context, | 482 scoped_refptr<ChromeURLRequestContext> main_context, |
465 const std::string& app_id) const { | 483 const std::string& app_id) const { |
466 // We create per-app contexts on demand, unlike the others above. | 484 // We create per-app contexts on demand, unlike the others above. |
467 scoped_refptr<ChromeURLRequestContext> app_request_context = | 485 scoped_refptr<ChromeURLRequestContext> app_request_context = |
468 InitializeAppRequestContext(main_context, app_id); | 486 InitializeAppRequestContext(main_context, app_id); |
469 DCHECK(app_request_context); | 487 DCHECK(app_request_context); |
470 return app_request_context; | 488 return app_request_context; |
471 } | 489 } |
OLD | NEW |