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_impl_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 NavigationURLLoaderImplCore::NavigationURLLoaderImplCore( | |
| 22 const base::WeakPtr<NavigationURLLoaderImpl>& loader) | |
| 23 : loader_(loader), | |
| 24 resource_handler_(nullptr) { | |
| 25 // This object is created on the UI thread but otherwise lives entirely on the | |
|
nasko
2014/10/23 22:36:17
nit: Let's add that it is also deleted on the IO t
davidben
2014/10/27 20:46:04
Done.
| |
| 26 // IO thread. | |
| 27 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 28 } | |
| 29 | |
| 30 NavigationURLLoaderImplCore::~NavigationURLLoaderImplCore() { | |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 32 | |
| 33 if (resource_handler_) | |
| 34 resource_handler_->Cancel(); | |
| 35 } | |
| 36 | |
| 37 void NavigationURLLoaderImplCore::Start( | |
| 38 ResourceContext* resource_context, | |
| 39 int64 frame_tree_node_id, | |
| 40 const CommonNavigationParams& common_params, | |
| 41 scoped_ptr<NavigationRequestInfo> request_info, | |
| 42 ResourceRequestBody* request_body) { | |
| 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 44 | |
| 45 ResourceDispatcherHostImpl::Get()->BeginNavigationRequest( | |
| 46 resource_context, frame_tree_node_id, | |
| 47 common_params, *request_info, request_body, | |
| 48 this); | |
| 49 } | |
| 50 | |
| 51 void NavigationURLLoaderImplCore::FollowRedirect() { | |
| 52 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 53 | |
| 54 if (resource_handler_) | |
| 55 resource_handler_->FollowRedirect(); | |
| 56 } | |
| 57 | |
| 58 | |
| 59 void NavigationURLLoaderImplCore::NotifyRequestRedirected( | |
| 60 const net::RedirectInfo& redirect_info, | |
| 61 ResourceResponse* response) { | |
| 62 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 63 | |
| 64 // Make a copy of the ResourceResponse before it is passed to another thread. | |
| 65 // | |
| 66 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | |
| 67 // reference counted and the loader stack passed unique ownership of the | |
| 68 // response. https://crbug.com/416050 | |
| 69 BrowserThread::PostTask( | |
| 70 BrowserThread::UI, FROM_HERE, | |
| 71 base::Bind(&NavigationURLLoaderImpl::NotifyRequestRedirected, loader_, | |
| 72 redirect_info, response->DeepCopy())); | |
| 73 } | |
| 74 | |
| 75 void NavigationURLLoaderImplCore::NotifyResponseStarted( | |
| 76 ResourceResponse* response, | |
| 77 scoped_ptr<StreamHandle> body) { | |
| 78 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 79 | |
| 80 // If, by the time the task reaches the UI thread, |loader_| has already been | |
| 81 // destroyed, NotifyResponseStarted will not run. |body| will be destructed | |
| 82 // and the request released at that point. | |
| 83 | |
| 84 // Make a copy of the ResourceResponse before it is passed to another thread. | |
| 85 // | |
| 86 // TODO(davidben): This copy could be avoided if ResourceResponse weren't | |
| 87 // reference counted and the loader stack passed unique ownership of the | |
| 88 // response. https://crbug.com/416050 | |
| 89 BrowserThread::PostTask( | |
| 90 BrowserThread::UI, FROM_HERE, | |
| 91 base::Bind(&NavigationURLLoaderImpl::NotifyResponseStarted, loader_, | |
| 92 response->DeepCopy(), base::Passed(&body))); | |
| 93 } | |
| 94 | |
| 95 void NavigationURLLoaderImplCore::NotifyRequestFailed(int net_error) { | |
| 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 97 | |
| 98 BrowserThread::PostTask( | |
| 99 BrowserThread::UI, FROM_HERE, | |
| 100 base::Bind(&NavigationURLLoaderImpl::NotifyRequestFailed, loader_, | |
| 101 net_error)); | |
| 102 } | |
| 103 | |
| 104 } // namespace content | |
| OLD | NEW |