Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / net / http / failing_http_transaction_factory.cc
bloba190597e369814f6d6a2635bcbd5e79b8dea23a1
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 ~FailingHttpTransaction() override;
34 // HttpTransaction
35 int Start(const HttpRequestInfo* request_info,
36 const CompletionCallback& callback,
37 const BoundNetLog& net_log) override;
38 int RestartIgnoringLastError(const CompletionCallback& callback) override;
39 int RestartWithCertificate(X509Certificate* client_cert,
40 const CompletionCallback& callback) override;
41 int RestartWithAuth(const AuthCredentials& credentials,
42 const CompletionCallback& callback) override;
43 bool IsReadyToRestartForAuth() override;
44 int Read(IOBuffer* buf,
45 int buf_len,
46 const CompletionCallback& callback) override;
47 void StopCaching() override;
48 bool GetFullRequestHeaders(HttpRequestHeaders* headers) const override;
49 int64 GetTotalReceivedBytes() const override;
50 void DoneReading() override;
51 const HttpResponseInfo* GetResponseInfo() const override;
52 LoadState GetLoadState() const override;
53 UploadProgress GetUploadProgress() const override;
54 void SetQuicServerInfo(QuicServerInfo* quic_server_info) override;
55 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override;
56 void SetPriority(RequestPriority priority) override;
57 void SetWebSocketHandshakeStreamCreateHelper(
58 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override;
59 void SetBeforeNetworkStartCallback(
60 const BeforeNetworkStartCallback& callback) override;
61 void SetBeforeProxyHeadersSentCallback(
62 const BeforeProxyHeadersSentCallback& callback) override;
63 int ResumeNetworkStart() override;
65 private:
66 Error error_;
69 FailingHttpTransaction::FailingHttpTransaction(Error error) : error_(error) {
70 DCHECK_LT(error, OK);
73 FailingHttpTransaction::~FailingHttpTransaction() {}
75 int FailingHttpTransaction::Start(const HttpRequestInfo* request_info,
76 const CompletionCallback& callback,
77 const BoundNetLog& net_log) {
78 base::MessageLoop::current()->PostTask(
79 FROM_HERE, base::Bind(callback, error_));
80 return ERR_IO_PENDING;
83 int FailingHttpTransaction::RestartIgnoringLastError(
84 const CompletionCallback& callback) {
85 return ERR_FAILED;
88 int FailingHttpTransaction::RestartWithCertificate(
89 X509Certificate* client_cert,
90 const CompletionCallback& callback) {
91 return ERR_FAILED;
94 int FailingHttpTransaction::RestartWithAuth(
95 const AuthCredentials& credentials,
96 const CompletionCallback& callback) {
97 return ERR_FAILED;
100 bool FailingHttpTransaction::IsReadyToRestartForAuth() {
101 return false;
104 int FailingHttpTransaction::Read(IOBuffer* buf, int buf_len,
105 const CompletionCallback& callback) {
106 NOTREACHED();
107 return ERR_FAILED;
110 void FailingHttpTransaction::StopCaching() {}
112 bool FailingHttpTransaction::GetFullRequestHeaders(
113 HttpRequestHeaders* headers) const {
114 return false;
117 int64 FailingHttpTransaction::GetTotalReceivedBytes() const {
118 return 0;
121 void FailingHttpTransaction::DoneReading() {
122 NOTREACHED();
125 const HttpResponseInfo* FailingHttpTransaction::GetResponseInfo() const {
126 return NULL;
129 LoadState FailingHttpTransaction::GetLoadState() const {
130 return LOAD_STATE_IDLE;
133 UploadProgress FailingHttpTransaction::GetUploadProgress() const {
134 return UploadProgress();
137 void FailingHttpTransaction::SetQuicServerInfo(
138 QuicServerInfo* quic_server_info) {
141 bool FailingHttpTransaction::GetLoadTimingInfo(
142 LoadTimingInfo* load_timing_info) const {
143 return false;
146 void FailingHttpTransaction::SetPriority(RequestPriority priority) {}
148 void FailingHttpTransaction::SetWebSocketHandshakeStreamCreateHelper(
149 WebSocketHandshakeStreamBase::CreateHelper* create_helper) {
150 NOTREACHED();
153 void FailingHttpTransaction::SetBeforeNetworkStartCallback(
154 const BeforeNetworkStartCallback& callback) {
157 void FailingHttpTransaction::SetBeforeProxyHeadersSentCallback(
158 const BeforeProxyHeadersSentCallback& callback) {
161 int FailingHttpTransaction::ResumeNetworkStart() {
162 NOTREACHED();
163 return ERR_FAILED;
166 } // namespace
168 FailingHttpTransactionFactory::FailingHttpTransactionFactory(
169 HttpNetworkSession* session,
170 Error error) : session_(session), error_(error) {
171 DCHECK_LT(error, OK);
174 FailingHttpTransactionFactory::~FailingHttpTransactionFactory() {}
176 // HttpTransactionFactory:
177 int FailingHttpTransactionFactory::CreateTransaction(
178 RequestPriority priority,
179 scoped_ptr<HttpTransaction>* trans) {
180 trans->reset(new FailingHttpTransaction(error_));
181 return OK;
184 HttpCache* FailingHttpTransactionFactory::GetCache() {
185 return NULL;
188 HttpNetworkSession* FailingHttpTransactionFactory::GetSession() {
189 return session_;
192 } // namespace net