Commit 2ab7450f authored by evan@chromium.org's avatar evan@chromium.org

Delete url_request_mock_net_error_job.*.

As far as I can tell this code is unreferenced in the Chrome tree,
and dates back to the initial commit.

Review URL: http://codereview.chromium.org/7491100

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95854 0039d316-1c4b-4281-b951-d872f2087c98
parent 5a395b78
...@@ -198,8 +198,6 @@ ...@@ -198,8 +198,6 @@
# production code code in libbrowser (in chrome.gyp). # production code code in libbrowser (in chrome.gyp).
#'../content/browser/net/url_request_mock_http_job.cc', #'../content/browser/net/url_request_mock_http_job.cc',
#'../content/browser/net/url_request_mock_http_job.h', #'../content/browser/net/url_request_mock_http_job.h',
'../content/browser/net/url_request_mock_net_error_job.cc',
'../content/browser/net/url_request_mock_net_error_job.h',
'../content/browser/renderer_host/media/mock_media_observer.cc', '../content/browser/renderer_host/media/mock_media_observer.cc',
'../content/browser/renderer_host/media/mock_media_observer.h', '../content/browser/renderer_host/media/mock_media_observer.h',
'../content/browser/renderer_host/mock_render_process_host.cc', '../content/browser/renderer_host/mock_render_process_host.cc',
......
// Copyright (c) 2011 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 "content/browser/net/url_request_mock_net_error_job.h"
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/task.h"
#include "base/utf_string_conversions.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/base/x509_certificate.h"
#include "net/url_request/url_request_filter.h"
// static
URLRequestMockNetErrorJob::URLMockInfoMap
URLRequestMockNetErrorJob::url_mock_info_map_;
struct URLRequestMockNetErrorJob::MockInfo {
MockInfo() : ssl_cert(NULL) { }
MockInfo(std::wstring base,
std::vector<int> errors,
net::X509Certificate* ssl_cert)
: base(base),
errors(errors),
ssl_cert(ssl_cert) { }
std::wstring base;
std::vector<int> errors;
scoped_refptr<net::X509Certificate> ssl_cert;
};
// static
void URLRequestMockNetErrorJob::AddMockedURL(const GURL& url,
const std::wstring& base,
const std::vector<int>& errors,
net::X509Certificate* ssl_cert) {
#ifndef NDEBUG
URLMockInfoMap::const_iterator iter = url_mock_info_map_.find(url);
DCHECK(iter == url_mock_info_map_.end());
#endif
url_mock_info_map_[url] = MockInfo(base, errors, ssl_cert);
net::URLRequestFilter::GetInstance()
->AddUrlHandler(url, &URLRequestMockNetErrorJob::Factory);
}
// static
void URLRequestMockNetErrorJob::RemoveMockedURL(const GURL& url) {
URLMockInfoMap::iterator iter = url_mock_info_map_.find(url);
DCHECK(iter != url_mock_info_map_.end());
url_mock_info_map_.erase(iter);
net::URLRequestFilter::GetInstance()->RemoveUrlHandler(url);
}
// static
net::URLRequestJob* URLRequestMockNetErrorJob::Factory(
net::URLRequest* request,
const std::string& scheme) {
GURL url = request->url();
URLMockInfoMap::const_iterator iter = url_mock_info_map_.find(url);
DCHECK(iter != url_mock_info_map_.end());
MockInfo mock_info = iter->second;
// URLRequestMockNetErrorJob derives from net::URLRequestFileJob. We pass a
// FilePath so that the net::URLRequestFileJob methods will do the loading
// from the files.
std::wstring file_url(L"file:///");
file_url.append(mock_info.base);
file_url.append(UTF8ToWide(url.path()));
// Convert the file:/// URL to a path on disk.
FilePath file_path;
net::FileURLToFilePath(GURL(WideToUTF8(file_url)), &file_path);
return new URLRequestMockNetErrorJob(request, mock_info.errors,
mock_info.ssl_cert,
file_path);
}
URLRequestMockNetErrorJob::URLRequestMockNetErrorJob(net::URLRequest* request,
const std::vector<int>& errors, net::X509Certificate* cert,
const FilePath& file_path)
: URLRequestMockHTTPJob(request, file_path),
errors_(errors),
ssl_cert_(cert),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
}
URLRequestMockNetErrorJob::~URLRequestMockNetErrorJob() {
}
void URLRequestMockNetErrorJob::Start() {
MessageLoop::current()->PostTask(
FROM_HERE,
method_factory_.NewRunnableMethod(
&URLRequestMockNetErrorJob::StartAsync));
}
void URLRequestMockNetErrorJob::StartAsync() {
if (errors_.empty()) {
URLRequestMockHTTPJob::Start();
} else {
int error = errors_[0];
errors_.erase(errors_.begin());
if (net::IsCertificateError(error)) {
DCHECK(ssl_cert_);
NotifySSLCertificateError(error, ssl_cert_.get());
} else {
NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
error));
}
}
}
void URLRequestMockNetErrorJob::ContinueDespiteLastError() {
Start();
}
// Copyright (c) 2011 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.
// A net::URLRequestJob class that simulates network errors (including https
// related).
// It is based on URLRequestMockHttpJob.
#ifndef CONTENT_BROWSER_NET_URL_REQUEST_MOCK_NET_ERROR_JOB_H_
#define CONTENT_BROWSER_NET_URL_REQUEST_MOCK_NET_ERROR_JOB_H_
#pragma once
#include "base/task.h"
#include "content/browser/net/url_request_mock_http_job.h"
class URLRequestMockNetErrorJob : public URLRequestMockHTTPJob {
public:
URLRequestMockNetErrorJob(net::URLRequest* request,
const std::vector<int>& errors,
net::X509Certificate* ssl_cert,
const FilePath& file_path);
virtual void Start();
virtual void ContinueDespiteLastError();
// Add the specified URL to the list of URLs that should be mocked. When this
// URL is hit, the specified |errors| will be played. If any of these errors
// is a cert error, |ssl_cert| will be used as the ssl cert when notifying of
// the error. |ssl_cert| can be NULL if |errors| does not contain any cert
// errors. |base| is the location on disk where the file mocking the URL
// contents and http-headers should be retrieved from.
static void AddMockedURL(const GURL& url,
const std::wstring& base,
const std::vector<int>& errors,
net::X509Certificate* ssl_cert);
// Removes the specified |url| from the list of mocked urls.
static void RemoveMockedURL(const GURL& url);
private:
virtual ~URLRequestMockNetErrorJob();
static net::URLRequest::ProtocolFactory Factory;
void StartAsync();
// The errors to simulate.
std::vector<int> errors_;
// The certificate to use for SSL errors.
scoped_refptr<net::X509Certificate> ssl_cert_;
struct MockInfo;
typedef std::map<GURL, MockInfo> URLMockInfoMap;
static URLMockInfoMap url_mock_info_map_;
ScopedRunnableMethodFactory<URLRequestMockNetErrorJob> method_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestMockNetErrorJob);
};
#endif // CONTENT_BROWSER_NET_URL_REQUEST_MOCK_NET_ERROR_JOB_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment