Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/loader/navigation_url_loader_core.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/location.h" | |
| 9 #include "content/browser/frame_host/navigation_request_info.h" | |
| 10 #include "content/browser/loader/navigation_resource_handler.h" | |
| 11 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
| 12 #include "content/common/navigation_params.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 14 #include "content/public/browser/stream_handle.h" | |
| 15 #include "content/public/common/resource_response.h" | |
| 16 #include "net/base/net_errors.h" | |
| 17 #include "net/url_request/redirect_info.h" | |
| 18 | |
| 19 namespace content { | |
| 20 | |
| 21 NavigationURLLoaderCore::NavigationURLLoaderCore( | |
| 22 const base::WeakPtr<NavigationURLLoaderImpl>& loader) | |
| 23 : loader_(loader), | |
| 24 resource_handler_(nullptr) { | |
| 25 } | |
| 26 | |
| 27 NavigationURLLoaderCore::~NavigationURLLoaderCore() { | |
| 28 if (resource_handler_) { | |
| 29 resource_handler_->Cancel(); | |
|
mmenke
2014/10/22 15:32:58
Not a real issue, but just for my edification...Th
davidben
2014/10/22 20:58:04
Well, there isn't a WeakPtr on this end. The Cance
| |
| 30 resource_handler_ = nullptr; | |
|
mmenke
2014/10/22 15:32:58
NULLing out resource_handler_ doesn't seem to get
davidben
2014/10/22 20:58:04
Done.
| |
| 31 } | |
| 32 } | |
| 33 | |
| 34 void NavigationURLLoaderCore::Start( | |
| 35 ResourceContext* resource_context, | |
| 36 int64 frame_tree_node_id, | |
| 37 const CommonNavigationParams& common_params, | |
| 38 scoped_ptr<NavigationRequestInfo> request_info, | |
| 39 ResourceRequestBody* request_body) { | |
| 40 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( | |
| 41 resource_context, frame_tree_node_id, | |
| 42 common_params, *request_info, request_body, | |
| 43 this); | |
| 44 } | |
| 45 | |
| 46 void NavigationURLLoaderCore::FollowRedirect() { | |
| 47 if (resource_handler_) | |
| 48 resource_handler_->FollowRedirect(); | |
| 49 } | |
| 50 | |
| 51 | |
| 52 void NavigationURLLoaderCore::NotifyRequestRedirected( | |
| 53 const net::RedirectInfo& redirect_info, | |
| 54 ResourceResponse* response) { | |
| 55 // Make a copy of the ResourceResponse before it is passed to another thread. | |
| 56 // | |
| 57 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | |
| 58 // reference counted and the loader stack passed unique ownership of the | |
| 59 // response. https://crbug.com/416050 | |
| 60 BrowserThread::PostTask( | |
| 61 BrowserThread::UI, FROM_HERE, | |
| 62 base::Bind(&NavigationURLLoaderImpl::NotifyRequestRedirected, loader_, | |
| 63 redirect_info, response->DeepCopy())); | |
| 64 } | |
| 65 | |
| 66 void NavigationURLLoaderCore::NotifyResponseStarted( | |
| 67 ResourceResponse* response, | |
| 68 scoped_ptr<StreamHandle> body) { | |
| 69 // If, by the time the task reaches the UI thread, |loader_| has already been | |
| 70 // destroyed, NotifyResponseStarted will not run. |body| will be destructed | |
| 71 // and the request released at that point. | |
| 72 | |
| 73 // Make a copy of the ResourceResponse before it is passed to another thread. | |
| 74 // | |
| 75 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | |
| 76 // reference counted and the loader stack passed unique ownership of the | |
| 77 // response. https://crbug.com/416050 | |
| 78 BrowserThread::PostTask( | |
| 79 BrowserThread::UI, FROM_HERE, | |
| 80 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, | |
| 81 response->DeepCopy(), base::Passed(&body))); | |
| 82 } | |
| 83 | |
| 84 void NavigationURLLoaderCore::NotifyRequestFailed(int net_error) { | |
| 85 BrowserThread::PostTask( | |
| 86 BrowserThread::UI, FROM_HERE, | |
| 87 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, | |
| 88 net_error)); | |
| 89 } | |
| 90 | |
| 91 } // namespace content | |
| OLD | NEW |