| 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 |
| 55 void CronetURLRequestAdapter::Start() { | 62 void CronetURLRequestAdapter::Start() { |
| 56 DCHECK(IsOnNetworkThread()); | 63 DCHECK(IsOnNetworkThread()); |
| 57 VLOG(1) << "Starting chromium request: " | 64 VLOG(1) << "Starting chromium request: " |
| 58 << initial_url_.possibly_invalid_spec().c_str() | 65 << initial_url_.possibly_invalid_spec().c_str() |
| 59 << " priority: " << RequestPriorityToString(initial_priority_); | 66 << " priority: " << RequestPriorityToString(initial_priority_); |
| 60 url_request_ = context_->GetURLRequestContext()->CreateRequest( | 67 url_request_ = context_->GetURLRequestContext()->CreateRequest( |
| 61 initial_url_, net::DEFAULT_PRIORITY, this, NULL); | 68 initial_url_, net::DEFAULT_PRIORITY, this, NULL); |
| 62 url_request_->SetLoadFlags(context_->default_load_flags()); | 69 url_request_->SetLoadFlags(context_->default_load_flags()); |
| 63 url_request_->set_method(initial_method_); | 70 url_request_->set_method(initial_method_); |
| 64 url_request_->SetExtraRequestHeaders(initial_request_headers_); | 71 url_request_->SetExtraRequestHeaders(initial_request_headers_); |
| 65 url_request_->SetPriority(initial_priority_); | 72 url_request_->SetPriority(initial_priority_); |
| 73 if (upload_) |
| 74 url_request_->set_upload(upload_.Pass()); |
| 66 url_request_->Start(); | 75 url_request_->Start(); |
| 67 } | 76 } |
| 68 | 77 |
| 69 void CronetURLRequestAdapter::FollowDeferredRedirect() { | 78 void CronetURLRequestAdapter::FollowDeferredRedirect() { |
| 70 DCHECK(IsOnNetworkThread()); | 79 DCHECK(IsOnNetworkThread()); |
| 71 | 80 |
| 72 url_request_->FollowDeferredRedirect(); | 81 url_request_->FollowDeferredRedirect(); |
| 73 } | 82 } |
| 74 | 83 |
| 75 void CronetURLRequestAdapter::ReadData() { | 84 void CronetURLRequestAdapter::ReadData() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 DCHECK_EQ(request, url_request_); | 158 DCHECK_EQ(request, url_request_); |
| 150 if (url_request_->status().is_success()) | 159 if (url_request_->status().is_success()) |
| 151 return false; | 160 return false; |
| 152 VLOG(1) << "Error " << url_request_->status().error() | 161 VLOG(1) << "Error " << url_request_->status().error() |
| 153 << " on chromium request: " << initial_url_.possibly_invalid_spec(); | 162 << " on chromium request: " << initial_url_.possibly_invalid_spec(); |
| 154 delegate_->OnError(url_request_->status().error()); | 163 delegate_->OnError(url_request_->status().error()); |
| 155 return true; | 164 return true; |
| 156 } | 165 } |
| 157 | 166 |
| 158 } // namespace cronet | 167 } // namespace cronet |
| OLD | NEW |