From b65ce0948709317aadc38e18c1a16f23a72bb5eb Mon Sep 17 00:00:00 2001 From: "wtc@chromium.org" Date: Mon, 16 Mar 2009 20:13:33 +0000 Subject: Add command line switch "--new-ftp" for new portable FTP implementation. Add the (empty) URLRequestNewFtpJob class. Contributed by Ibrar Ahmed . BUG=4965 R=darin,wtc Review URL: http://codereview.chromium.org/42197 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11768 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/net/chrome_url_request_context.cc | 11 +++ chrome/common/chrome_switches.cc | 3 + chrome/common/chrome_switches.h | 2 + net/build/net.vcproj | 14 +++- net/ftp/ftp_network_transaction.h | 2 +- net/net.gyp | 2 + net/net_lib.scons | 2 + net/url_request/url_request_context.h | 10 ++- net/url_request/url_request_ftp_job.cc | 7 +- net/url_request/url_request_new_ftp_job.cc | 90 ++++++++++++++++++++++++ net/url_request/url_request_new_ftp_job.h | 60 ++++++++++++++++ 11 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 net/url_request/url_request_new_ftp_job.cc create mode 100644 net/url_request/url_request_new_ftp_job.h diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index a33716e..528c0e1 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -15,6 +15,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" +#include "net/ftp/ftp_network_layer.h" #include "net/http/http_cache.h" #include "net/http/http_network_layer.h" #include "net/http/http_util.h" @@ -82,6 +83,15 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal( } context->http_transaction_factory_ = cache; + // The kNewFtp switch is Windows specific only because we have multiple FTP + // implementations on Windows. +#if defined(OS_WIN) + if (command_line.HasSwitch(switches::kNewFtp)) + context->ftp_transaction_factory_ = new net::FtpNetworkLayer; +#else + context->ftp_transaction_factory_ = new net::FtpNetworkLayer; +#endif + // setup cookie store if (!context->cookie_store_) { DCHECK(!cookie_store_path.empty()); @@ -288,6 +298,7 @@ ChromeURLRequestContext::~ChromeURLRequestContext() { NotificationService::NoDetails()); delete cookie_store_; + delete ftp_transaction_factory_; delete http_transaction_factory_; // Do not delete the proxy service in the case of OTR, as it is owned by the diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 1a7e91b..0a101b4 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -392,6 +392,9 @@ const wchar_t kTestName[] = L"test-name"; // command line. (Useful values might be "valgrind" or "gdb --args") const wchar_t kRendererCmdPrefix[] = L"renderer-cmd-prefix"; +// Temparary option for new ftp implemetation. +const wchar_t kNewFtp[] = L"new-ftp"; + // On POSIX only: use FIFO for IPC channels so that "unrelated" process // can connect to a channel, provided it knows its name. For debugging purposes. const wchar_t kIPCUseFIFO[] = L"ipc-use-fifo"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 07b171f..cd78d00 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -149,6 +149,8 @@ extern const wchar_t kTestName[]; extern const wchar_t kRendererCmdPrefix[]; +extern const wchar_t kNewFtp[]; + extern const wchar_t kIPCUseFIFO[]; extern const wchar_t kEnableOutOfProcessDevTools[]; diff --git a/net/build/net.vcproj b/net/build/net.vcproj index ffe5699..07d47a6 100644 --- a/net/build/net.vcproj +++ b/net/build/net.vcproj @@ -662,6 +662,14 @@ > + + + + @@ -1054,15 +1062,15 @@ > context() && request->context()->ftp_transaction_factory()) + return URLRequestNewFtpJob::Factory(request, scheme); + DCHECK(scheme == "ftp"); if (request->url().has_port() && diff --git a/net/url_request/url_request_new_ftp_job.cc b/net/url_request/url_request_new_ftp_job.cc new file mode 100644 index 0000000..3101783 --- /dev/null +++ b/net/url_request/url_request_new_ftp_job.cc @@ -0,0 +1,90 @@ +// Copyright (c) 2009 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/url_request_new_ftp_job.h" + +#include "base/file_version_info.h" +#include "net/base/net_util.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_error_job.h" + + +URLRequestNewFtpJob::URLRequestNewFtpJob(URLRequest* request) + : URLRequestJob(request), + server_auth_state_(net::AUTH_STATE_DONT_NEED_AUTH), + ALLOW_THIS_IN_INITIALIZER_LIST( + start_callback_(this, &URLRequestNewFtpJob::OnStartCompleted)), + ALLOW_THIS_IN_INITIALIZER_LIST( + read_callback_(this, &URLRequestNewFtpJob::OnReadCompleted)), + read_in_progress_(false), + context_(request->context()) { +} + +URLRequestNewFtpJob::~URLRequestNewFtpJob() { +} + +// static +URLRequestJob* URLRequestNewFtpJob::Factory(URLRequest* request, + const std::string& scheme) { + DCHECK(scheme == "ftp"); + + if (request->url().has_port() && + !net::IsPortAllowedByFtp(request->url().IntPort())) + return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); + + DCHECK(request->context()); + DCHECK(request->context()->ftp_transaction_factory()); + return new URLRequestNewFtpJob(request); +} + +void URLRequestNewFtpJob::Start() { + NOTIMPLEMENTED(); +} + +void URLRequestNewFtpJob::Kill() { + NOTIMPLEMENTED(); +} + +uint64 URLRequestNewFtpJob::GetUploadProgress() const { + NOTIMPLEMENTED(); + return 0; +} + +void URLRequestNewFtpJob::GetResponseInfo() { + NOTIMPLEMENTED(); +} + +int URLRequestNewFtpJob::GetResponseCode() { + NOTIMPLEMENTED(); + return -1; +} + +bool URLRequestNewFtpJob::GetMoreData() { + NOTIMPLEMENTED(); + return false; +} + +bool URLRequestNewFtpJob::ReadRawData(net::IOBuffer* buf, + int buf_size, + int *bytes_read) { + NOTIMPLEMENTED(); + return false; +} + +void URLRequestNewFtpJob::OnStartCompleted(int result) { + NOTIMPLEMENTED(); +} + +void URLRequestNewFtpJob::OnReadCompleted(int result) { + NOTIMPLEMENTED(); +} + +void URLRequestNewFtpJob::DestroyTransaction() { + NOTIMPLEMENTED(); +} + +void URLRequestNewFtpJob::StartTransaction() { + NOTIMPLEMENTED(); +} diff --git a/net/url_request/url_request_new_ftp_job.h b/net/url_request/url_request_new_ftp_job.h new file mode 100644 index 0000000..79b165c --- /dev/null +++ b/net/url_request/url_request_new_ftp_job.h @@ -0,0 +1,60 @@ +// Copyright (c) 2009 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_URL_REQUEST_NEW_FTP_JOB_H_ +#define NET_URL_REQUEST_URL_REQUEST_NEW_FTP_JOB_H_ + +#include +#include + +#include "net/base/auth.h" +#include "net/base/completion_callback.h" +#include "net/url_request/url_request_job.h" + +class URLRequestContext; + +// A URLRequestJob subclass that is built on top of FtpTransaction. It +// provides an implementation for FTP. +class URLRequestNewFtpJob : public URLRequestJob { + public: + + explicit URLRequestNewFtpJob(URLRequest* request); + + virtual ~URLRequestNewFtpJob(); + + static URLRequestJob* Factory(URLRequest* request, const std::string& scheme); + + private: + // URLRequestJob methods: + virtual void Start(); + virtual void Kill(); + virtual uint64 GetUploadProgress() const; + virtual void GetResponseInfo(); + virtual int GetResponseCode(); + virtual bool GetMoreData(); + virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); + + void NotifyHeadersComplete(); + + void DestroyTransaction(); + void StartTransaction(); + + void OnStartCompleted(int result); + void OnReadCompleted(int result); + + net::AuthState server_auth_state_; + + net::CompletionCallbackImpl start_callback_; + net::CompletionCallbackImpl read_callback_; + + bool read_in_progress_; + + // Keep a reference to the url request context to be sure it's not deleted + // before us. + scoped_refptr context_; + + DISALLOW_COPY_AND_ASSIGN(URLRequestNewFtpJob); +}; + +#endif // NET_URL_REQUEST_URL_REQUEST_NEW_FTP_JOB_H_ -- cgit v1.1