Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: chrome/browser/devtools/devtools_network_transaction.h

Issue 342473004: DevTools: make network conditions emulation scoped (browser) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_ 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_ 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
9 #include "net/base/completion_callback.h" 10 #include "net/base/completion_callback.h"
10 #include "net/base/load_states.h" 11 #include "net/base/load_states.h"
11 #include "net/base/request_priority.h" 12 #include "net/base/request_priority.h"
12 #include "net/http/http_transaction.h" 13 #include "net/http/http_transaction.h"
13 #include "net/websockets/websocket_handshake_stream_base.h" 14 #include "net/websockets/websocket_handshake_stream_base.h"
14 15
15 class DevToolsNetworkController; 16 class DevToolsNetworkController;
17 class DevToolsNetworkInterceptor;
16 class GURL; 18 class GURL;
17 19
18 namespace net { 20 namespace net {
19 class AuthCredentials; 21 class AuthCredentials;
20 class BoundNetLog; 22 class BoundNetLog;
21 class HttpRequestHeaders; 23 class HttpRequestHeaders;
22 struct HttpRequestInfo; 24 struct HttpRequestInfo;
23 class HttpResponseInfo; 25 class HttpResponseInfo;
24 class HttpNetworkSession; 26 class HttpNetworkSession;
25 class IOBuffer; 27 class IOBuffer;
26 struct LoadTimingInfo; 28 struct LoadTimingInfo;
27 class UploadProgress; 29 class UploadProgress;
28 class X509Certificate; 30 class X509Certificate;
31 } // namespace net
32
33 namespace test {
34 class DevToolsNetworkControllerHelper;
29 } 35 }
30 36
31 // DevToolsNetworkTransaction is a wrapper for network transaction. All 37 // DevToolsNetworkTransaction is a wrapper for network transaction. All
32 // HttpTransaction methods are proxied to real transaction, but |callback| 38 // HttpTransaction methods are proxied to real transaction, but |callback|
33 // parameter is saved and replaced with proxy callback. Fail method should be 39 // parameter is saved and replaced with proxy callback. Fail method should be
34 // used to simulate network outage. It runs saved callback (if any) with 40 // used to simulate network outage. It runs saved callback (if any) with
35 // net::ERR_INTERNET_DISCONNECTED result value. 41 // net::ERR_INTERNET_DISCONNECTED result value.
36 class DevToolsNetworkTransaction : public net::HttpTransaction { 42 class DevToolsNetworkTransaction : public net::HttpTransaction {
37 public: 43 public:
38 DevToolsNetworkTransaction( 44 DevToolsNetworkTransaction(
39 DevToolsNetworkController* controller, 45 DevToolsNetworkController* controller,
40 scoped_ptr<net::HttpTransaction> network_transaction); 46 scoped_ptr<net::HttpTransaction> network_transaction);
41 47
42 virtual ~DevToolsNetworkTransaction(); 48 virtual ~DevToolsNetworkTransaction();
43 49
44 const net::HttpRequestInfo* request() const { return request_; } 50 const net::HttpRequestInfo* request() const { return request_; }
51
52 // Checks if request contains DevTools specific headers. Found values are
53 // remembered and corresponding keys are removed from headers.
54 void ProcessRequest();
55
45 bool failed() const { return failed_; } 56 bool failed() const { return failed_; }
46 57
47 // Runs callback (if any) with net::ERR_INTERNET_DISCONNECTED result value. 58 // Runs callback (if any) with net::ERR_INTERNET_DISCONNECTED result value.
48 void Fail(); 59 void Fail();
49 60
50 int64_t throttled_byte_count() const { return throttled_byte_count_; } 61 int64_t throttled_byte_count() const { return throttled_byte_count_; }
51 void DecreaseThrottledByteCount(int64_t delta) { 62 void DecreaseThrottledByteCount(int64_t delta) {
52 throttled_byte_count_ -= delta; 63 throttled_byte_count_ -= delta;
53 } 64 }
54 65
66 const std::string& request_initiator() const { return request_initiator_; }
67
68 const std::string& client_id() const {
69 return client_id_;
70 }
71
55 void FireThrottledCallback(); 72 void FireThrottledCallback();
56 73
57 // HttpTransaction methods: 74 // HttpTransaction methods:
58 virtual int Start( 75 virtual int Start(
59 const net::HttpRequestInfo* request, 76 const net::HttpRequestInfo* request,
60 const net::CompletionCallback& callback, 77 const net::CompletionCallback& callback,
61 const net::BoundNetLog& net_log) OVERRIDE; 78 const net::BoundNetLog& net_log) OVERRIDE;
62 virtual int RestartIgnoringLastError( 79 virtual int RestartIgnoringLastError(
63 const net::CompletionCallback& callback) OVERRIDE; 80 const net::CompletionCallback& callback) OVERRIDE;
64 virtual int RestartWithCertificate( 81 virtual int RestartWithCertificate(
(...skipping 20 matching lines...) Expand all
85 net::QuicServerInfo* quic_server_info) OVERRIDE; 102 net::QuicServerInfo* quic_server_info) OVERRIDE;
86 virtual bool GetLoadTimingInfo( 103 virtual bool GetLoadTimingInfo(
87 net::LoadTimingInfo* load_timing_info) const OVERRIDE; 104 net::LoadTimingInfo* load_timing_info) const OVERRIDE;
88 virtual void SetPriority(net::RequestPriority priority) OVERRIDE; 105 virtual void SetPriority(net::RequestPriority priority) OVERRIDE;
89 virtual void SetWebSocketHandshakeStreamCreateHelper( 106 virtual void SetWebSocketHandshakeStreamCreateHelper(
90 net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) OVERRIDE; 107 net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) OVERRIDE;
91 virtual void SetBeforeNetworkStartCallback( 108 virtual void SetBeforeNetworkStartCallback(
92 const BeforeNetworkStartCallback& callback) OVERRIDE; 109 const BeforeNetworkStartCallback& callback) OVERRIDE;
93 virtual int ResumeNetworkStart() OVERRIDE; 110 virtual int ResumeNetworkStart() OVERRIDE;
94 111
112 protected:
113 friend class test::DevToolsNetworkControllerHelper;
114
95 private: 115 private:
96 // Proxy callback handler. Runs saved callback. 116 // Proxy callback handler. Runs saved callback.
97 void OnCallback(int result); 117 void OnCallback(int result);
98 118
99 DevToolsNetworkController* controller_; 119 DevToolsNetworkController* controller_;
120 base::WeakPtr<DevToolsNetworkInterceptor> interceptor_;
100 121
101 // Real network transaction. 122 // Real network transaction.
102 scoped_ptr<net::HttpTransaction> network_transaction_; 123 scoped_ptr<net::HttpTransaction> network_transaction_;
103 124
104 const net::HttpRequestInfo* request_; 125 const net::HttpRequestInfo* request_;
105 126
106 // True if Start was already invoked. 127 // True if Start was already invoked.
107 bool started_; 128 bool started_;
108 129
109 // True if Fail was already invoked. 130 // True if Fail was already invoked.
110 bool failed_; 131 bool failed_;
111 132
133 // Value of "X-DevTools-Request-Initiator" request header.
134 std::string request_initiator_;
135
136 // Value of "X-DevTools-Emulate-Network-Conditions-Client-Id" request header.
137 std::string client_id_;
138
139 scoped_ptr<net::HttpRequestInfo> custom_request_;
140
112 enum CallbackType { 141 enum CallbackType {
113 NONE, 142 NONE,
114 READ, 143 READ,
115 RESTART_IGNORING_LAST_ERROR, 144 RESTART_IGNORING_LAST_ERROR,
116 RESTART_WITH_AUTH, 145 RESTART_WITH_AUTH,
117 RESTART_WITH_CERTIFICATE, 146 RESTART_WITH_CERTIFICATE,
118 START 147 START
119 }; 148 };
120 149
121 int SetupCallback( 150 int SetupCallback(
122 net::CompletionCallback callback, 151 net::CompletionCallback callback,
123 int result, 152 int result,
124 CallbackType callback_type); 153 CallbackType callback_type);
125 154
126 void Throttle(int result); 155 void Throttle(int result);
127 156
128 int throttled_result_; 157 int throttled_result_;
129 int64_t throttled_byte_count_; 158 int64_t throttled_byte_count_;
130 CallbackType callback_type_; 159 CallbackType callback_type_;
131 net::CompletionCallback proxy_callback_; 160 net::CompletionCallback proxy_callback_;
132 net::CompletionCallback callback_; 161 net::CompletionCallback callback_;
133 162
134 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransaction); 163 DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransaction);
135 }; 164 };
136 165
137 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_ 166 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_NETWORK_TRANSACTION_H_
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_network_interceptor.cc ('k') | chrome/browser/devtools/devtools_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698