Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / net / http / failing_http_transaction_factory.cc
blob07023f205fb52f6c62c586201136a52089b8e5ff
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"
13 #include "net/http/http_response_info.h"
14 #include "net/socket/connection_attempts.h"
16 namespace net {
18 class AuthCredentials;
19 class BoundNetLog;
20 class HttpRequestHeaders;
21 class IOBuffer;
22 class X509Certificate;
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;
64 void GetConnectionAttempts(ConnectionAttempts* out) const override;
66 private:
67 Error error_;
68 HttpResponseInfo response_;
71 FailingHttpTransaction::FailingHttpTransaction(Error error) : error_(error) {
72 DCHECK_LT(error, OK);
75 FailingHttpTransaction::~FailingHttpTransaction() {}
77 int FailingHttpTransaction::Start(const HttpRequestInfo* request_info,
78 const CompletionCallback& callback,
79 const BoundNetLog& net_log) {
80 base::MessageLoop::current()->PostTask(
81 FROM_HERE, base::Bind(callback, error_));
82 return ERR_IO_PENDING;
85 int FailingHttpTransaction::RestartIgnoringLastError(
86 const CompletionCallback& callback) {
87 return ERR_FAILED;
90 int FailingHttpTransaction::RestartWithCertificate(
91 X509Certificate* client_cert,
92 const CompletionCallback& callback) {
93 return ERR_FAILED;
96 int FailingHttpTransaction::RestartWithAuth(
97 const AuthCredentials& credentials,
98 const CompletionCallback& callback) {
99 return ERR_FAILED;
102 bool FailingHttpTransaction::IsReadyToRestartForAuth() {
103 return false;
106 int FailingHttpTransaction::Read(IOBuffer* buf, int buf_len,
107 const CompletionCallback& callback) {
108 NOTREACHED();
109 return ERR_FAILED;
112 void FailingHttpTransaction::StopCaching() {}
114 bool FailingHttpTransaction::GetFullRequestHeaders(
115 HttpRequestHeaders* headers) const {
116 return false;
119 int64 FailingHttpTransaction::GetTotalReceivedBytes() const {
120 return 0;
123 void FailingHttpTransaction::DoneReading() {
124 NOTREACHED();
127 const HttpResponseInfo* FailingHttpTransaction::GetResponseInfo() const {
128 return &response_;
131 LoadState FailingHttpTransaction::GetLoadState() const {
132 return LOAD_STATE_IDLE;
135 UploadProgress FailingHttpTransaction::GetUploadProgress() const {
136 return UploadProgress();
139 void FailingHttpTransaction::SetQuicServerInfo(
140 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 void FailingHttpTransaction::SetBeforeProxyHeadersSentCallback(
160 const BeforeProxyHeadersSentCallback& callback) {
163 int FailingHttpTransaction::ResumeNetworkStart() {
164 NOTREACHED();
165 return ERR_FAILED;
168 void FailingHttpTransaction::GetConnectionAttempts(
169 ConnectionAttempts* out) const {
170 NOTIMPLEMENTED();
173 } // namespace
175 FailingHttpTransactionFactory::FailingHttpTransactionFactory(
176 HttpNetworkSession* session,
177 Error error) : session_(session), error_(error) {
178 DCHECK_LT(error, OK);
181 FailingHttpTransactionFactory::~FailingHttpTransactionFactory() {}
183 // HttpTransactionFactory:
184 int FailingHttpTransactionFactory::CreateTransaction(
185 RequestPriority priority,
186 scoped_ptr<HttpTransaction>* trans) {
187 trans->reset(new FailingHttpTransaction(error_));
188 return OK;
191 HttpCache* FailingHttpTransactionFactory::GetCache() {
192 return NULL;
195 HttpNetworkSession* FailingHttpTransactionFactory::GetSession() {
196 return session_;
199 } // namespace net