diff options
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_io_data.cc | 16 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_io_data.h | 3 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl_io_data.cc | 17 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl_io_data.h | 3 | ||||
-rw-r--r-- | net/net.gyp | 2 | ||||
-rw-r--r-- | net/url_request/ftp_protocol_handler.cc | 31 | ||||
-rw-r--r-- | net/url_request/ftp_protocol_handler.h | 39 | ||||
-rw-r--r-- | net/url_request/url_request_ftp_job.cc | 39 | ||||
-rw-r--r-- | net/url_request/url_request_ftp_job.h | 13 |
9 files changed, 143 insertions, 20 deletions
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc index 7128a0b..830d6df 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -27,6 +27,7 @@ #include "net/ftp/ftp_network_layer.h" #include "net/http/http_cache.h" #include "net/http/http_server_properties_impl.h" +#include "net/url_request/ftp_protocol_handler.h" #include "net/url_request/url_request_job_factory.h" #include "webkit/database/database_tracker.h" @@ -254,8 +255,13 @@ void OffTheRecordProfileIOData::LazyInitializeInternal( job_factories[0] = main_job_factory_.get(); job_factories[1] = extensions_job_factory_.get(); + net::FtpAuthCache* ftp_auth_caches[2]; + ftp_auth_caches[0] = main_context->ftp_auth_cache(); + ftp_auth_caches[1] = extensions_context->ftp_auth_cache(); + for (int i = 0; i < 2; i++) { SetUpJobFactoryDefaults(job_factories[i]); + CreateFtpProtocolHandler(job_factories[i], ftp_auth_caches[i]); } main_context->set_job_factory(main_job_factory_.get()); @@ -304,3 +310,13 @@ OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( DCHECK(app_request_context); return app_request_context; } + +void OffTheRecordProfileIOData::CreateFtpProtocolHandler( + net::URLRequestJobFactory* job_factory, + net::FtpAuthCache* ftp_auth_cache) const { + job_factory->SetProtocolHandler( + chrome::kFtpScheme, + new net::FtpProtocolHandler( + network_delegate(), ftp_factory_.get(), ftp_auth_cache)); +} + diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.h b/chrome/browser/profiles/off_the_record_profile_io_data.h index 6497374..19fe115 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.h +++ b/chrome/browser/profiles/off_the_record_profile_io_data.h @@ -108,6 +108,9 @@ class OffTheRecordProfileIOData : public ProfileIOData { ChromeURLRequestContext* main_context, const std::string& app_id) const OVERRIDE; + void CreateFtpProtocolHandler(net::URLRequestJobFactory* job_factory, + net::FtpAuthCache* ftp_auth_cache) const; + mutable scoped_ptr<net::HttpServerPropertiesImpl> http_server_properties_; mutable scoped_ptr<net::HttpTransactionFactory> main_http_factory_; diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index bf5bc50..da28878 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -30,6 +30,7 @@ #include "net/base/server_bound_cert_service.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_cache.h" +#include "net/url_request/ftp_protocol_handler.h" #include "net/url_request/url_request_job_factory.h" #include "webkit/quota/special_storage_policy.h" @@ -446,8 +447,14 @@ void ProfileImplIOData::LazyInitializeInternal( job_factories[1] = media_request_job_factory_.get(); job_factories[2] = extensions_job_factory_.get(); + net::FtpAuthCache* ftp_auth_caches[3]; + ftp_auth_caches[0] = main_context->ftp_auth_cache(); + ftp_auth_caches[1] = media_request_context_->ftp_auth_cache(); + ftp_auth_caches[2] = extensions_context->ftp_auth_cache(); + for (int i = 0; i < 3; i++) { SetUpJobFactoryDefaults(job_factories[i]); + CreateFtpProtocolHandler(job_factories[i], ftp_auth_caches[i]); job_factories[i]->AddInterceptor( new chrome_browser_net::ConnectInterceptor(predictor_.get())); } @@ -540,6 +547,16 @@ ProfileImplIOData::AcquireIsolatedAppRequestContext( return app_request_context; } +void ProfileImplIOData::CreateFtpProtocolHandler( + net::URLRequestJobFactory* job_factory, + net::FtpAuthCache* ftp_auth_cache) const { + job_factory->SetProtocolHandler( + chrome::kFtpScheme, + new net::FtpProtocolHandler(network_delegate(), + ftp_factory_.get(), + ftp_auth_cache)); +} + void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( base::Time time) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); diff --git a/chrome/browser/profiles/profile_impl_io_data.h b/chrome/browser/profiles/profile_impl_io_data.h index 680dc0b..a5d45c9 100644 --- a/chrome/browser/profiles/profile_impl_io_data.h +++ b/chrome/browser/profiles/profile_impl_io_data.h @@ -141,6 +141,9 @@ class ProfileImplIOData : public ProfileIOData { ChromeURLRequestContext* main_context, const std::string& app_id) const OVERRIDE; + void CreateFtpProtocolHandler(net::URLRequestJobFactory* job_factory, + net::FtpAuthCache* ftp_auth_cache) const; + // Clears the networking history since |time|. void ClearNetworkingHistorySinceOnIOThread(base::Time time); diff --git a/net/net.gyp b/net/net.gyp index 48fd6b3..d7d0fe0 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -719,6 +719,8 @@ 'udp/udp_socket_win.cc', 'udp/udp_socket_win.h', 'url_request/fraudulent_certificate_reporter.h', + 'url_request/ftp_protocol_handler.cc', + 'url_request/ftp_protocol_handler.h', 'url_request/url_fetcher.cc', 'url_request/url_fetcher.h', 'url_request/url_fetcher_core.cc', diff --git a/net/url_request/ftp_protocol_handler.cc b/net/url_request/ftp_protocol_handler.cc new file mode 100644 index 0000000..e10a1cd --- /dev/null +++ b/net/url_request/ftp_protocol_handler.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/url_request/ftp_protocol_handler.h" + +#include "base/logging.h" +#include "net/url_request/url_request_ftp_job.h" + +namespace net { + +FtpProtocolHandler::FtpProtocolHandler( + NetworkDelegate* network_delegate, + FtpTransactionFactory* ftp_transaction_factory, + FtpAuthCache* ftp_auth_cache) + : network_delegate_(network_delegate), + ftp_transaction_factory_(ftp_transaction_factory), + ftp_auth_cache_(ftp_auth_cache) { + DCHECK(ftp_transaction_factory_); + DCHECK(ftp_auth_cache_); +} + +URLRequestJob* FtpProtocolHandler::MaybeCreateJob( + URLRequest* request) const { + return new URLRequestFtpJob(request, + network_delegate_, + ftp_transaction_factory_, + ftp_auth_cache_); +} + +} // namespace net diff --git a/net/url_request/ftp_protocol_handler.h b/net/url_request/ftp_protocol_handler.h new file mode 100644 index 0000000..093aded --- /dev/null +++ b/net/url_request/ftp_protocol_handler.h @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_URL_REQUEST_FTP_PROTOCOL_HANDLER_H_ +#define NET_URL_REQUEST_FTP_PROTOCOL_HANDLER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "net/url_request/url_request_job_factory.h" + +namespace net { + +class FtpAuthCache; +class FtpTransactionFactory; +class NetworkDelegate; +class URLRequestJob; + +// Implements a ProtocolHandler for FTP. +class NET_EXPORT FtpProtocolHandler : + public URLRequestJobFactory::ProtocolHandler { + public: + FtpProtocolHandler(NetworkDelegate* network_delegate, + FtpTransactionFactory* ftp_transaction_factory, + FtpAuthCache* ftp_auth_cache); + virtual URLRequestJob* MaybeCreateJob(URLRequest* request) const OVERRIDE; + + private: + NetworkDelegate* network_delegate_; + FtpTransactionFactory* ftp_transaction_factory_; + FtpAuthCache* ftp_auth_cache_; + + DISALLOW_COPY_AND_ASSIGN(FtpProtocolHandler); +}; + +} // namespace net + +#endif // NET_URL_REQUEST_FTP_PROTOCOL_HANDLER_H_ diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc index aca1b48..b0a3b43 100644 --- a/net/url_request/url_request_ftp_job.cc +++ b/net/url_request/url_request_ftp_job.cc @@ -19,10 +19,18 @@ namespace net { -URLRequestFtpJob::URLRequestFtpJob(URLRequest* request) - : URLRequestJob(request, request->context()->network_delegate()), +URLRequestFtpJob::URLRequestFtpJob( + URLRequest* request, + NetworkDelegate* network_delegate, + FtpTransactionFactory* ftp_transaction_factory, + FtpAuthCache* ftp_auth_cache) + : URLRequestJob(request, network_delegate), read_in_progress_(false), - ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), + ftp_transaction_factory_(ftp_transaction_factory), + ftp_auth_cache_(ftp_auth_cache) { + DCHECK(ftp_transaction_factory); + DCHECK(ftp_auth_cache); } // static @@ -32,12 +40,14 @@ URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request, int port = request->url().IntPort(); if (request->url().has_port() && - !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) + !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) { return new URLRequestErrorJob(request, ERR_UNSAFE_PORT); + } - DCHECK(request->context()); - DCHECK(request->context()->ftp_transaction_factory()); - return new URLRequestFtpJob(request); + return new URLRequestFtpJob(request, + request->context()->network_delegate(), + request->context()->ftp_transaction_factory(), + request->context()->ftp_auth_cache()); } bool URLRequestFtpJob::GetMimeType(std::string* mime_type) const { @@ -61,11 +71,8 @@ URLRequestFtpJob::~URLRequestFtpJob() { void URLRequestFtpJob::StartTransaction() { // Create a transaction. DCHECK(!transaction_.get()); - DCHECK(request_->context()); - DCHECK(request_->context()->ftp_transaction_factory()); - transaction_.reset( - request_->context()->ftp_transaction_factory()->CreateTransaction()); + transaction_.reset(ftp_transaction_factory_->CreateTransaction()); // No matter what, we want to report our status as IO pending since we will // be notifying our consumer asynchronously via OnStartCompleted. @@ -104,16 +111,13 @@ void URLRequestFtpJob::OnStartCompleted(int result) { } else if (transaction_->GetResponseInfo()->needs_auth) { GURL origin = request_->url().GetOrigin(); if (server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH) { - request_->context()->ftp_auth_cache()->Remove( - origin, server_auth_->credentials); + ftp_auth_cache_->Remove(origin, server_auth_->credentials); } else if (!server_auth_) { server_auth_ = new AuthData(); } server_auth_->state = AUTH_STATE_NEED_AUTH; - FtpAuthCache::Entry* cached_auth = - request_->context()->ftp_auth_cache()->Lookup(origin); - + FtpAuthCache::Entry* cached_auth = ftp_auth_cache_->Lookup(origin); if (cached_auth) { // Retry using cached auth data. SetAuth(cached_auth->credentials); @@ -204,8 +208,7 @@ void URLRequestFtpJob::SetAuth(const AuthCredentials& credentials) { server_auth_->state = AUTH_STATE_HAVE_AUTH; server_auth_->credentials = credentials; - request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), - server_auth_->credentials); + ftp_auth_cache_->Add(request_->url().GetOrigin(), server_auth_->credentials); RestartTransactionWithAuth(); } diff --git a/net/url_request/url_request_ftp_job.h b/net/url_request/url_request_ftp_job.h index 05cbb33..7eaba0c 100644 --- a/net/url_request/url_request_ftp_job.h +++ b/net/url_request/url_request_ftp_job.h @@ -17,14 +17,20 @@ namespace net { -class URLRequestContext; +class NetworkDelegate; +class FtpTransactionFactory; +class FtpAuthCache; // A URLRequestJob subclass that is built on top of FtpTransaction. It // provides an implementation for FTP. class URLRequestFtpJob : public URLRequestJob { public: - explicit URLRequestFtpJob(URLRequest* request); + URLRequestFtpJob(URLRequest* request, + NetworkDelegate* network_delegate, + FtpTransactionFactory* ftp_transaction_factory, + FtpAuthCache* ftp_auth_cache); + // TODO(shalev): get rid of this function in favor of FtpProtocolHandler. static URLRequestJob* Factory(URLRequest* request, const std::string& scheme); @@ -69,6 +75,9 @@ class URLRequestFtpJob : public URLRequestJob { base::WeakPtrFactory<URLRequestFtpJob> weak_factory_; + FtpTransactionFactory* ftp_transaction_factory_; + FtpAuthCache* ftp_auth_cache_; + DISALLOW_COPY_AND_ASSIGN(URLRequestFtpJob); }; |