146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// found in the LICENSE file.
446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/devtools/devtools_network_transaction.h"
646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/devtools/devtools_network_controller.h"
8f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "chrome/browser/devtools/devtools_network_interceptor.h"
946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "net/base/net_errors.h"
1046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "net/base/upload_progress.h"
1146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "net/http/http_network_transaction.h"
1246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "net/http/http_request_info.h"
1346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
14f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)namespace {
15f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
16f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)const char kDevToolsRequestInitiator[] = "X-DevTools-Request-Initiator";
17f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)const char kDevToolsEmulateNetworkConditionsClientId[] =
18f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    "X-DevTools-Emulate-Network-Conditions-Client-Id";
19f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
20f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}  // namespace
21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
2246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)DevToolsNetworkTransaction::DevToolsNetworkTransaction(
2346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    DevToolsNetworkController* controller,
2446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    scoped_ptr<net::HttpTransaction> network_transaction)
2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    : controller_(controller),
2646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      network_transaction_(network_transaction.Pass()),
2746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      request_(NULL),
2846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      failed_(false),
29f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      throttled_byte_count_(0),
30f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      callback_type_(NONE),
3146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      proxy_callback_(base::Bind(&DevToolsNetworkTransaction::OnCallback,
3246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                                 base::Unretained(this))) {
3346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DCHECK(controller);
3446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
3546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)DevToolsNetworkTransaction::~DevToolsNetworkTransaction() {
37f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (interceptor_)
38f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    interceptor_->RemoveTransaction(this);
39f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
40f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
41f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void DevToolsNetworkTransaction::Throttle(int result) {
42f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  throttled_result_ = result;
43f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
44f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (callback_type_ == START)
45f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    throttled_byte_count_ += network_transaction_->GetTotalReceivedBytes();
46f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (result > 0)
47f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    throttled_byte_count_ += result;
48f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
49f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (interceptor_)
506d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)    interceptor_->ThrottleTransaction(this, callback_type_ == START);
5146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
5246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
5346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::OnCallback(int rv) {
5446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (failed_)
5546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return;
5646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DCHECK(!callback_.is_null());
57f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (callback_type_ == START || callback_type_ == READ) {
58f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    if (interceptor_ && interceptor_->ShouldThrottle(this)) {
59f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      Throttle(rv);
60f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      return;
61f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    }
62f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
6346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  net::CompletionCallback callback = callback_;
6446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  callback_.Reset();
65f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  callback_type_ = NONE;
6646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  callback.Run(rv);
6746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
6846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
69f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)int DevToolsNetworkTransaction::SetupCallback(
70f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    net::CompletionCallback callback,
71f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    int result,
72f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    CallbackType callback_type) {
73f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DCHECK(callback_type_ == NONE);
74f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
75f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (result == net::ERR_IO_PENDING) {
76f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    callback_type_ = callback_type;
77f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    callback_ = callback;
78f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return result;
79f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
80f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
81f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (!interceptor_ || !interceptor_->ShouldThrottle(this))
82f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return result;
83f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
84f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // Only START and READ operation throttling is supported.
85f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (callback_type != START && callback_type != READ)
86f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return result;
87f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
88f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // In case of error |throttled_byte_count_| is unknown.
89f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (result < 0)
90f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return result;
91f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
92f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // URLRequestJob relies on synchronous end-of-stream notification.
93f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (callback_type == READ && result == 0)
94f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return result;
95f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
96f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  callback_type_ = callback_type;
97f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  callback_ = callback;
98f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  Throttle(result);
99f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return net::ERR_IO_PENDING;
100f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
101f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
10246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::Fail() {
10346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DCHECK(request_);
10446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DCHECK(!failed_);
10546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  failed_ = true;
10646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  network_transaction_->SetBeforeNetworkStartCallback(
10746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      BeforeNetworkStartCallback());
10846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (callback_.is_null())
10946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return;
11046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  net::CompletionCallback callback = callback_;
11146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  callback_.Reset();
112f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  callback_type_ = NONE;
11346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  callback.Run(net::ERR_INTERNET_DISCONNECTED);
11446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
11546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
11646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)int DevToolsNetworkTransaction::Start(
11746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::HttpRequestInfo* request,
11846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::CompletionCallback& callback,
11946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::BoundNetLog& net_log) {
12046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DCHECK(request);
12146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  request_ = request;
122f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  interceptor_ = controller_->GetInterceptor(this);
123f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  interceptor_->AddTransaction(this);
12446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
125f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (interceptor_->ShouldFail(this)) {
12646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    failed_ = true;
12746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    network_transaction_->SetBeforeNetworkStartCallback(
12846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)        BeforeNetworkStartCallback());
12946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return net::ERR_INTERNET_DISCONNECTED;
13046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  }
131f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  int rv = network_transaction_->Start(request_, proxy_callback_, net_log);
132f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return SetupCallback(callback, rv, START);
133f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
134f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
135f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void DevToolsNetworkTransaction::ProcessRequest() {
136f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DCHECK(request_);
137f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool has_devtools_client_id = request_->extra_headers.HasHeader(
138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      kDevToolsEmulateNetworkConditionsClientId);
139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  bool has_devtools_request_initiator = request_->extra_headers.HasHeader(
140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      kDevToolsRequestInitiator);
141f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (!has_devtools_client_id && !has_devtools_request_initiator)
142f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    return;
143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
144f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  custom_request_.reset(new net::HttpRequestInfo(*request_));
145f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
146f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (has_devtools_client_id) {
147f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    custom_request_->extra_headers.GetHeader(
148f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        kDevToolsEmulateNetworkConditionsClientId, &client_id_);
149f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    custom_request_->extra_headers.RemoveHeader(
150f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        kDevToolsEmulateNetworkConditionsClientId);
151f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
152f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
153f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if (has_devtools_request_initiator) {
154f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    custom_request_->extra_headers.GetHeader(
155f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)        kDevToolsRequestInitiator, &request_initiator_);
156f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    custom_request_->extra_headers.RemoveHeader(kDevToolsRequestInitiator);
157f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  }
158f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
159f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  request_ = custom_request_.get();
16046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
16146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
16246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)int DevToolsNetworkTransaction::RestartIgnoringLastError(
16346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::CompletionCallback& callback) {
16446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (failed_)
16546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return net::ERR_INTERNET_DISCONNECTED;
16646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int rv = network_transaction_->RestartIgnoringLastError(proxy_callback_);
167f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return SetupCallback(callback, rv, RESTART_IGNORING_LAST_ERROR);
16846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
16946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
17046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)int DevToolsNetworkTransaction::RestartWithCertificate(
17146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    net::X509Certificate* client_cert,
17246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::CompletionCallback& callback) {
17346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (failed_)
17446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return net::ERR_INTERNET_DISCONNECTED;
17546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int rv = network_transaction_->RestartWithCertificate(
17646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)      client_cert, proxy_callback_);
177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return SetupCallback(callback, rv, RESTART_WITH_CERTIFICATE);
17846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
17946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
18046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)int DevToolsNetworkTransaction::RestartWithAuth(
18146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::AuthCredentials& credentials,
18246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::CompletionCallback& callback) {
18346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (failed_)
18446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return net::ERR_INTERNET_DISCONNECTED;
18546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int rv = network_transaction_->RestartWithAuth(credentials, proxy_callback_);
186f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return SetupCallback(callback, rv, RESTART_WITH_AUTH);
18746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
18846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
18946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)bool DevToolsNetworkTransaction::IsReadyToRestartForAuth() {
19046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->IsReadyToRestartForAuth();
19146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
19246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
19346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)int DevToolsNetworkTransaction::Read(
19446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    net::IOBuffer* buf,
19546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    int buf_len,
19646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const net::CompletionCallback& callback) {
19746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (failed_)
19846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return net::ERR_INTERNET_DISCONNECTED;
19946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int rv = network_transaction_->Read(buf, buf_len, proxy_callback_);
200f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  return SetupCallback(callback, rv, READ);
20146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
20246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
20346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::StopCaching() {
20446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  network_transaction_->StopCaching();
20546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
20646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
20746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)bool DevToolsNetworkTransaction::GetFullRequestHeaders(
20846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    net::HttpRequestHeaders* headers) const {
20946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->GetFullRequestHeaders(headers);
21046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
21146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
21246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)int64 DevToolsNetworkTransaction::GetTotalReceivedBytes() const {
21346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->GetTotalReceivedBytes();
21446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
21546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
21646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::DoneReading() {
21746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  network_transaction_->DoneReading();
21846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
21946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
22046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)const net::HttpResponseInfo*
22146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)DevToolsNetworkTransaction::GetResponseInfo() const {
22246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->GetResponseInfo();
22346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
22446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
22546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)net::LoadState DevToolsNetworkTransaction::GetLoadState() const {
22646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->GetLoadState();
22746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
22846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
22946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)net::UploadProgress DevToolsNetworkTransaction::GetUploadProgress() const {
23046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->GetUploadProgress();
23146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
23246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
23346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::SetQuicServerInfo(
23446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    net::QuicServerInfo* quic_server_info) {
23546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  network_transaction_->SetQuicServerInfo(quic_server_info);
23646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
23746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
23846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)bool DevToolsNetworkTransaction::GetLoadTimingInfo(
23946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    net::LoadTimingInfo* load_timing_info) const {
24046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->GetLoadTimingInfo(load_timing_info);
24146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
24246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
24346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::SetPriority(net::RequestPriority priority) {
24446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  network_transaction_->SetPriority(priority);
24546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
24646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
24746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::SetWebSocketHandshakeStreamCreateHelper(
24846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) {
24946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  network_transaction_->SetWebSocketHandshakeStreamCreateHelper(create_helper);
25046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
25146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
25246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void DevToolsNetworkTransaction::SetBeforeNetworkStartCallback(
25346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    const BeforeNetworkStartCallback& callback) {
25446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  network_transaction_->SetBeforeNetworkStartCallback(callback);
25546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
25646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
257116680a4aac90f2aa7413d9095a592090648e557Ben Murdochvoid DevToolsNetworkTransaction::SetBeforeProxyHeadersSentCallback(
258116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    const BeforeProxyHeadersSentCallback& callback) {
259116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  network_transaction_->SetBeforeProxyHeadersSentCallback(callback);
260116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch}
261116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
26246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)int DevToolsNetworkTransaction::ResumeNetworkStart() {
26346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  if (failed_)
26446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    return net::ERR_INTERNET_DISCONNECTED;
26546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  return network_transaction_->ResumeNetworkStart();
26646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}
267f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
268f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)void DevToolsNetworkTransaction::FireThrottledCallback() {
269f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DCHECK(!callback_.is_null());
270f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  DCHECK(callback_type_ == READ || callback_type_ == START);
271f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  net::CompletionCallback callback = callback_;
272f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  callback_.Reset();
273f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  callback_type_ = NONE;
274f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  callback.Run(throttled_result_);
275f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}
276