Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: chrome/browser/profiles/profile_impl_io_data.cc

Issue 11293252: Change Interceptors into URLRequestJobFactory::ProtocolHandlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/prefs/public/pref_member.h" 11 #include "base/prefs/public/pref_member.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
15 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 15 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
16 #include "chrome/browser/io_thread.h" 16 #include "chrome/browser/io_thread.h"
17 #include "chrome/browser/net/chrome_net_log.h" 17 #include "chrome/browser/net/chrome_net_log.h"
18 #include "chrome/browser/net/chrome_network_delegate.h"
18 #include "chrome/browser/net/clear_on_exit_policy.h" 19 #include "chrome/browser/net/clear_on_exit_policy.h"
19 #include "chrome/browser/net/connect_interceptor.h" 20 #include "chrome/browser/net/connect_interceptor.h"
20 #include "chrome/browser/net/http_server_properties_manager.h" 21 #include "chrome/browser/net/http_server_properties_manager.h"
21 #include "chrome/browser/net/predictor.h" 22 #include "chrome/browser/net/predictor.h"
22 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" 23 #include "chrome/browser/net/sqlite_persistent_cookie_store.h"
23 #include "chrome/browser/net/sqlite_server_bound_cert_store.h" 24 #include "chrome/browser/net/sqlite_server_bound_cert_store.h"
24 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 27 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
27 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 IOThread* const io_thread = profile_params->io_thread; 307 IOThread* const io_thread = profile_params->io_thread;
307 IOThread::Globals* const io_thread_globals = io_thread->globals(); 308 IOThread::Globals* const io_thread_globals = io_thread->globals();
308 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 309 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
309 // Only allow Record Mode if we are in a Debug build or where we are running 310 // Only allow Record Mode if we are in a Debug build or where we are running
310 // a cycle, and the user has limited control. 311 // a cycle, and the user has limited control.
311 bool record_mode = command_line.HasSwitch(switches::kRecordMode) && 312 bool record_mode = command_line.HasSwitch(switches::kRecordMode) &&
312 (chrome::kRecordModeEnabled || 313 (chrome::kRecordModeEnabled ||
313 command_line.HasSwitch(switches::kVisitURLs)); 314 command_line.HasSwitch(switches::kVisitURLs));
314 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode); 315 bool playback_mode = command_line.HasSwitch(switches::kPlaybackMode);
315 316
317 network_delegate()->set_predictor(predictor_.get());
318
316 // Initialize context members. 319 // Initialize context members.
317 320
318 ApplyProfileParamsToContext(main_context); 321 ApplyProfileParamsToContext(main_context);
319 322
320 if (http_server_properties_manager_) 323 if (http_server_properties_manager_)
321 http_server_properties_manager_->InitializeOnIOThread(); 324 http_server_properties_manager_->InitializeOnIOThread();
322 325
323 main_context->set_transport_security_state(transport_security_state()); 326 main_context->set_transport_security_state(transport_security_state());
324 327
325 main_context->set_net_log(io_thread->net_log()); 328 main_context->set_net_log(io_thread->net_log());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 ftp_factory_.reset( 415 ftp_factory_.reset(
413 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); 416 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get()));
414 main_context->set_ftp_transaction_factory(ftp_factory_.get()); 417 main_context->set_ftp_transaction_factory(ftp_factory_.get());
415 #endif // !defined(DISABLE_FTP_SUPPORT) 418 #endif // !defined(DISABLE_FTP_SUPPORT)
416 419
417 main_context->set_chrome_url_data_manager_backend( 420 main_context->set_chrome_url_data_manager_backend(
418 chrome_url_data_manager_backend()); 421 chrome_url_data_manager_backend());
419 422
420 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( 423 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
421 new net::URLRequestJobFactoryImpl()); 424 new net::URLRequestJobFactoryImpl());
422 SetUpJobFactory(main_job_factory.get(), 425 SetUpJobFactoryDefaults(main_job_factory.get(),
423 profile_params->protocol_handler_interceptor.Pass(), 426 profile_params->protocol_handler_interceptor.Pass(),
424 network_delegate(), 427 network_delegate(),
425 main_context->ftp_transaction_factory(), 428 main_context->ftp_transaction_factory(),
426 main_context->ftp_auth_cache()); 429 main_context->ftp_auth_cache());
427 main_job_factory_ = main_job_factory.Pass(); 430 main_job_factory_ = main_job_factory.Pass();
428 main_context->set_job_factory(main_job_factory_.get()); 431 main_context->set_job_factory(main_job_factory_.get());
429 432
430 #if defined(ENABLE_EXTENSIONS) 433 #if defined(ENABLE_EXTENSIONS)
431 InitializeExtensionsRequestContext(profile_params); 434 InitializeExtensionsRequestContext(profile_params);
432 #endif 435 #endif
433 436
434 // Create a media request context based on the main context, but using a 437 // Create a media request context based on the main context, but using a
435 // media cache. It shares the same job factory as the main context. 438 // media cache. It shares the same job factory as the main context.
436 StoragePartitionDescriptor details(profile_path_, false); 439 StoragePartitionDescriptor details(profile_path_, false);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 #endif // !defined(DISABLE_FTP_SUPPORT) 474 #endif // !defined(DISABLE_FTP_SUPPORT)
472 475
473 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory( 476 scoped_ptr<net::URLRequestJobFactoryImpl> extensions_job_factory(
474 new net::URLRequestJobFactoryImpl()); 477 new net::URLRequestJobFactoryImpl());
475 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. 478 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate.
476 // Without a network_delegate, this protocol handler will never 479 // Without a network_delegate, this protocol handler will never
477 // handle file: requests, but as a side effect it makes 480 // handle file: requests, but as a side effect it makes
478 // job_factory::IsHandledProtocol return true, which prevents attempts to 481 // job_factory::IsHandledProtocol return true, which prevents attempts to
479 // handle the protocol externally. We pass NULL in to 482 // handle the protocol externally. We pass NULL in to
480 // SetUpJobFactory() to get this effect. 483 // SetUpJobFactory() to get this effect.
481 SetUpJobFactory(extensions_job_factory.get(), 484 SetUpJobFactoryDefaults(
482 scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL), 485 extensions_job_factory.get(),
483 NULL, 486 scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL),
484 extensions_context->ftp_transaction_factory(), 487 NULL,
485 extensions_context->ftp_auth_cache()); 488 extensions_context->ftp_transaction_factory(),
489 extensions_context->ftp_auth_cache());
486 extensions_job_factory_ = extensions_job_factory.Pass(); 490 extensions_job_factory_ = extensions_job_factory.Pass();
487 extensions_context->set_job_factory(extensions_job_factory_.get()); 491 extensions_context->set_job_factory(extensions_job_factory_.get());
488 } 492 }
489 493
490 ChromeURLRequestContext* 494 ChromeURLRequestContext*
491 ProfileImplIOData::InitializeAppRequestContext( 495 ProfileImplIOData::InitializeAppRequestContext(
492 ChromeURLRequestContext* main_context, 496 ChromeURLRequestContext* main_context,
493 const StoragePartitionDescriptor& partition_descriptor, 497 const StoragePartitionDescriptor& partition_descriptor,
494 scoped_ptr<net::URLRequestJobFactory::Interceptor> 498 scoped_ptr<net::URLRequestJobFactory::Interceptor>
495 protocol_handler_interceptor) const { 499 protocol_handler_interceptor) const {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // first. 553 // first.
550 cookie_store = new net::CookieMonster(cookie_db.get(), NULL); 554 cookie_store = new net::CookieMonster(cookie_db.get(), NULL);
551 } 555 }
552 556
553 // Transfer ownership of the cookies and cache to AppRequestContext. 557 // Transfer ownership of the cookies and cache to AppRequestContext.
554 context->SetCookieStore(cookie_store); 558 context->SetCookieStore(cookie_store);
555 context->SetHttpTransactionFactory( 559 context->SetHttpTransactionFactory(
556 scoped_ptr<net::HttpTransactionFactory>(app_http_cache)); 560 scoped_ptr<net::HttpTransactionFactory>(app_http_cache));
557 561
558 // Overwrite the job factory that we inherit from the main context so 562 // Overwrite the job factory that we inherit from the main context so
559 // that we can later provide our own handles for storage related protocols. 563 // that we can later provide our own handlers for storage related protocols.
560 // Install all the usual protocol handlers unless we are in a browser plugin 564 // Install all the usual protocol handlers unless we are in a browser plugin
561 // guest process, in which case only web-safe schemes are allowed. 565 // guest process, in which case only web-safe schemes are allowed.
562 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 566 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
563 new net::URLRequestJobFactoryImpl()); 567 new net::URLRequestJobFactoryImpl());
564 if (!partition_descriptor.in_memory) { 568 if (!partition_descriptor.in_memory) {
565 SetUpJobFactory(job_factory.get(), protocol_handler_interceptor.Pass(), 569 SetUpJobFactoryDefaults(
566 network_delegate(), 570 job_factory.get(), protocol_handler_interceptor.Pass(),
567 context->ftp_transaction_factory(), 571 network_delegate(),
568 context->ftp_auth_cache()); 572 context->ftp_transaction_factory(),
573 context->ftp_auth_cache());
569 } 574 }
570 context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>()); 575 context->SetJobFactory(job_factory.PassAs<net::URLRequestJobFactory>());
571 576
572 return context; 577 return context;
573 } 578 }
574 579
575 ChromeURLRequestContext* 580 ChromeURLRequestContext*
576 ProfileImplIOData::InitializeMediaRequestContext( 581 ProfileImplIOData::InitializeMediaRequestContext(
577 ChromeURLRequestContext* original_context, 582 ChromeURLRequestContext* original_context,
578 const StoragePartitionDescriptor& partition_descriptor) const { 583 const StoragePartitionDescriptor& partition_descriptor) const {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 InitializeMediaRequestContext(app_context, partition_descriptor); 654 InitializeMediaRequestContext(app_context, partition_descriptor);
650 DCHECK(media_request_context); 655 DCHECK(media_request_context);
651 return media_request_context; 656 return media_request_context;
652 } 657 }
653 658
654 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats( 659 chrome_browser_net::LoadTimeStats* ProfileImplIOData::GetLoadTimeStats(
655 IOThread::Globals* io_thread_globals) const { 660 IOThread::Globals* io_thread_globals) const {
656 return io_thread_globals->load_time_stats.get(); 661 return io_thread_globals->load_time_stats.get();
657 } 662 }
658 663
659 void ProfileImplIOData::SetUpJobFactory(
660 net::URLRequestJobFactoryImpl* job_factory,
661 scoped_ptr<net::URLRequestJobFactory::Interceptor>
662 protocol_handler_interceptor,
663 net::NetworkDelegate* network_delegate,
664 net::FtpTransactionFactory* ftp_transaction_factory,
665 net::FtpAuthCache* ftp_auth_cache) const {
666 SetUpJobFactoryDefaults(job_factory, protocol_handler_interceptor.Pass(),
667 network_delegate, ftp_transaction_factory,
668 ftp_auth_cache);
669
670 job_factory->AddInterceptor(
671 new chrome_browser_net::ConnectInterceptor(predictor_.get()));
672 }
673
674 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( 664 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread(
675 base::Time time, 665 base::Time time,
676 const base::Closure& completion) { 666 const base::Closure& completion) {
677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
678 LazyInitialize(); 668 LazyInitialize();
679 669
680 DCHECK(transport_security_state()); 670 DCHECK(transport_security_state());
681 transport_security_state()->DeleteSince(time); // Completes synchronously. 671 transport_security_state()->DeleteSince(time); // Completes synchronously.
682 DCHECK(http_server_properties_manager_); 672 DCHECK(http_server_properties_manager_);
683 http_server_properties_manager_->Clear(completion); 673 http_server_properties_manager_->Clear(completion);
684 } 674 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl_io_data.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698