Revert 254567 "don't create SkDevice directly, use SkBitmap or (..."
[chromium-blink-merge.git] / net / http / failing_http_transaction_factory.cc
blobd1d1612966d7eb67372bab24d28a176d43603534
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/http/failing_http_transaction_factory.h"
7 #include "base/bind.h"
8 #include "base/compiler_specific.h"
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "net/base/load_timing_info.h"
12 #include "net/base/upload_progress.h"
14 namespace net {
16 class AuthCredentials;
17 class BoundNetLog;
18 class HttpRequestHeaders;
19 class IOBuffer;
20 class X509Certificate;
22 struct HttpRequestInfo;
24 namespace {
26 // A simple class to interpose between the cache and network http layers.
27 // These transactions can be generated by the FailingHttpTransactionFactory
28 // to test interactions between cache and network.
29 class FailingHttpTransaction : public HttpTransaction {
30 public:
31 explicit FailingHttpTransaction(Error error);
32 virtual ~FailingHttpTransaction();
34 // HttpTransaction
35 virtual int Start(const HttpRequestInfo* request_info,
36 const CompletionCallback& callback,
37 const BoundNetLog& net_log) OVERRIDE;
38 virtual int RestartIgnoringLastError(
39 const CompletionCallback& callback) OVERRIDE;
40 virtual int RestartWithCertificate(
41 X509Certificate* client_cert,
42 const CompletionCallback& callback) OVERRIDE;
43 virtual int RestartWithAuth(
44 const AuthCredentials& credentials,
45 const CompletionCallback& callback) OVERRIDE;
46 virtual bool IsReadyToRestartForAuth() OVERRIDE;
47 virtual int Read(IOBuffer* buf, int buf_len,
48 const CompletionCallback& callback) OVERRIDE;
49 virtual void StopCaching() OVERRIDE;
50 virtual bool GetFullRequestHeaders(
51 HttpRequestHeaders* headers) const OVERRIDE;
52 virtual int64 GetTotalReceivedBytes() const OVERRIDE;
53 virtual void DoneReading() OVERRIDE;
54 virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
55 virtual LoadState GetLoadState() const OVERRIDE;
56 virtual UploadProgress GetUploadProgress() const OVERRIDE;
57 virtual void SetQuicServerInfo(
58 net::QuicServerInfo* quic_server_info) OVERRIDE;
59 virtual bool GetLoadTimingInfo(
60 LoadTimingInfo* load_timing_info) const OVERRIDE;
61 virtual void SetPriority(RequestPriority priority) OVERRIDE;
62 virtual void SetWebSocketHandshakeStreamCreateHelper(
63 WebSocketHandshakeStreamBase::CreateHelper* create_helper) OVERRIDE;
64 virtual void SetBeforeNetworkStartCallback(
65 const BeforeNetworkStartCallback& callback) OVERRIDE;
66 virtual int ResumeNetworkStart() OVERRIDE;
68 private:
69 Error error_;
72 FailingHttpTransaction::FailingHttpTransaction(Error error) : error_(error) {
73 DCHECK_LT(error, OK);
76 FailingHttpTransaction::~FailingHttpTransaction() {}
78 int FailingHttpTransaction::Start(const HttpRequestInfo* request_info,
79 const CompletionCallback& callback,
80 const BoundNetLog& net_log) {
81 base::MessageLoop::current()->PostTask(
82 FROM_HERE, base::Bind(callback, error_));
83 return ERR_IO_PENDING;
86 int FailingHttpTransaction::RestartIgnoringLastError(
87 const CompletionCallback& callback) {
88 return ERR_FAILED;
91 int FailingHttpTransaction::RestartWithCertificate(
92 X509Certificate* client_cert,
93 const CompletionCallback& callback) {
94 return ERR_FAILED;
97 int FailingHttpTransaction::RestartWithAuth(
98 const AuthCredentials& credentials,
99 const CompletionCallback& callback) {
100 return ERR_FAILED;
103 bool FailingHttpTransaction::IsReadyToRestartForAuth() {
104 return false;
107 int FailingHttpTransaction::Read(IOBuffer* buf, int buf_len,
108 const CompletionCallback& callback) {
109 NOTREACHED();
110 return ERR_FAILED;
113 void FailingHttpTransaction::StopCaching() {}
115 bool FailingHttpTransaction::GetFullRequestHeaders(
116 HttpRequestHeaders* headers) const {
117 return false;
120 int64 FailingHttpTransaction::GetTotalReceivedBytes() const {
121 return 0;
124 void FailingHttpTransaction::DoneReading() {
125 NOTREACHED();
128 const HttpResponseInfo* FailingHttpTransaction::GetResponseInfo() const {
129 return NULL;
132 LoadState FailingHttpTransaction::GetLoadState() const {
133 return LOAD_STATE_IDLE;
136 UploadProgress FailingHttpTransaction::GetUploadProgress() const {
137 return UploadProgress();
140 void FailingHttpTransaction::SetQuicServerInfo(
141 net::QuicServerInfo* quic_server_info) {}
143 bool FailingHttpTransaction::GetLoadTimingInfo(
144 LoadTimingInfo* load_timing_info) const {
145 return false;
148 void FailingHttpTransaction::SetPriority(RequestPriority priority) {}
150 void FailingHttpTransaction::SetWebSocketHandshakeStreamCreateHelper(
151 WebSocketHandshakeStreamBase::CreateHelper* create_helper) {
152 NOTREACHED();
155 void FailingHttpTransaction::SetBeforeNetworkStartCallback(
156 const BeforeNetworkStartCallback& callback) {
159 int FailingHttpTransaction::ResumeNetworkStart() {
160 NOTREACHED();
161 return ERR_FAILED;
164 } // namespace
166 FailingHttpTransactionFactory::FailingHttpTransactionFactory(
167 HttpNetworkSession* session,
168 Error error) : session_(session), error_(error) {
169 DCHECK_LT(error, OK);
172 FailingHttpTransactionFactory::~FailingHttpTransactionFactory() {}
174 // HttpTransactionFactory:
175 int FailingHttpTransactionFactory::CreateTransaction(
176 RequestPriority priority,
177 scoped_ptr<HttpTransaction>* trans) {
178 trans->reset(new FailingHttpTransaction(error_));
179 return OK;
182 HttpCache* FailingHttpTransactionFactory::GetCache() {
183 return NULL;
186 HttpNetworkSession* FailingHttpTransactionFactory::GetSession() {
187 return session_;
190 } // namespace net