Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_network_transaction.h
blobcbc085adfba120af830f4681752bee67fa59a8b3
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 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "net/base/completion_callback.h"
11 #include "net/base/load_states.h"
12 #include "net/base/request_priority.h"
13 #include "net/http/http_transaction.h"
14 #include "net/websockets/websocket_handshake_stream_base.h"
16 class DevToolsNetworkController;
17 class DevToolsNetworkInterceptor;
18 class GURL;
20 namespace net {
21 class AuthCredentials;
22 class BoundNetLog;
23 class HttpRequestHeaders;
24 struct HttpRequestInfo;
25 class HttpResponseInfo;
26 class HttpNetworkSession;
27 class IOBuffer;
28 struct LoadTimingInfo;
29 class UploadProgress;
30 class X509Certificate;
31 } // namespace net
33 namespace test {
34 class DevToolsNetworkControllerHelper;
37 // DevToolsNetworkTransaction is a wrapper for network transaction. All
38 // HttpTransaction methods are proxied to real transaction, but |callback|
39 // parameter is saved and replaced with proxy callback. Fail method should be
40 // used to simulate network outage. It runs saved callback (if any) with
41 // net::ERR_INTERNET_DISCONNECTED result value.
42 class DevToolsNetworkTransaction : public net::HttpTransaction {
43 public:
44 DevToolsNetworkTransaction(
45 DevToolsNetworkController* controller,
46 scoped_ptr<net::HttpTransaction> network_transaction);
48 virtual ~DevToolsNetworkTransaction();
50 const net::HttpRequestInfo* request() const { return request_; }
52 // Checks if request contains DevTools specific headers. Found values are
53 // remembered and corresponding keys are removed from headers.
54 void ProcessRequest();
56 bool failed() const { return failed_; }
58 // Runs callback (if any) with net::ERR_INTERNET_DISCONNECTED result value.
59 void Fail();
61 int64_t throttled_byte_count() const { return throttled_byte_count_; }
62 void DecreaseThrottledByteCount(int64_t delta) {
63 throttled_byte_count_ -= delta;
66 const std::string& request_initiator() const { return request_initiator_; }
68 const std::string& client_id() const {
69 return client_id_;
72 void FireThrottledCallback();
74 // HttpTransaction methods:
75 virtual int Start(
76 const net::HttpRequestInfo* request,
77 const net::CompletionCallback& callback,
78 const net::BoundNetLog& net_log) OVERRIDE;
79 virtual int RestartIgnoringLastError(
80 const net::CompletionCallback& callback) OVERRIDE;
81 virtual int RestartWithCertificate(
82 net::X509Certificate* client_cert,
83 const net::CompletionCallback& callback) OVERRIDE;
84 virtual int RestartWithAuth(
85 const net::AuthCredentials& credentials,
86 const net::CompletionCallback& callback) OVERRIDE;
87 virtual bool IsReadyToRestartForAuth() OVERRIDE;
89 virtual int Read(
90 net::IOBuffer* buf,
91 int buf_len,
92 const net::CompletionCallback& callback) OVERRIDE;
93 virtual void StopCaching() OVERRIDE;
94 virtual bool GetFullRequestHeaders(
95 net::HttpRequestHeaders* headers) const OVERRIDE;
96 virtual int64 GetTotalReceivedBytes() const OVERRIDE;
97 virtual void DoneReading() OVERRIDE;
98 virtual const net::HttpResponseInfo* GetResponseInfo() const OVERRIDE;
99 virtual net::LoadState GetLoadState() const OVERRIDE;
100 virtual net::UploadProgress GetUploadProgress() const OVERRIDE;
101 virtual void SetQuicServerInfo(
102 net::QuicServerInfo* quic_server_info) OVERRIDE;
103 virtual bool GetLoadTimingInfo(
104 net::LoadTimingInfo* load_timing_info) const OVERRIDE;
105 virtual void SetPriority(net::RequestPriority priority) OVERRIDE;
106 virtual void SetWebSocketHandshakeStreamCreateHelper(
107 net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) OVERRIDE;
108 virtual void SetBeforeNetworkStartCallback(
109 const BeforeNetworkStartCallback& callback) OVERRIDE;
110 virtual void SetBeforeProxyHeadersSentCallback(
111 const BeforeProxyHeadersSentCallback& callback) OVERRIDE;
112 virtual int ResumeNetworkStart() OVERRIDE;
114 protected:
115 friend class test::DevToolsNetworkControllerHelper;
117 private:
118 // Proxy callback handler. Runs saved callback.
119 void OnCallback(int result);
121 DevToolsNetworkController* controller_;
122 base::WeakPtr<DevToolsNetworkInterceptor> interceptor_;
124 // Modified request. Should be destructed after |network_transaction_|
125 scoped_ptr<net::HttpRequestInfo> custom_request_;
127 // Real network transaction.
128 scoped_ptr<net::HttpTransaction> network_transaction_;
130 const net::HttpRequestInfo* request_;
132 // True if Start was already invoked.
133 bool started_;
135 // True if Fail was already invoked.
136 bool failed_;
138 // Value of "X-DevTools-Request-Initiator" request header.
139 std::string request_initiator_;
141 // Value of "X-DevTools-Emulate-Network-Conditions-Client-Id" request header.
142 std::string client_id_;
144 enum CallbackType {
145 NONE,
146 READ,
147 RESTART_IGNORING_LAST_ERROR,
148 RESTART_WITH_AUTH,
149 RESTART_WITH_CERTIFICATE,
150 START
153 int SetupCallback(
154 net::CompletionCallback callback,
155 int result,
156 CallbackType callback_type);
158 void Throttle(int result);
160 int throttled_result_;
161 int64_t throttled_byte_count_;
162 CallbackType callback_type_;
163 net::CompletionCallback proxy_callback_;
164 net::CompletionCallback callback_;
166 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransaction);
169 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_