Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / net / http / failing_http_transaction_factory.cc
blobdfe78f24011636df1e3a4a9f946d7c66846db7c0
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(net::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 net::QuicServerInfo* quic_server_info) {}
140 bool FailingHttpTransaction::GetLoadTimingInfo(
141 LoadTimingInfo* load_timing_info) const {
142 return false;
145 void FailingHttpTransaction::SetPriority(RequestPriority priority) {}
147 void FailingHttpTransaction::SetWebSocketHandshakeStreamCreateHelper(
148 WebSocketHandshakeStreamBase::CreateHelper* create_helper) {
149 NOTREACHED();
152 void FailingHttpTransaction::SetBeforeNetworkStartCallback(
153 const BeforeNetworkStartCallback& callback) {
156 void FailingHttpTransaction::SetBeforeProxyHeadersSentCallback(
157 const BeforeProxyHeadersSentCallback& callback) {
160 int FailingHttpTransaction::ResumeNetworkStart() {
161 NOTREACHED();
162 return ERR_FAILED;
165 } // namespace
167 FailingHttpTransactionFactory::FailingHttpTransactionFactory(
168 HttpNetworkSession* session,
169 Error error) : session_(session), error_(error) {
170 DCHECK_LT(error, OK);
173 FailingHttpTransactionFactory::~FailingHttpTransactionFactory() {}
175 // HttpTransactionFactory:
176 int FailingHttpTransactionFactory::CreateTransaction(
177 RequestPriority priority,
178 scoped_ptr<HttpTransaction>* trans) {
179 trans->reset(new FailingHttpTransaction(error_));
180 return OK;
183 HttpCache* FailingHttpTransactionFactory::GetCache() {
184 return NULL;
187 HttpNetworkSession* FailingHttpTransactionFactory::GetSession() {
188 return session_;
191 } // namespace net