Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "cronet_url_request_adapter.h" | 5 #include "cronet_url_request_adapter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "components/cronet/android/cronet_url_request_context_adapter.h" | 10 #include "components/cronet/android/cronet_url_request_context_adapter.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 delegate_(delegate.Pass()), | 28 delegate_(delegate.Pass()), |
| 29 initial_url_(url), | 29 initial_url_(url), |
| 30 initial_priority_(priority), | 30 initial_priority_(priority), |
| 31 initial_method_("GET") { | 31 initial_method_("GET") { |
| 32 } | 32 } |
| 33 | 33 |
| 34 CronetURLRequestAdapter::~CronetURLRequestAdapter() { | 34 CronetURLRequestAdapter::~CronetURLRequestAdapter() { |
| 35 DCHECK(IsOnNetworkThread()); | 35 DCHECK(IsOnNetworkThread()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void CronetURLRequestAdapter::AddRequestHeader(const std::string& name, | |
| 39 const std::string& value) { | |
| 40 DCHECK(!IsOnNetworkThread()); | |
| 41 initial_request_headers_.SetHeader(name, value); | |
| 42 } | |
| 43 | |
| 44 bool CronetURLRequestAdapter::PostTaskToNetworkThread( | 38 bool CronetURLRequestAdapter::PostTaskToNetworkThread( |
| 45 const tracked_objects::Location& from_here, | 39 const tracked_objects::Location& from_here, |
| 46 const base::Closure& task) { | 40 const base::Closure& task) { |
| 47 DCHECK(!IsOnNetworkThread()); | 41 DCHECK(!IsOnNetworkThread()); |
| 48 return context_->GetNetworkTaskRunner()->PostTask(from_here, task); | 42 return context_->GetNetworkTaskRunner()->PostTask(from_here, task); |
| 49 } | 43 } |
| 50 | 44 |
| 51 bool CronetURLRequestAdapter::IsOnNetworkThread() const { | 45 bool CronetURLRequestAdapter::IsOnNetworkThread() const { |
| 52 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); | 46 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); |
| 53 } | 47 } |
| 54 | 48 |
| 49 void CronetURLRequestAdapter::AddRequestHeader(const std::string& name, | |
| 50 const std::string& value) { | |
| 51 DCHECK(!IsOnNetworkThread()); | |
| 52 initial_request_headers_.SetHeader(name, value); | |
| 53 } | |
| 54 | |
| 55 void CronetURLRequestAdapter::SetUpload( | |
| 56 scoped_ptr<net::UploadDataStream> upload) { | |
| 57 DCHECK(!IsOnNetworkThread()); | |
| 58 DCHECK(!upload_.get()); | |
| 59 upload_ = upload.Pass(); | |
| 60 } | |
| 61 | |
| 62 // For testing. | |
| 63 net::UploadDataStream* CronetURLRequestAdapter::GetUpload() { | |
|
mef
2015/02/02 17:45:11
nit: GetUploadForTesting?
xunjieli
2015/02/02 18:25:41
Done.
| |
| 64 return upload_.get(); | |
| 65 } | |
| 66 | |
| 55 void CronetURLRequestAdapter::Start() { | 67 void CronetURLRequestAdapter::Start() { |
| 56 DCHECK(IsOnNetworkThread()); | 68 DCHECK(IsOnNetworkThread()); |
| 57 VLOG(1) << "Starting chromium request: " | 69 VLOG(1) << "Starting chromium request: " |
| 58 << initial_url_.possibly_invalid_spec().c_str() | 70 << initial_url_.possibly_invalid_spec().c_str() |
| 59 << " priority: " << RequestPriorityToString(initial_priority_); | 71 << " priority: " << RequestPriorityToString(initial_priority_); |
| 60 url_request_ = context_->GetURLRequestContext()->CreateRequest( | 72 url_request_ = context_->GetURLRequestContext()->CreateRequest( |
| 61 initial_url_, net::DEFAULT_PRIORITY, this, NULL); | 73 initial_url_, net::DEFAULT_PRIORITY, this, NULL); |
| 62 url_request_->SetLoadFlags(context_->default_load_flags()); | 74 url_request_->SetLoadFlags(context_->default_load_flags()); |
| 63 url_request_->set_method(initial_method_); | 75 url_request_->set_method(initial_method_); |
| 64 url_request_->SetExtraRequestHeaders(initial_request_headers_); | 76 url_request_->SetExtraRequestHeaders(initial_request_headers_); |
| 65 url_request_->SetPriority(initial_priority_); | 77 url_request_->SetPriority(initial_priority_); |
| 78 if (upload_) | |
| 79 url_request_->set_upload(upload_.Pass()); | |
| 66 url_request_->Start(); | 80 url_request_->Start(); |
| 67 } | 81 } |
| 68 | 82 |
| 69 void CronetURLRequestAdapter::FollowDeferredRedirect() { | 83 void CronetURLRequestAdapter::FollowDeferredRedirect() { |
| 70 DCHECK(IsOnNetworkThread()); | 84 DCHECK(IsOnNetworkThread()); |
| 71 | 85 |
| 72 url_request_->FollowDeferredRedirect(); | 86 url_request_->FollowDeferredRedirect(); |
| 73 } | 87 } |
| 74 | 88 |
| 75 void CronetURLRequestAdapter::ReadData() { | 89 void CronetURLRequestAdapter::ReadData() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 DCHECK_EQ(request, url_request_); | 163 DCHECK_EQ(request, url_request_); |
| 150 if (url_request_->status().is_success()) | 164 if (url_request_->status().is_success()) |
| 151 return false; | 165 return false; |
| 152 VLOG(1) << "Error " << url_request_->status().error() | 166 VLOG(1) << "Error " << url_request_->status().error() |
| 153 << " on chromium request: " << initial_url_.possibly_invalid_spec(); | 167 << " on chromium request: " << initial_url_.possibly_invalid_spec(); |
| 154 delegate_->OnError(url_request_->status().error()); | 168 delegate_->OnError(url_request_->status().error()); |
| 155 return true; | 169 return true; |
| 156 } | 170 } |
| 157 | 171 |
| 158 } // namespace cronet | 172 } // namespace cronet |
| OLD | NEW |