Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/net/network_transaction.h" | |
| 6 | |
| 7 #include "base/atomicops.h" | |
| 8 #include "chrome/browser/net/network_controller.h" | |
| 9 #include "net/base/net_errors.h" | |
| 10 #include "net/http/http_network_transaction.h" | |
| 11 #include "net/http/http_request_info.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 base::subtle::Atomic64 g_last_transaction_id = 0; | |
| 16 | |
| 17 uint64 GenerateTransactionId() { | |
| 18 return base::subtle::NoBarrier_AtomicIncrement(&g_last_transaction_id, 1); | |
| 19 } | |
| 20 | |
| 21 } // namrspace | |
| 22 | |
| 23 NetworkTransaction::NetworkTransaction( | |
|
mmenke
2014/03/13 15:33:34
In general, I think it's a really bad idea for two
| |
| 24 NetworkController* controller, | |
| 25 scoped_ptr<net::HttpTransaction>& network_transaction) | |
| 26 : id_(GenerateTransactionId()), | |
| 27 controller_(controller), | |
| 28 network_transaction_(network_transaction.Pass()), | |
| 29 proxy_callback_(base::Bind(&NetworkTransaction::OnCallback, | |
| 30 base::Unretained(this))) { | |
| 31 CHECK(controller); | |
| 32 controller->AddTransaction(id_, this); | |
| 33 } | |
| 34 | |
| 35 NetworkTransaction::~NetworkTransaction() { | |
| 36 controller_->RemoveTransaction(id_); | |
| 37 } | |
| 38 | |
| 39 const GURL& NetworkTransaction::GetURL() { | |
| 40 return url_; | |
| 41 } | |
| 42 | |
| 43 void NetworkTransaction::OnCallback(int rv) { | |
| 44 net::CompletionCallback callback = callback_; | |
| 45 callback_.Reset(); | |
| 46 callback.Run(rv); | |
| 47 } | |
| 48 | |
| 49 void NetworkTransaction::Stop() { | |
| 50 net::CompletionCallback callback = callback_; | |
| 51 callback_.Reset(); | |
| 52 if (!callback.is_null()) | |
| 53 callback.Run(net::ERR_INTERNET_DISCONNECTED); | |
| 54 } | |
| 55 | |
| 56 int NetworkTransaction::Start( | |
| 57 const net::HttpRequestInfo* request_info, | |
| 58 const net::CompletionCallback& callback, | |
| 59 const net::BoundNetLog& net_log) { | |
| 60 url_ = request_info->url; | |
| 61 | |
| 62 if (controller_ && controller_->IsBlockedURL(url_)) | |
| 63 return net::ERR_INTERNET_DISCONNECTED; | |
| 64 int rv = network_transaction_->Start(request_info, proxy_callback_, net_log); | |
| 65 if (rv == net::ERR_IO_PENDING) | |
| 66 callback_ = callback; | |
| 67 return rv; | |
| 68 } | |
| 69 | |
| 70 int NetworkTransaction::RestartIgnoringLastError( | |
| 71 const net::CompletionCallback& callback) { | |
| 72 int rv = network_transaction_->RestartIgnoringLastError(proxy_callback_); | |
| 73 if (rv == net::ERR_IO_PENDING) | |
| 74 callback_ = callback; | |
| 75 return rv; | |
| 76 } | |
| 77 | |
| 78 int NetworkTransaction::RestartWithCertificate( | |
| 79 net::X509Certificate* client_cert, | |
| 80 const net::CompletionCallback& callback) { | |
| 81 int rv = network_transaction_->RestartWithCertificate( | |
| 82 client_cert, proxy_callback_); | |
| 83 if (rv == net::ERR_IO_PENDING) | |
| 84 callback_ = callback; | |
| 85 return rv; | |
| 86 } | |
| 87 | |
| 88 int NetworkTransaction::RestartWithAuth( | |
| 89 const net::AuthCredentials& credentials, | |
| 90 const net::CompletionCallback& callback) { | |
| 91 int rv = network_transaction_->RestartWithAuth(credentials, proxy_callback_); | |
| 92 if (rv == net::ERR_IO_PENDING) | |
| 93 callback_ = callback; | |
| 94 return rv; | |
| 95 } | |
| 96 | |
| 97 bool NetworkTransaction::IsReadyToRestartForAuth() { | |
| 98 return network_transaction_->IsReadyToRestartForAuth(); | |
| 99 } | |
| 100 | |
| 101 int NetworkTransaction::Read( | |
| 102 net::IOBuffer* buf, | |
| 103 int buf_len, | |
| 104 const net::CompletionCallback& callback) { | |
| 105 int rv = network_transaction_->Read(buf, buf_len, proxy_callback_); | |
| 106 if (rv == net::ERR_IO_PENDING) | |
| 107 callback_ = callback; | |
| 108 return rv; | |
| 109 } | |
| 110 | |
| 111 void NetworkTransaction::StopCaching() { | |
| 112 network_transaction_->StopCaching(); | |
| 113 } | |
| 114 | |
| 115 bool NetworkTransaction::GetFullRequestHeaders( | |
| 116 net::HttpRequestHeaders* headers) const { | |
| 117 return network_transaction_->GetFullRequestHeaders(headers); | |
| 118 } | |
| 119 | |
| 120 int64 NetworkTransaction::GetTotalReceivedBytes() const { | |
| 121 return network_transaction_->GetTotalReceivedBytes(); | |
| 122 } | |
| 123 | |
| 124 void NetworkTransaction::DoneReading() { | |
| 125 network_transaction_->DoneReading(); | |
| 126 } | |
| 127 | |
| 128 const net::HttpResponseInfo* NetworkTransaction::GetResponseInfo() const | |
| 129 { | |
| 130 return network_transaction_->GetResponseInfo(); | |
| 131 } | |
| 132 | |
| 133 net::LoadState NetworkTransaction::GetLoadState() const { | |
| 134 return network_transaction_->GetLoadState(); | |
| 135 } | |
| 136 | |
| 137 net::UploadProgress NetworkTransaction::GetUploadProgress() const { | |
| 138 return network_transaction_->GetUploadProgress(); | |
| 139 } | |
| 140 | |
| 141 void NetworkTransaction::SetQuicServerInfo( | |
| 142 net::QuicServerInfo* quic_server_info) { | |
| 143 network_transaction_->SetQuicServerInfo(quic_server_info); | |
| 144 } | |
| 145 | |
| 146 bool NetworkTransaction::GetLoadTimingInfo( | |
| 147 net::LoadTimingInfo* load_timing_info) const { | |
| 148 return network_transaction_->GetLoadTimingInfo(load_timing_info); | |
| 149 } | |
| 150 | |
| 151 void NetworkTransaction::SetPriority(net::RequestPriority priority) { | |
| 152 network_transaction_->SetPriority(priority); | |
| 153 } | |
| 154 | |
| 155 void NetworkTransaction::SetWebSocketHandshakeStreamCreateHelper( | |
| 156 net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) { | |
| 157 network_transaction_->SetWebSocketHandshakeStreamCreateHelper(create_helper); | |
| 158 } | |
| 159 | |
| 160 void NetworkTransaction::SetBeforeNetworkStartCallback( | |
| 161 const BeforeNetworkStartCallback& callback) { | |
| 162 // TODO | |
| 163 network_transaction_->SetBeforeNetworkStartCallback(callback); | |
| 164 } | |
| 165 | |
| 166 int NetworkTransaction::ResumeNetworkStart() { | |
| 167 return network_transaction_->ResumeNetworkStart(); | |
| 168 } | |
| OLD | NEW |