[Presentation API, Android] Implement basic messaging
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_network_transaction.h
blob826b0025f689ec4b55e18d293059c54603c5d14e
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 static const char kDevToolsRequestInitiator[];
45 static const char kDevToolsEmulateNetworkConditionsClientId[];
47 DevToolsNetworkTransaction(
48 DevToolsNetworkController* controller,
49 scoped_ptr<net::HttpTransaction> network_transaction);
51 ~DevToolsNetworkTransaction() override;
53 const net::HttpRequestInfo* request() const { return request_; }
55 // Checks if request contains DevTools specific headers. Found values are
56 // remembered and corresponding keys are removed from headers.
57 void ProcessRequest();
59 bool failed() const { return failed_; }
61 // Runs callback (if any) with net::ERR_INTERNET_DISCONNECTED result value.
62 void Fail();
64 int64_t throttled_byte_count() const { return throttled_byte_count_; }
65 void DecreaseThrottledByteCount(int64_t delta) {
66 throttled_byte_count_ -= delta;
69 const std::string& request_initiator() const { return request_initiator_; }
71 const std::string& client_id() const {
72 return client_id_;
75 void FireThrottledCallback();
77 // HttpTransaction methods:
78 int Start(const net::HttpRequestInfo* request,
79 const net::CompletionCallback& callback,
80 const net::BoundNetLog& net_log) override;
81 int RestartIgnoringLastError(
82 const net::CompletionCallback& callback) override;
83 int RestartWithCertificate(net::X509Certificate* client_cert,
84 const net::CompletionCallback& callback) override;
85 int RestartWithAuth(const net::AuthCredentials& credentials,
86 const net::CompletionCallback& callback) override;
87 bool IsReadyToRestartForAuth() override;
89 int Read(net::IOBuffer* buf,
90 int buf_len,
91 const net::CompletionCallback& callback) override;
92 void StopCaching() override;
93 bool GetFullRequestHeaders(net::HttpRequestHeaders* headers) const override;
94 int64 GetTotalReceivedBytes() const override;
95 void DoneReading() override;
96 const net::HttpResponseInfo* GetResponseInfo() const override;
97 net::LoadState GetLoadState() const override;
98 net::UploadProgress GetUploadProgress() const override;
99 void SetQuicServerInfo(net::QuicServerInfo* quic_server_info) override;
100 bool GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override;
101 void SetPriority(net::RequestPriority priority) override;
102 void SetWebSocketHandshakeStreamCreateHelper(
103 net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) override;
104 void SetBeforeNetworkStartCallback(
105 const BeforeNetworkStartCallback& callback) override;
106 void SetBeforeProxyHeadersSentCallback(
107 const BeforeProxyHeadersSentCallback& callback) override;
108 int ResumeNetworkStart() override;
109 void GetConnectionAttempts(net::ConnectionAttempts* out) const override;
111 protected:
112 friend class test::DevToolsNetworkControllerHelper;
114 private:
115 // Proxy callback handler. Runs saved callback.
116 void OnCallback(int result);
118 DevToolsNetworkController* controller_;
119 base::WeakPtr<DevToolsNetworkInterceptor> interceptor_;
121 // Modified request. Should be destructed after |network_transaction_|
122 scoped_ptr<net::HttpRequestInfo> custom_request_;
124 // Real network transaction.
125 scoped_ptr<net::HttpTransaction> network_transaction_;
127 const net::HttpRequestInfo* request_;
129 // True if Fail was already invoked.
130 bool failed_;
132 // Value of "X-DevTools-Request-Initiator" request header.
133 std::string request_initiator_;
135 // Value of "X-DevTools-Emulate-Network-Conditions-Client-Id" request header.
136 std::string client_id_;
138 enum CallbackType {
139 NONE,
140 READ,
141 RESTART_IGNORING_LAST_ERROR,
142 RESTART_WITH_AUTH,
143 RESTART_WITH_CERTIFICATE,
144 START
147 int SetupCallback(
148 net::CompletionCallback callback,
149 int result,
150 CallbackType callback_type);
152 void Throttle(int result);
154 int throttled_result_;
155 int64_t throttled_byte_count_;
156 CallbackType callback_type_;
157 net::CompletionCallback proxy_callback_;
158 net::CompletionCallback callback_;
160 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransaction);
163 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_