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 10 matching lines...) Expand all Loading... | |
| 21 | 21 |
| 22 CronetURLRequestAdapter::CronetURLRequestAdapter( | 22 CronetURLRequestAdapter::CronetURLRequestAdapter( |
| 23 CronetURLRequestContextAdapter* context, | 23 CronetURLRequestContextAdapter* context, |
| 24 scoped_ptr<CronetURLRequestAdapterDelegate> delegate, | 24 scoped_ptr<CronetURLRequestAdapterDelegate> delegate, |
| 25 const GURL& url, | 25 const GURL& url, |
| 26 net::RequestPriority priority) | 26 net::RequestPriority priority) |
| 27 : context_(context), | 27 : context_(context), |
| 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 bypass_cache_(false) { | |
| 32 } | 33 } |
| 33 | 34 |
| 34 CronetURLRequestAdapter::~CronetURLRequestAdapter() { | 35 CronetURLRequestAdapter::~CronetURLRequestAdapter() { |
| 35 DCHECK(IsOnNetworkThread()); | 36 DCHECK(IsOnNetworkThread()); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void CronetURLRequestAdapter::AddRequestHeader(const std::string& name, | 39 void CronetURLRequestAdapter::AddRequestHeader(const std::string& name, |
| 39 const std::string& value) { | 40 const std::string& value) { |
| 40 DCHECK(!IsOnNetworkThread()); | 41 DCHECK(!IsOnNetworkThread()); |
| 41 initial_request_headers_.SetHeader(name, value); | 42 initial_request_headers_.SetHeader(name, value); |
| 42 } | 43 } |
| 43 | 44 |
| 45 void CronetURLRequestAdapter::BypassCache() { | |
| 46 DCHECK(!IsOnNetworkThread()); | |
| 47 bypass_cache_ = true; | |
| 48 } | |
| 49 | |
| 44 bool CronetURLRequestAdapter::PostTaskToNetworkThread( | 50 bool CronetURLRequestAdapter::PostTaskToNetworkThread( |
| 45 const tracked_objects::Location& from_here, | 51 const tracked_objects::Location& from_here, |
| 46 const base::Closure& task) { | 52 const base::Closure& task) { |
| 47 DCHECK(!IsOnNetworkThread()); | 53 DCHECK(!IsOnNetworkThread()); |
| 48 return context_->GetNetworkTaskRunner()->PostTask(from_here, task); | 54 return context_->GetNetworkTaskRunner()->PostTask(from_here, task); |
| 49 } | 55 } |
| 50 | 56 |
| 51 bool CronetURLRequestAdapter::IsOnNetworkThread() const { | 57 bool CronetURLRequestAdapter::IsOnNetworkThread() const { |
| 52 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); | 58 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); |
| 53 } | 59 } |
| 54 | 60 |
| 55 void CronetURLRequestAdapter::Start() { | 61 void CronetURLRequestAdapter::Start() { |
| 56 DCHECK(IsOnNetworkThread()); | 62 DCHECK(IsOnNetworkThread()); |
| 57 VLOG(1) << "Starting chromium request: " | 63 VLOG(1) << "Starting chromium request: " |
| 58 << initial_url_.possibly_invalid_spec().c_str() | 64 << initial_url_.possibly_invalid_spec().c_str() |
| 59 << " priority: " << RequestPriorityToString(initial_priority_); | 65 << " priority: " << RequestPriorityToString(initial_priority_); |
| 60 url_request_ = context_->GetURLRequestContext()->CreateRequest( | 66 url_request_ = context_->GetURLRequestContext()->CreateRequest( |
| 61 initial_url_, net::DEFAULT_PRIORITY, this, NULL); | 67 initial_url_, net::DEFAULT_PRIORITY, this, NULL); |
| 62 url_request_->SetLoadFlags(context_->default_load_flags()); | 68 int load_flags = context_->default_load_flags(); |
| 69 if (bypass_cache_) { | |
| 70 load_flags |= net::LOAD_DISABLE_CACHE; | |
| 71 } | |
|
mmenke
2015/01/22 16:21:20
nit: Don't use brace if the body and condition of
xunjieli
2015/01/26 21:36:09
Done.
| |
| 72 url_request_->SetLoadFlags(load_flags); | |
| 63 url_request_->set_method(initial_method_); | 73 url_request_->set_method(initial_method_); |
| 64 url_request_->SetExtraRequestHeaders(initial_request_headers_); | 74 url_request_->SetExtraRequestHeaders(initial_request_headers_); |
| 65 url_request_->SetPriority(initial_priority_); | 75 url_request_->SetPriority(initial_priority_); |
| 66 url_request_->Start(); | 76 url_request_->Start(); |
| 67 } | 77 } |
| 68 | 78 |
| 69 void CronetURLRequestAdapter::FollowDeferredRedirect() { | 79 void CronetURLRequestAdapter::FollowDeferredRedirect() { |
| 70 DCHECK(IsOnNetworkThread()); | 80 DCHECK(IsOnNetworkThread()); |
| 71 | 81 |
| 72 url_request_->FollowDeferredRedirect(); | 82 url_request_->FollowDeferredRedirect(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 DCHECK_EQ(request, url_request_); | 159 DCHECK_EQ(request, url_request_); |
| 150 if (url_request_->status().is_success()) | 160 if (url_request_->status().is_success()) |
| 151 return false; | 161 return false; |
| 152 VLOG(1) << "Error " << url_request_->status().error() | 162 VLOG(1) << "Error " << url_request_->status().error() |
| 153 << " on chromium request: " << initial_url_.possibly_invalid_spec(); | 163 << " on chromium request: " << initial_url_.possibly_invalid_spec(); |
| 154 delegate_->OnError(url_request_->status().error()); | 164 delegate_->OnError(url_request_->status().error()); |
| 155 return true; | 165 return true; |
| 156 } | 166 } |
| 157 | 167 |
| 158 } // namespace cronet | 168 } // namespace cronet |
| OLD | NEW |