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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 const tracked_objects::Location& from_here, | 51 const tracked_objects::Location& from_here, |
| 52 const base::Closure& task) { | 52 const base::Closure& task) { |
| 53 DCHECK(!IsOnNetworkThread()); | 53 DCHECK(!IsOnNetworkThread()); |
| 54 return context_->GetNetworkTaskRunner()->PostTask(from_here, task); | 54 return context_->GetNetworkTaskRunner()->PostTask(from_here, task); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool CronetURLRequestAdapter::IsOnNetworkThread() const { | 57 bool CronetURLRequestAdapter::IsOnNetworkThread() const { |
| 58 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); | 58 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void CronetURLRequestAdapter::SetUpload( | |
| 62 scoped_ptr<net::UploadDataStream> upload) { | |
| 63 DCHECK(!IsOnNetworkThread()); | |
| 64 DCHECK(!upload_.get()); | |
|
mmenke
2015/02/10 19:37:09
nit: This should probably just be DCHECK(!upload_
xunjieli
2015/02/10 20:28:30
Done.
| |
| 65 upload_ = upload.Pass(); | |
| 66 } | |
| 67 | |
| 61 void CronetURLRequestAdapter::Start() { | 68 void CronetURLRequestAdapter::Start() { |
| 62 DCHECK(IsOnNetworkThread()); | 69 DCHECK(IsOnNetworkThread()); |
| 63 VLOG(1) << "Starting chromium request: " | 70 VLOG(1) << "Starting chromium request: " |
| 64 << initial_url_.possibly_invalid_spec().c_str() | 71 << initial_url_.possibly_invalid_spec().c_str() |
| 65 << " priority: " << RequestPriorityToString(initial_priority_); | 72 << " priority: " << RequestPriorityToString(initial_priority_); |
| 66 url_request_ = context_->GetURLRequestContext()->CreateRequest( | 73 url_request_ = context_->GetURLRequestContext()->CreateRequest( |
| 67 initial_url_, net::DEFAULT_PRIORITY, this, NULL); | 74 initial_url_, net::DEFAULT_PRIORITY, this, NULL); |
| 68 url_request_->SetLoadFlags(load_flags_); | 75 url_request_->SetLoadFlags(load_flags_); |
| 69 url_request_->set_method(initial_method_); | 76 url_request_->set_method(initial_method_); |
| 70 url_request_->SetExtraRequestHeaders(initial_request_headers_); | 77 url_request_->SetExtraRequestHeaders(initial_request_headers_); |
| 71 url_request_->SetPriority(initial_priority_); | 78 url_request_->SetPriority(initial_priority_); |
| 79 if (upload_) | |
| 80 url_request_->set_upload(upload_.Pass()); | |
| 72 url_request_->Start(); | 81 url_request_->Start(); |
| 73 } | 82 } |
| 74 | 83 |
| 75 void CronetURLRequestAdapter::FollowDeferredRedirect() { | 84 void CronetURLRequestAdapter::FollowDeferredRedirect() { |
| 76 DCHECK(IsOnNetworkThread()); | 85 DCHECK(IsOnNetworkThread()); |
| 77 | 86 |
| 78 url_request_->FollowDeferredRedirect(); | 87 url_request_->FollowDeferredRedirect(); |
| 79 } | 88 } |
| 80 | 89 |
| 81 void CronetURLRequestAdapter::ReadData() { | 90 void CronetURLRequestAdapter::ReadData() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 DCHECK_EQ(request, url_request_); | 164 DCHECK_EQ(request, url_request_); |
| 156 if (url_request_->status().is_success()) | 165 if (url_request_->status().is_success()) |
| 157 return false; | 166 return false; |
| 158 VLOG(1) << "Error " << url_request_->status().error() | 167 VLOG(1) << "Error " << url_request_->status().error() |
| 159 << " on chromium request: " << initial_url_.possibly_invalid_spec(); | 168 << " on chromium request: " << initial_url_.possibly_invalid_spec(); |
| 160 delegate_->OnError(url_request_->status().error()); | 169 delegate_->OnError(url_request_->status().error()); |
| 161 return true; | 170 return true; |
| 162 } | 171 } |
| 163 | 172 |
| 164 } // namespace cronet | 173 } // namespace cronet |
| OLD | NEW |