Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / http / failing_http_transaction_factory.cc
blob89e5329d5d99bece047b8e9823dd4e4219c49122
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/location.h"
10 #include "base/logging.h"
11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "net/base/load_timing_info.h"
14 #include "net/base/upload_progress.h"
15 #include "net/http/http_response_info.h"
16 #include "net/socket/connection_attempts.h"
18 namespace net {
20 class AuthCredentials;
21 class BoundNetLog;
22 class HttpRequestHeaders;
23 class IOBuffer;
24 class X509Certificate;
26 namespace {
28 // A simple class to interpose between the cache and network http layers.
29 // These transactions can be generated by the FailingHttpTransactionFactory
30 // to test interactions between cache and network.
31 class FailingHttpTransaction : public HttpTransaction {
32 public:
33 explicit FailingHttpTransaction(Error error);
34 ~FailingHttpTransaction() override;
36 // HttpTransaction
37 int Start(const HttpRequestInfo* request_info,
38 const CompletionCallback& callback,
39 const BoundNetLog& net_log) override;
40 int RestartIgnoringLastError(const CompletionCallback& callback) override;
41 int RestartWithCertificate(X509Certificate* client_cert,
42 const CompletionCallback& callback) override;
43 int RestartWithAuth(const AuthCredentials& credentials,
44 const CompletionCallback& callback) override;
45 bool IsReadyToRestartForAuth() override;
46 int Read(IOBuffer* buf,
47 int buf_len,
48 const CompletionCallback& callback) override;
49 void StopCaching() override;
50 bool GetFullRequestHeaders(HttpRequestHeaders* headers) const override;
51 int64 GetTotalReceivedBytes() const override;
52 void DoneReading() override;
53 const HttpResponseInfo* GetResponseInfo() const override;
54 LoadState GetLoadState() const override;
55 UploadProgress GetUploadProgress() const override;
56 void SetQuicServerInfo(QuicServerInfo* quic_server_info) override;
57 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override;
58 void SetPriority(RequestPriority priority) override;
59 void SetWebSocketHandshakeStreamCreateHelper(
60 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override;
61 void SetBeforeNetworkStartCallback(
62 const BeforeNetworkStartCallback& callback) override;
63 void SetBeforeProxyHeadersSentCallback(
64 const BeforeProxyHeadersSentCallback& callback) override;
65 int ResumeNetworkStart() override;
66 void GetConnectionAttempts(ConnectionAttempts* out) const override;
68 private:
69 Error error_;
70 HttpResponseInfo response_;
73 FailingHttpTransaction::FailingHttpTransaction(Error error) : error_(error) {
74 DCHECK_LT(error, OK);
77 FailingHttpTransaction::~FailingHttpTransaction() {}
79 int FailingHttpTransaction::Start(const HttpRequestInfo* request_info,
80 const CompletionCallback& callback,
81 const BoundNetLog& net_log) {
82 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
83 base::Bind(callback, error_));
84 return ERR_IO_PENDING;
87 int FailingHttpTransaction::RestartIgnoringLastError(
88 const CompletionCallback& callback) {
89 return ERR_FAILED;
92 int FailingHttpTransaction::RestartWithCertificate(
93 X509Certificate* client_cert,
94 const CompletionCallback& callback) {
95 return ERR_FAILED;
98 int FailingHttpTransaction::RestartWithAuth(
99 const AuthCredentials& credentials,
100 const CompletionCallback& callback) {
101 return ERR_FAILED;
104 bool FailingHttpTransaction::IsReadyToRestartForAuth() {
105 return false;
108 int FailingHttpTransaction::Read(IOBuffer* buf, int buf_len,
109 const CompletionCallback& callback) {
110 NOTREACHED();
111 return ERR_FAILED;
114 void FailingHttpTransaction::StopCaching() {}
116 bool FailingHttpTransaction::GetFullRequestHeaders(
117 HttpRequestHeaders* headers) const {
118 return false;
121 int64 FailingHttpTransaction::GetTotalReceivedBytes() const {
122 return 0;
125 void FailingHttpTransaction::DoneReading() {
126 NOTREACHED();
129 const HttpResponseInfo* FailingHttpTransaction::GetResponseInfo() const {
130 return &response_;
133 LoadState FailingHttpTransaction::GetLoadState() const {
134 return LOAD_STATE_IDLE;
137 UploadProgress FailingHttpTransaction::GetUploadProgress() const {
138 return UploadProgress();
141 void FailingHttpTransaction::SetQuicServerInfo(
142 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 void FailingHttpTransaction::GetConnectionAttempts(
171 ConnectionAttempts* out) const {
172 NOTIMPLEMENTED();
175 } // namespace
177 FailingHttpTransactionFactory::FailingHttpTransactionFactory(
178 HttpNetworkSession* session,
179 Error error) : session_(session), error_(error) {
180 DCHECK_LT(error, OK);
183 FailingHttpTransactionFactory::~FailingHttpTransactionFactory() {}
185 // HttpTransactionFactory:
186 int FailingHttpTransactionFactory::CreateTransaction(
187 RequestPriority priority,
188 scoped_ptr<HttpTransaction>* trans) {
189 trans->reset(new FailingHttpTransaction(error_));
190 return OK;
193 HttpCache* FailingHttpTransactionFactory::GetCache() {
194 return NULL;
197 HttpNetworkSession* FailingHttpTransactionFactory::GetSession() {
198 return session_;
201 } // namespace net