Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/fetchers/resource_fetcher_impl.h" | 5 #include "content/renderer/fetchers/resource_fetcher_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "third_party/WebKit/public/platform/Platform.h" | 10 #include "third_party/WebKit/public/platform/Platform.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 switch (loader_type) { | 115 switch (loader_type) { |
| 116 case PLATFORM_LOADER: | 116 case PLATFORM_LOADER: |
| 117 loader_.reset(blink::Platform::current()->createURLLoader()); | 117 loader_.reset(blink::Platform::current()->createURLLoader()); |
| 118 break; | 118 break; |
| 119 case FRAME_ASSOCIATED_LOADER: | 119 case FRAME_ASSOCIATED_LOADER: |
| 120 loader_.reset(frame->createAssociatedURLLoader(options_)); | 120 loader_.reset(frame->createAssociatedURLLoader(options_)); |
| 121 break; | 121 break; |
| 122 } | 122 } |
| 123 loader_->loadAsynchronously(request_, this); | 123 loader_->loadAsynchronously(request_, this); |
| 124 | 124 |
| 125 // No need to hold on to the request. | 125 // Reset the request. |
| 126 request_.reset(); | 126 request_.setURL(GURL()); |
|
dcheng
2016/07/11 09:47:50
It's a bit unexpected that this is the right way t
kinuko
2016/07/11 09:54:23
Yup you're right this change is probably not quite
kinuko
2016/07/12 04:19:57
Took the path to simply do request_ = WebURLReques
| |
| 127 } | 127 } |
| 128 | 128 |
| 129 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) { | 129 void ResourceFetcherImpl::SetTimeout(const base::TimeDelta& timeout) { |
| 130 DCHECK(loader_); | 130 DCHECK(loader_); |
| 131 DCHECK(!completed()); | 131 DCHECK(!completed()); |
| 132 | 132 |
| 133 timeout_timer_.Start(FROM_HERE, timeout, this, &ResourceFetcherImpl::Cancel); | 133 timeout_timer_.Start(FROM_HERE, timeout, this, &ResourceFetcherImpl::Cancel); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void ResourceFetcherImpl::OnLoadComplete() { | 136 void ResourceFetcherImpl::OnLoadComplete() { |
| 137 timeout_timer_.Stop(); | 137 timeout_timer_.Stop(); |
| 138 if (callback_.is_null()) | 138 if (callback_.is_null()) |
| 139 return; | 139 return; |
| 140 | 140 |
| 141 // Take a reference to the callback as running the callback may lead to our | 141 // Take a reference to the callback as running the callback may lead to our |
| 142 // destruction. | 142 // destruction. |
| 143 Callback callback = callback_; | 143 Callback callback = callback_; |
| 144 callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(), | 144 callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(), |
| 145 status() == LOAD_FAILED ? std::string() : data()); | 145 status() == LOAD_FAILED ? std::string() : data()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void ResourceFetcherImpl::Cancel() { | 148 void ResourceFetcherImpl::Cancel() { |
| 149 loader_->cancel(); | 149 loader_->cancel(); |
| 150 WebURLLoaderClientImpl::Cancel(); | 150 WebURLLoaderClientImpl::Cancel(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace content | 153 } // namespace content |
| OLD | NEW |