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/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" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 } | 63 } |
64 | 64 |
65 // Clean up all isolated app request contexts. | 65 // Clean up all isolated app request contexts. |
66 for (ChromeURLRequestContextGetterMap::iterator iter = | 66 for (ChromeURLRequestContextGetterMap::iterator iter = |
67 app_request_context_getter_map_.begin(); | 67 app_request_context_getter_map_.begin(); |
68 iter != app_request_context_getter_map_.end(); | 68 iter != app_request_context_getter_map_.end(); |
69 ++iter) { | 69 ++iter) { |
70 iter->second->CleanupOnUIThread(); | 70 iter->second->CleanupOnUIThread(); |
71 } | 71 } |
72 | 72 |
73 // Clean up all isolated media request contexts. | |
74 for (ChromeURLRequestContextGetterMap::iterator iter = | |
75 isolated_media_request_context_getter_map_.begin(); | |
76 iter != isolated_media_request_context_getter_map_.end(); | |
77 ++iter) { | |
78 iter->second->CleanupOnUIThread(); | |
79 } | |
80 | |
73 if (io_data_->http_server_properties_manager()) | 81 if (io_data_->http_server_properties_manager()) |
74 io_data_->http_server_properties_manager()->ShutdownOnUIThread(); | 82 io_data_->http_server_properties_manager()->ShutdownOnUIThread(); |
75 io_data_->ShutdownOnUIThread(); | 83 io_data_->ShutdownOnUIThread(); |
76 } | 84 } |
77 | 85 |
78 void ProfileImplIOData::Handle::Init( | 86 void ProfileImplIOData::Handle::Init( |
79 const FilePath& cookie_path, | 87 const FilePath& cookie_path, |
80 const FilePath& server_bound_cert_path, | 88 const FilePath& server_bound_cert_path, |
81 const FilePath& cache_path, | 89 const FilePath& cache_path, |
82 int cache_max_size, | 90 int cache_max_size, |
(...skipping 17 matching lines...) Expand all Loading... | |
100 lazy_params->cache_path = cache_path; | 108 lazy_params->cache_path = cache_path; |
101 lazy_params->cache_max_size = cache_max_size; | 109 lazy_params->cache_max_size = cache_max_size; |
102 lazy_params->media_cache_path = media_cache_path; | 110 lazy_params->media_cache_path = media_cache_path; |
103 lazy_params->media_cache_max_size = media_cache_max_size; | 111 lazy_params->media_cache_max_size = media_cache_max_size; |
104 lazy_params->extensions_cookie_path = extensions_cookie_path; | 112 lazy_params->extensions_cookie_path = extensions_cookie_path; |
105 lazy_params->restore_old_session_cookies = restore_old_session_cookies; | 113 lazy_params->restore_old_session_cookies = restore_old_session_cookies; |
106 lazy_params->special_storage_policy = special_storage_policy; | 114 lazy_params->special_storage_policy = special_storage_policy; |
107 | 115 |
108 io_data_->lazy_params_.reset(lazy_params); | 116 io_data_->lazy_params_.reset(lazy_params); |
109 | 117 |
110 // Keep track of isolated app path separately so we can use it on demand. | 118 // Keep track of isolated app path and cache sizes separately so we can use |
119 // them on demand. | |
111 io_data_->app_path_ = app_path; | 120 io_data_->app_path_ = app_path; |
121 io_data_->app_cache_max_size_ = cache_max_size; | |
122 io_data_->app_media_cache_max_size_ = media_cache_max_size; | |
112 | 123 |
113 io_data_->predictor_.reset(predictor); | 124 io_data_->predictor_.reset(predictor); |
114 | 125 |
115 if (!main_request_context_getter_) { | 126 if (!main_request_context_getter_) { |
116 main_request_context_getter_ = | 127 main_request_context_getter_ = |
117 ChromeURLRequestContextGetter::CreateOriginal( | 128 ChromeURLRequestContextGetter::CreateOriginal( |
118 profile_, io_data_); | 129 profile_, io_data_); |
119 } | 130 } |
120 io_data_->predictor_->InitNetworkPredictor(profile_->GetPrefs(), | 131 io_data_->predictor_->InitNetworkPredictor(profile_->GetPrefs(), |
121 local_state, | 132 local_state, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 ChromeURLRequestContextGetter::CreateOriginalForExtensions( | 198 ChromeURLRequestContextGetter::CreateOriginalForExtensions( |
188 profile_, io_data_); | 199 profile_, io_data_); |
189 } | 200 } |
190 return extensions_request_context_getter_; | 201 return extensions_request_context_getter_; |
191 } | 202 } |
192 | 203 |
193 scoped_refptr<ChromeURLRequestContextGetter> | 204 scoped_refptr<ChromeURLRequestContextGetter> |
194 ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter( | 205 ProfileImplIOData::Handle::GetIsolatedAppRequestContextGetter( |
195 const std::string& app_id) const { | 206 const std::string& app_id) const { |
196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
197 DCHECK(!app_id.empty()); | 208 CHECK(!app_id.empty()); |
198 LazyInitialize(); | 209 LazyInitialize(); |
199 | 210 |
200 // Keep a map of request context getters, one per requested app ID. | 211 // Keep a map of request context getters, one per requested app ID. |
201 ChromeURLRequestContextGetterMap::iterator iter = | 212 ChromeURLRequestContextGetterMap::iterator iter = |
202 app_request_context_getter_map_.find(app_id); | 213 app_request_context_getter_map_.find(app_id); |
203 if (iter != app_request_context_getter_map_.end()) | 214 if (iter != app_request_context_getter_map_.end()) |
204 return iter->second; | 215 return iter->second; |
205 | 216 |
206 ChromeURLRequestContextGetter* context = | 217 ChromeURLRequestContextGetter* context = |
207 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( | 218 ChromeURLRequestContextGetter::CreateOriginalForIsolatedApp( |
208 profile_, io_data_, app_id); | 219 profile_, io_data_, app_id); |
209 app_request_context_getter_map_[app_id] = context; | 220 app_request_context_getter_map_[app_id] = context; |
210 | 221 |
211 return context; | 222 return context; |
212 } | 223 } |
213 | 224 |
225 scoped_refptr<ChromeURLRequestContextGetter> | |
226 ProfileImplIOData::Handle::GetIsolatedMediaRequestContextGetter( | |
227 const std::string& app_id) const { | |
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
229 // We must have an app ID, or this will act like the default media context. | |
230 CHECK(!app_id.empty()); | |
231 LazyInitialize(); | |
232 | |
233 // Keep a map of request context getters, one per requested app ID. | |
234 ChromeURLRequestContextGetterMap::iterator iter = | |
235 isolated_media_request_context_getter_map_.find(app_id); | |
236 if (iter != isolated_media_request_context_getter_map_.end()) | |
237 return iter->second; | |
238 | |
239 ChromeURLRequestContextGetter* context = | |
240 ChromeURLRequestContextGetter::CreateOriginalForIsolatedMedia( | |
241 profile_, io_data_, app_id); | |
242 isolated_media_request_context_getter_map_[app_id] = context; | |
243 | |
244 return context; | |
245 } | |
246 | |
214 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( | 247 void ProfileImplIOData::Handle::ClearNetworkingHistorySince( |
215 base::Time time) { | 248 base::Time time) { |
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
217 LazyInitialize(); | 250 LazyInitialize(); |
218 | 251 |
219 BrowserThread::PostTask( | 252 BrowserThread::PostTask( |
220 BrowserThread::IO, FROM_HERE, | 253 BrowserThread::IO, FROM_HERE, |
221 base::Bind( | 254 base::Bind( |
222 &ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread, | 255 &ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread, |
223 base::Unretained(io_data_), | 256 base::Unretained(io_data_), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 DestroyResourceContext(); | 293 DestroyResourceContext(); |
261 | 294 |
262 if (media_request_context_.get()) | 295 if (media_request_context_.get()) |
263 media_request_context_->AssertNoURLRequests(); | 296 media_request_context_->AssertNoURLRequests(); |
264 } | 297 } |
265 | 298 |
266 void ProfileImplIOData::LazyInitializeInternal( | 299 void ProfileImplIOData::LazyInitializeInternal( |
267 ProfileParams* profile_params) const { | 300 ProfileParams* profile_params) const { |
268 ChromeURLRequestContext* main_context = main_request_context(); | 301 ChromeURLRequestContext* main_context = main_request_context(); |
269 ChromeURLRequestContext* extensions_context = extensions_request_context(); | 302 ChromeURLRequestContext* extensions_context = extensions_request_context(); |
270 media_request_context_.reset(new ChromeURLRequestContext( | |
271 ChromeURLRequestContext::CONTEXT_TYPE_MEDIA, cache_stats())); | |
272 | 303 |
273 IOThread* const io_thread = profile_params->io_thread; | 304 IOThread* const io_thread = profile_params->io_thread; |
274 IOThread::Globals* const io_thread_globals = io_thread->globals(); | 305 IOThread::Globals* const io_thread_globals = io_thread->globals(); |
275 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 306 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
276 // Only allow Record Mode if we are in a Debug build or where we are running | 307 // Only allow Record Mode if we are in a Debug build or where we are running |
277 // a cycle, and the user has limited control. | 308 // a cycle, and the user has limited control. |
278 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && | 309 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
279 (chrome::kRecordModeEnabled || | 310 (chrome::kRecordModeEnabled || |
280 command_line.HasSwitch(switches::kVisitURLs)); | 311 command_line.HasSwitch(switches::kVisitURLs)); |
281 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 312 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
282 | 313 |
283 // Initialize context members. | 314 // Initialize context members. |
284 | 315 |
285 ApplyProfileParamsToContext(main_context); | 316 ApplyProfileParamsToContext(main_context); |
286 ApplyProfileParamsToContext(media_request_context_.get()); | |
287 ApplyProfileParamsToContext(extensions_context); | 317 ApplyProfileParamsToContext(extensions_context); |
288 | 318 |
289 if (http_server_properties_manager()) | 319 if (http_server_properties_manager()) |
290 http_server_properties_manager()->InitializeOnIOThread(); | 320 http_server_properties_manager()->InitializeOnIOThread(); |
291 | 321 |
292 main_context->set_transport_security_state(transport_security_state()); | 322 main_context->set_transport_security_state(transport_security_state()); |
293 media_request_context_->set_transport_security_state( | |
294 transport_security_state()); | |
295 extensions_context->set_transport_security_state(transport_security_state()); | 323 extensions_context->set_transport_security_state(transport_security_state()); |
296 | 324 |
297 main_context->set_net_log(io_thread->net_log()); | 325 main_context->set_net_log(io_thread->net_log()); |
298 media_request_context_->set_net_log(io_thread->net_log()); | |
299 extensions_context->set_net_log(io_thread->net_log()); | 326 extensions_context->set_net_log(io_thread->net_log()); |
300 | 327 |
301 main_context->set_network_delegate(network_delegate()); | 328 main_context->set_network_delegate(network_delegate()); |
302 media_request_context_->set_network_delegate(network_delegate()); | |
303 | 329 |
304 main_context->set_http_server_properties(http_server_properties_manager()); | 330 main_context->set_http_server_properties(http_server_properties_manager()); |
305 media_request_context_->set_http_server_properties( | |
306 http_server_properties_manager()); | |
307 | 331 |
308 main_context->set_host_resolver( | 332 main_context->set_host_resolver( |
309 io_thread_globals->host_resolver.get()); | 333 io_thread_globals->host_resolver.get()); |
310 media_request_context_->set_host_resolver( | |
311 io_thread_globals->host_resolver.get()); | |
312 main_context->set_cert_verifier( | 334 main_context->set_cert_verifier( |
313 io_thread_globals->cert_verifier.get()); | 335 io_thread_globals->cert_verifier.get()); |
314 media_request_context_->set_cert_verifier( | |
315 io_thread_globals->cert_verifier.get()); | |
316 main_context->set_http_auth_handler_factory( | 336 main_context->set_http_auth_handler_factory( |
317 io_thread_globals->http_auth_handler_factory.get()); | 337 io_thread_globals->http_auth_handler_factory.get()); |
318 media_request_context_->set_http_auth_handler_factory( | |
319 io_thread_globals->http_auth_handler_factory.get()); | |
320 | 338 |
321 main_context->set_fraudulent_certificate_reporter( | 339 main_context->set_fraudulent_certificate_reporter( |
322 fraudulent_certificate_reporter()); | 340 fraudulent_certificate_reporter()); |
323 media_request_context_->set_fraudulent_certificate_reporter( | |
324 fraudulent_certificate_reporter()); | |
325 | 341 |
326 main_context->set_throttler_manager( | 342 main_context->set_throttler_manager( |
327 io_thread_globals->throttler_manager.get()); | 343 io_thread_globals->throttler_manager.get()); |
328 media_request_context_->set_throttler_manager( | |
329 io_thread_globals->throttler_manager.get()); | |
330 extensions_context->set_throttler_manager( | 344 extensions_context->set_throttler_manager( |
331 io_thread_globals->throttler_manager.get()); | 345 io_thread_globals->throttler_manager.get()); |
332 | 346 |
333 main_context->set_proxy_service(proxy_service()); | 347 main_context->set_proxy_service(proxy_service()); |
334 media_request_context_->set_proxy_service(proxy_service()); | |
335 | 348 |
336 scoped_refptr<net::CookieStore> cookie_store = NULL; | 349 scoped_refptr<net::CookieStore> cookie_store = NULL; |
337 net::ServerBoundCertService* server_bound_cert_service = NULL; | 350 net::ServerBoundCertService* server_bound_cert_service = NULL; |
338 if (record_mode || playback_mode) { | 351 if (record_mode || playback_mode) { |
339 // Don't use existing cookies and use an in-memory store. | 352 // Don't use existing cookies and use an in-memory store. |
340 cookie_store = new net::CookieMonster( | 353 cookie_store = new net::CookieMonster( |
341 NULL, profile_params->cookie_monster_delegate); | 354 NULL, profile_params->cookie_monster_delegate); |
342 // Don't use existing server-bound certs and use an in-memory store. | 355 // Don't use existing server-bound certs and use an in-memory store. |
343 server_bound_cert_service = new net::ServerBoundCertService( | 356 server_bound_cert_service = new net::ServerBoundCertService( |
344 new net::DefaultServerBoundCertStore(NULL), | 357 new net::DefaultServerBoundCertStore(NULL), |
(...skipping 19 matching lines...) Expand all Loading... | |
364 new net::CookieMonster( | 377 new net::CookieMonster( |
365 new SQLitePersistentCookieStore( | 378 new SQLitePersistentCookieStore( |
366 lazy_params_->extensions_cookie_path, | 379 lazy_params_->extensions_cookie_path, |
367 lazy_params_->restore_old_session_cookies, NULL), NULL); | 380 lazy_params_->restore_old_session_cookies, NULL), NULL); |
368 // Enable cookies for devtools and extension URLs. | 381 // Enable cookies for devtools and extension URLs. |
369 const char* schemes[] = {chrome::kChromeDevToolsScheme, | 382 const char* schemes[] = {chrome::kChromeDevToolsScheme, |
370 chrome::kExtensionScheme}; | 383 chrome::kExtensionScheme}; |
371 extensions_cookie_store->SetCookieableSchemes(schemes, 2); | 384 extensions_cookie_store->SetCookieableSchemes(schemes, 2); |
372 | 385 |
373 main_context->set_cookie_store(cookie_store); | 386 main_context->set_cookie_store(cookie_store); |
374 media_request_context_->set_cookie_store(cookie_store); | |
375 extensions_context->set_cookie_store(extensions_cookie_store); | 387 extensions_context->set_cookie_store(extensions_cookie_store); |
376 | 388 |
377 // Setup server bound cert service. | 389 // Setup server bound cert service. |
378 if (!server_bound_cert_service) { | 390 if (!server_bound_cert_service) { |
379 DCHECK(!lazy_params_->server_bound_cert_path.empty()); | 391 DCHECK(!lazy_params_->server_bound_cert_path.empty()); |
380 | 392 |
381 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = | 393 scoped_refptr<SQLiteServerBoundCertStore> server_bound_cert_db = |
382 new SQLiteServerBoundCertStore( | 394 new SQLiteServerBoundCertStore( |
383 lazy_params_->server_bound_cert_path, | 395 lazy_params_->server_bound_cert_path, |
384 new ClearOnExitPolicy(lazy_params_->special_storage_policy)); | 396 new ClearOnExitPolicy(lazy_params_->special_storage_policy)); |
385 server_bound_cert_service = new net::ServerBoundCertService( | 397 server_bound_cert_service = new net::ServerBoundCertService( |
386 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), | 398 new net::DefaultServerBoundCertStore(server_bound_cert_db.get()), |
387 base::WorkerPool::GetTaskRunner(true)); | 399 base::WorkerPool::GetTaskRunner(true)); |
388 } | 400 } |
389 | 401 |
390 set_server_bound_cert_service(server_bound_cert_service); | 402 set_server_bound_cert_service(server_bound_cert_service); |
391 main_context->set_server_bound_cert_service(server_bound_cert_service); | 403 main_context->set_server_bound_cert_service(server_bound_cert_service); |
392 media_request_context_->set_server_bound_cert_service( | |
393 server_bound_cert_service); | |
394 | 404 |
395 std::string trusted_spdy_proxy; | 405 std::string trusted_spdy_proxy; |
396 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { | 406 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { |
397 trusted_spdy_proxy = command_line.GetSwitchValueASCII( | 407 trusted_spdy_proxy = command_line.GetSwitchValueASCII( |
398 switches::kTrustedSpdyProxy); | 408 switches::kTrustedSpdyProxy); |
399 } | 409 } |
400 net::HttpCache::DefaultBackend* main_backend = | 410 net::HttpCache::DefaultBackend* main_backend = |
401 new net::HttpCache::DefaultBackend( | 411 new net::HttpCache::DefaultBackend( |
402 net::DISK_CACHE, | 412 net::DISK_CACHE, |
403 lazy_params_->cache_path, | 413 lazy_params_->cache_path, |
404 lazy_params_->cache_max_size, | 414 lazy_params_->cache_max_size, |
405 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 415 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
406 net::HttpCache* main_cache = new net::HttpCache( | 416 net::HttpCache* main_cache = new net::HttpCache( |
407 main_context->host_resolver(), | 417 main_context->host_resolver(), |
408 main_context->cert_verifier(), | 418 main_context->cert_verifier(), |
409 main_context->server_bound_cert_service(), | 419 main_context->server_bound_cert_service(), |
410 main_context->transport_security_state(), | 420 main_context->transport_security_state(), |
411 main_context->proxy_service(), | 421 main_context->proxy_service(), |
412 GetSSLSessionCacheShard(), | 422 GetSSLSessionCacheShard(), |
413 main_context->ssl_config_service(), | 423 main_context->ssl_config_service(), |
414 main_context->http_auth_handler_factory(), | 424 main_context->http_auth_handler_factory(), |
415 main_context->network_delegate(), | 425 main_context->network_delegate(), |
416 main_context->http_server_properties(), | 426 main_context->http_server_properties(), |
417 main_context->net_log(), | 427 main_context->net_log(), |
418 main_backend, | 428 main_backend, |
419 trusted_spdy_proxy); | 429 trusted_spdy_proxy); |
420 | 430 |
421 net::HttpCache::DefaultBackend* media_backend = | |
422 new net::HttpCache::DefaultBackend( | |
423 net::MEDIA_CACHE, lazy_params_->media_cache_path, | |
424 lazy_params_->media_cache_max_size, | |
425 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
426 net::HttpNetworkSession* main_network_session = main_cache->GetSession(); | |
427 net::HttpCache* media_cache = | |
428 new net::HttpCache(main_network_session, media_backend); | |
429 | |
430 if (record_mode || playback_mode) { | 431 if (record_mode || playback_mode) { |
431 main_cache->set_mode( | 432 main_cache->set_mode( |
432 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 433 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
433 } | 434 } |
434 | 435 |
435 main_http_factory_.reset(main_cache); | 436 main_http_factory_.reset(main_cache); |
436 media_http_factory_.reset(media_cache); | |
437 main_context->set_http_transaction_factory(main_cache); | 437 main_context->set_http_transaction_factory(main_cache); |
438 media_request_context_->set_http_transaction_factory(media_cache); | |
439 | 438 |
440 ftp_factory_.reset( | 439 ftp_factory_.reset( |
441 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); | 440 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); |
442 main_context->set_ftp_transaction_factory(ftp_factory_.get()); | 441 main_context->set_ftp_transaction_factory(ftp_factory_.get()); |
443 media_request_context_->set_ftp_transaction_factory(ftp_factory_.get()); | |
444 | 442 |
445 main_context->set_chrome_url_data_manager_backend( | 443 main_context->set_chrome_url_data_manager_backend( |
446 chrome_url_data_manager_backend()); | 444 chrome_url_data_manager_backend()); |
447 | 445 |
446 // Create a media request context based on the main context, but using a | |
447 // media cache. | |
448 media_request_context_.reset(InitializeMediaRequestContext(main_context, "")); | |
449 | |
448 main_job_factory_.reset(new net::URLRequestJobFactory); | 450 main_job_factory_.reset(new net::URLRequestJobFactory); |
449 media_request_job_factory_.reset(new net::URLRequestJobFactory); | 451 media_request_job_factory_.reset(new net::URLRequestJobFactory); |
450 extensions_job_factory_.reset(new net::URLRequestJobFactory); | 452 extensions_job_factory_.reset(new net::URLRequestJobFactory); |
451 | 453 |
452 net::URLRequestJobFactory* job_factories[3]; | 454 net::URLRequestJobFactory* job_factories[3]; |
453 job_factories[0] = main_job_factory_.get(); | 455 job_factories[0] = main_job_factory_.get(); |
454 job_factories[1] = media_request_job_factory_.get(); | 456 job_factories[1] = media_request_job_factory_.get(); |
455 job_factories[2] = extensions_job_factory_.get(); | 457 job_factories[2] = extensions_job_factory_.get(); |
456 | 458 |
457 net::FtpAuthCache* ftp_auth_caches[3]; | 459 net::FtpAuthCache* ftp_auth_caches[3]; |
(...skipping 12 matching lines...) Expand all Loading... | |
470 media_request_context_->set_job_factory(media_request_job_factory_.get()); | 472 media_request_context_->set_job_factory(media_request_job_factory_.get()); |
471 extensions_context->set_job_factory(extensions_job_factory_.get()); | 473 extensions_context->set_job_factory(extensions_job_factory_.get()); |
472 | 474 |
473 lazy_params_.reset(); | 475 lazy_params_.reset(); |
474 } | 476 } |
475 | 477 |
476 ChromeURLRequestContext* | 478 ChromeURLRequestContext* |
477 ProfileImplIOData::InitializeAppRequestContext( | 479 ProfileImplIOData::InitializeAppRequestContext( |
478 ChromeURLRequestContext* main_context, | 480 ChromeURLRequestContext* main_context, |
479 const std::string& app_id) const { | 481 const std::string& app_id) const { |
480 AppRequestContext* context = new AppRequestContext(cache_stats()); | |
481 | |
482 // If this is for a guest process, we should not persist cookies and http | 482 // If this is for a guest process, we should not persist cookies and http |
483 // cache. | 483 // cache. |
484 bool guest_process = (app_id.find("guest-") != std::string::npos); | 484 bool is_guest_process = (app_id.find("guest-") != std::string::npos); |
485 | 485 |
486 // Copy most state from the main context. | 486 // Copy most state from the main context. |
487 AppRequestContext* context = new AppRequestContext(cache_stats()); | |
487 context->CopyFrom(main_context); | 488 context->CopyFrom(main_context); |
488 | 489 |
489 FilePath app_path = app_path_.AppendASCII(app_id); | 490 FilePath app_path = app_path_.AppendASCII(app_id); |
490 FilePath cookie_path = app_path.Append(chrome::kCookieFilename); | 491 FilePath cookie_path = app_path.Append(chrome::kCookieFilename); |
491 FilePath cache_path = app_path.Append(chrome::kCacheDirname); | 492 FilePath cache_path = app_path.Append(chrome::kCacheDirname); |
492 // TODO(creis): Determine correct cache size. | |
493 int cache_max_size = 0; | |
494 | 493 |
495 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 494 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
496 // Only allow Record Mode if we are in a Debug build or where we are running | 495 // Only allow Record Mode if we are in a Debug build or where we are running |
497 // a cycle, and the user has limited control. | 496 // a cycle, and the user has limited control. |
498 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && | 497 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && |
499 (chrome::kRecordModeEnabled || | 498 (chrome::kRecordModeEnabled || |
500 command_line.HasSwitch(switches::kVisitURLs)); | 499 command_line.HasSwitch(switches::kVisitURLs)); |
501 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); | 500 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); |
502 | 501 |
503 // Use a separate HTTP disk cache for isolated apps. | 502 // Use a separate HTTP disk cache for isolated apps. |
504 net::HttpCache::BackendFactory* app_backend = NULL; | 503 net::HttpCache::BackendFactory* app_backend = NULL; |
505 if (guest_process) { | 504 if (is_guest_process) { |
506 app_backend = net::HttpCache::DefaultBackend::InMemory(0); | 505 app_backend = net::HttpCache::DefaultBackend::InMemory(0); |
507 } else { | 506 } else { |
508 app_backend = new net::HttpCache::DefaultBackend( | 507 app_backend = new net::HttpCache::DefaultBackend( |
509 net::DISK_CACHE, | 508 net::DISK_CACHE, |
510 cache_path, | 509 cache_path, |
511 cache_max_size, | 510 app_cache_max_size_, |
512 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 511 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
513 } | 512 } |
514 net::HttpNetworkSession* main_network_session = | 513 net::HttpNetworkSession* main_network_session = |
515 main_http_factory_->GetSession(); | 514 main_http_factory_->GetSession(); |
516 net::HttpCache* app_http_cache = | 515 net::HttpCache* app_http_cache = |
517 new net::HttpCache(main_network_session, app_backend); | 516 new net::HttpCache(main_network_session, app_backend); |
518 | 517 |
519 scoped_refptr<net::CookieStore> cookie_store = NULL; | 518 scoped_refptr<net::CookieStore> cookie_store = NULL; |
520 if (guest_process) { | 519 if (is_guest_process) { |
521 cookie_store = new net::CookieMonster(NULL, NULL); | 520 cookie_store = new net::CookieMonster(NULL, NULL); |
522 } else if (record_mode || playback_mode) { | 521 } else if (record_mode || playback_mode) { |
523 // Don't use existing cookies and use an in-memory store. | 522 // Don't use existing cookies and use an in-memory store. |
524 // TODO(creis): We should have a cookie delegate for notifying the cookie | 523 // TODO(creis): We should have a cookie delegate for notifying the cookie |
525 // extensions API, but we need to update it to understand isolated apps | 524 // extensions API, but we need to update it to understand isolated apps |
526 // first. | 525 // first. |
527 cookie_store = new net::CookieMonster(NULL, NULL); | 526 cookie_store = new net::CookieMonster(NULL, NULL); |
528 app_http_cache->set_mode( | 527 app_http_cache->set_mode( |
529 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); | 528 record_mode ? net::HttpCache::RECORD : net::HttpCache::PLAYBACK); |
530 } | 529 } |
531 | 530 |
532 // Use an app-specific cookie store. | 531 // Use an app-specific cookie store. |
533 if (!cookie_store) { | 532 if (!cookie_store) { |
534 DCHECK(!cookie_path.empty()); | 533 DCHECK(!cookie_path.empty()); |
535 | 534 |
536 scoped_refptr<SQLitePersistentCookieStore> cookie_db = | 535 scoped_refptr<SQLitePersistentCookieStore> cookie_db = |
537 new SQLitePersistentCookieStore(cookie_path, false, NULL); | 536 new SQLitePersistentCookieStore(cookie_path, false, NULL); |
538 // TODO(creis): We should have a cookie delegate for notifying the cookie | 537 // TODO(creis): We should have a cookie delegate for notifying the cookie |
539 // extensions API, but we need to update it to understand isolated apps | 538 // extensions API, but we need to update it to understand isolated apps |
540 // first. | 539 // first. |
541 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); | 540 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); |
542 } | 541 } |
543 | 542 |
543 // Transfer ownership of the cookies and cache to AppRequestContext. | |
544 context->SetCookieStore(cookie_store); | 544 context->SetCookieStore(cookie_store); |
545 context->SetHttpTransactionFactory(app_http_cache); | 545 context->SetHttpTransactionFactory(app_http_cache); |
546 | 546 |
547 return context; | 547 return context; |
548 } | 548 } |
549 | 549 |
550 ChromeURLRequestContext* | 550 ChromeURLRequestContext* |
551 ProfileImplIOData::InitializeMediaRequestContext( | |
willchan no longer on Chromium
2012/08/20 23:04:51
I think this is right. I assume you've manually te
Charlie Reis
2012/08/20 23:49:44
I manually tested it for cookies and cache, yes, a
| |
552 ChromeURLRequestContext* original_context, | |
553 const std::string& app_id) const { | |
554 // If this is for a guest process, we do not persist storage, so we can | |
555 // simply use the app's in-memory cache (like off-the-record mode). | |
556 if (app_id.find("guest-") != std::string::npos) | |
557 return original_context; | |
558 | |
559 // Copy most state from the original context. | |
560 MediaRequestContext* context = new MediaRequestContext(cache_stats()); | |
561 context->CopyFrom(original_context); | |
562 | |
563 FilePath app_path = app_path_.AppendASCII(app_id); | |
564 FilePath cache_path; | |
565 int cache_max_size = app_media_cache_max_size_; | |
566 if (app_id.empty()) { | |
567 // lazy_params_ is only valid for the default media context creation. | |
568 cache_path = lazy_params_->media_cache_path; | |
569 cache_max_size = lazy_params_->media_cache_max_size; | |
570 } else { | |
571 cache_path = app_path.Append(chrome::kMediaCacheDirname); | |
572 } | |
573 | |
574 // Use a separate HTTP disk cache for isolated apps. | |
575 net::HttpCache::BackendFactory* media_backend = | |
576 new net::HttpCache::DefaultBackend( | |
577 net::MEDIA_CACHE, | |
578 cache_path, | |
579 cache_max_size, | |
580 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
581 net::HttpNetworkSession* main_network_session = | |
582 main_http_factory_->GetSession(); | |
583 net::HttpCache* media_http_cache = | |
584 new net::HttpCache(main_network_session, media_backend); | |
585 | |
586 // Transfer ownership of the cache to MediaRequestContext. | |
587 context->SetHttpTransactionFactory(media_http_cache); | |
588 | |
589 return context; | |
590 } | |
591 | |
592 ChromeURLRequestContext* | |
551 ProfileImplIOData::AcquireMediaRequestContext() const { | 593 ProfileImplIOData::AcquireMediaRequestContext() const { |
552 DCHECK(media_request_context_.get()); | 594 DCHECK(media_request_context_.get()); |
553 return media_request_context_.get(); | 595 return media_request_context_.get(); |
554 } | 596 } |
555 | 597 |
556 ChromeURLRequestContext* | 598 ChromeURLRequestContext* |
557 ProfileImplIOData::AcquireIsolatedAppRequestContext( | 599 ProfileImplIOData::AcquireIsolatedAppRequestContext( |
558 ChromeURLRequestContext* main_context, | 600 ChromeURLRequestContext* main_context, |
559 const std::string& app_id) const { | 601 const std::string& app_id) const { |
560 // We create per-app contexts on demand, unlike the others above. | 602 // We create per-app contexts on demand, unlike the others above. |
561 ChromeURLRequestContext* app_request_context = | 603 ChromeURLRequestContext* app_request_context = |
562 InitializeAppRequestContext(main_context, app_id); | 604 InitializeAppRequestContext(main_context, app_id); |
563 DCHECK(app_request_context); | 605 DCHECK(app_request_context); |
564 return app_request_context; | 606 return app_request_context; |
565 } | 607 } |
566 | 608 |
609 ChromeURLRequestContext* | |
610 ProfileImplIOData::AcquireIsolatedMediaRequestContext( | |
611 ChromeURLRequestContext* app_context, | |
612 const std::string& app_id) const { | |
613 // We create per-app media contexts on demand, unlike the others above. | |
614 ChromeURLRequestContext* media_request_context = | |
615 InitializeMediaRequestContext(app_context, app_id); | |
616 DCHECK(media_request_context); | |
617 return media_request_context; | |
618 } | |
619 | |
567 chrome_browser_net::CacheStats* ProfileImplIOData::GetCacheStats( | 620 chrome_browser_net::CacheStats* ProfileImplIOData::GetCacheStats( |
568 IOThread::Globals* io_thread_globals) const { | 621 IOThread::Globals* io_thread_globals) const { |
569 return io_thread_globals->cache_stats.get(); | 622 return io_thread_globals->cache_stats.get(); |
570 } | 623 } |
571 | 624 |
572 void ProfileImplIOData::CreateFtpProtocolHandler( | 625 void ProfileImplIOData::CreateFtpProtocolHandler( |
573 net::URLRequestJobFactory* job_factory, | 626 net::URLRequestJobFactory* job_factory, |
574 net::FtpAuthCache* ftp_auth_cache) const { | 627 net::FtpAuthCache* ftp_auth_cache) const { |
575 job_factory->SetProtocolHandler( | 628 job_factory->SetProtocolHandler( |
576 chrome::kFtpScheme, | 629 chrome::kFtpScheme, |
577 new net::FtpProtocolHandler(network_delegate(), | 630 new net::FtpProtocolHandler(network_delegate(), |
578 ftp_factory_.get(), | 631 ftp_factory_.get(), |
579 ftp_auth_cache)); | 632 ftp_auth_cache)); |
580 } | 633 } |
581 | 634 |
582 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( | 635 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( |
583 base::Time time) { | 636 base::Time time) { |
584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
585 LazyInitialize(); | 638 LazyInitialize(); |
586 | 639 |
587 DCHECK(transport_security_state()); | 640 DCHECK(transport_security_state()); |
588 transport_security_state()->DeleteSince(time); | 641 transport_security_state()->DeleteSince(time); |
589 DCHECK(http_server_properties_manager()); | 642 DCHECK(http_server_properties_manager()); |
590 http_server_properties_manager()->Clear(); | 643 http_server_properties_manager()->Clear(); |
591 } | 644 } |
OLD | NEW |