Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / net / http / failing_http_transaction_factory.cc
blob23a184f1bd3fb7576dc4ace294104df942bfff06
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 void SetBeforeProxyHeadersSentCallback(
67 const BeforeProxyHeadersSentCallback& callback) OVERRIDE;
68 virtual int ResumeNetworkStart() OVERRIDE;
70 private:
71 Error error_;
74 FailingHttpTransaction::FailingHttpTransaction(Error error) : error_(error) {
75 DCHECK_LT(error, OK);
78 FailingHttpTransaction::~FailingHttpTransaction() {}
80 int FailingHttpTransaction::Start(const HttpRequestInfo* request_info,
81 const CompletionCallback& callback,
82 const BoundNetLog& net_log) {
83 base::MessageLoop::current()->PostTask(
84 FROM_HERE, base::Bind(callback, error_));
85 return ERR_IO_PENDING;
88 int FailingHttpTransaction::RestartIgnoringLastError(
89 const CompletionCallback& callback) {
90 return ERR_FAILED;
93 int FailingHttpTransaction::RestartWithCertificate(
94 X509Certificate* client_cert,
95 const CompletionCallback& callback) {
96 return ERR_FAILED;
99 int FailingHttpTransaction::RestartWithAuth(
100 const AuthCredentials& credentials,
101 const CompletionCallback& callback) {
102 return ERR_FAILED;
105 bool FailingHttpTransaction::IsReadyToRestartForAuth() {
106 return false;
109 int FailingHttpTransaction::Read(IOBuffer* buf, int buf_len,
110 const CompletionCallback& callback) {
111 NOTREACHED();
112 return ERR_FAILED;
115 void FailingHttpTransaction::StopCaching() {}
117 bool FailingHttpTransaction::GetFullRequestHeaders(
118 HttpRequestHeaders* headers) const {
119 return false;
122 int64 FailingHttpTransaction::GetTotalReceivedBytes() const {
123 return 0;
126 void FailingHttpTransaction::DoneReading() {
127 NOTREACHED();
130 const HttpResponseInfo* FailingHttpTransaction::GetResponseInfo() const {
131 return NULL;
134 LoadState FailingHttpTransaction::GetLoadState() const {
135 return LOAD_STATE_IDLE;
138 UploadProgress FailingHttpTransaction::GetUploadProgress() const {
139 return UploadProgress();
142 void FailingHttpTransaction::SetQuicServerInfo(
143 net::QuicServerInfo* quic_server_info) {}
145 bool FailingHttpTransaction::GetLoadTimingInfo(
146 LoadTimingInfo* load_timing_info) const {
147 return false;
150 void FailingHttpTransaction::SetPriority(RequestPriority priority) {}
152 void FailingHttpTransaction::SetWebSocketHandshakeStreamCreateHelper(
153 WebSocketHandshakeStreamBase::CreateHelper* create_helper) {
154 NOTREACHED();
157 void FailingHttpTransaction::SetBeforeNetworkStartCallback(
158 const BeforeNetworkStartCallback& callback) {
161 void FailingHttpTransaction::SetBeforeProxyHeadersSentCallback(
162 const BeforeProxyHeadersSentCallback& callback) {
165 int FailingHttpTransaction::ResumeNetworkStart() {
166 NOTREACHED();
167 return ERR_FAILED;
170 } // namespace
172 FailingHttpTransactionFactory::FailingHttpTransactionFactory(
173 HttpNetworkSession* session,
174 Error error) : session_(session), error_(error) {
175 DCHECK_LT(error, OK);
178 FailingHttpTransactionFactory::~FailingHttpTransactionFactory() {}
180 // HttpTransactionFactory:
181 int FailingHttpTransactionFactory::CreateTransaction(
182 RequestPriority priority,
183 scoped_ptr<HttpTransaction>* trans) {
184 trans->reset(new FailingHttpTransaction(error_));
185 return OK;
188 HttpCache* FailingHttpTransactionFactory::GetCache() {
189 return NULL;
192 HttpNetworkSession* FailingHttpTransactionFactory::GetSession() {
193 return session_;
196 } // namespace net