| 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/browser/download/download_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 using content::ResourceDispatcherHostImpl; | 46 using content::ResourceDispatcherHostImpl; |
| 47 using content::WebContents; | 47 using content::WebContents; |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 void BeginDownload(content::DownloadUrlParameters* params) { | 51 void BeginDownload(content::DownloadUrlParameters* params) { |
| 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 53 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and | 53 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and |
| 54 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so | 54 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so |
| 55 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. | 55 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. |
| 56 content::ResourceDispatcherHostImpl* resource_dispatcher_host = | |
| 57 static_cast<content::ResourceDispatcherHostImpl*>( | |
| 58 params->resource_dispatcher_host()); | |
| 59 scoped_ptr<net::URLRequest> request(new net::URLRequest( | 56 scoped_ptr<net::URLRequest> request(new net::URLRequest( |
| 60 params->url(), resource_dispatcher_host)); | 57 params->url(), NULL)); |
| 61 request->set_referrer(params->referrer().url.spec()); | 58 request->set_referrer(params->referrer().url.spec()); |
| 62 webkit_glue::ConfigureURLRequestForReferrerPolicy( | 59 webkit_glue::ConfigureURLRequestForReferrerPolicy( |
| 63 request.get(), params->referrer().policy); | 60 request.get(), params->referrer().policy); |
| 64 request->set_load_flags(request->load_flags() | params->load_flags()); | 61 request->set_load_flags(request->load_flags() | params->load_flags()); |
| 65 request->set_method(params->method()); | 62 request->set_method(params->method()); |
| 66 if (!params->post_body().empty()) | 63 if (!params->post_body().empty()) |
| 67 request->AppendBytesToUpload(params->post_body().data(), | 64 request->AppendBytesToUpload(params->post_body().data(), |
| 68 params->post_body().size()); | 65 params->post_body().size()); |
| 69 if (params->post_id() >= 0) { | 66 if (params->post_id() >= 0) { |
| 70 // The POST in this case does not have an actual body, and only works | 67 // The POST in this case does not have an actual body, and only works |
| 71 // when retrieving data from cache. This is done because we don't want | 68 // when retrieving data from cache. This is done because we don't want |
| 72 // to do a re-POST without user consent, and currently don't have a good | 69 // to do a re-POST without user consent, and currently don't have a good |
| 73 // plan on how to display the UI for that. | 70 // plan on how to display the UI for that. |
| 74 DCHECK(params->prefer_cache()); | 71 DCHECK(params->prefer_cache()); |
| 75 DCHECK(params->method() == "POST"); | 72 DCHECK(params->method() == "POST"); |
| 76 scoped_refptr<net::UploadData> upload_data = new net::UploadData(); | 73 scoped_refptr<net::UploadData> upload_data = new net::UploadData(); |
| 77 upload_data->set_identifier(params->post_id()); | 74 upload_data->set_identifier(params->post_id()); |
| 78 request->set_upload(upload_data); | 75 request->set_upload(upload_data); |
| 79 } | 76 } |
| 80 for (content::DownloadUrlParameters::RequestHeadersType::const_iterator iter | 77 for (content::DownloadUrlParameters::RequestHeadersType::const_iterator iter |
| 81 = params->request_headers_begin(); | 78 = params->request_headers_begin(); |
| 82 iter != params->request_headers_end(); | 79 iter != params->request_headers_end(); |
| 83 ++iter) { | 80 ++iter) { |
| 84 request->SetExtraRequestHeaderByName( | 81 request->SetExtraRequestHeaderByName( |
| 85 iter->first, iter->second, false/*overwrite*/); | 82 iter->first, iter->second, false/*overwrite*/); |
| 86 } | 83 } |
| 87 resource_dispatcher_host->BeginDownload( | 84 params->resource_dispatcher_host()->BeginDownload( |
| 88 request.Pass(), | 85 request.Pass(), |
| 89 params->content_initiated(), | 86 params->content_initiated(), |
| 90 params->resource_context(), | 87 params->resource_context(), |
| 91 params->render_process_host_id(), | 88 params->render_process_host_id(), |
| 92 params->render_view_host_routing_id(), | 89 params->render_view_host_routing_id(), |
| 93 params->prefer_cache(), | 90 params->prefer_cache(), |
| 94 params->save_info(), | 91 params->save_info(), |
| 95 params->callback()); | 92 params->callback()); |
| 96 } | 93 } |
| 97 | 94 |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1174 void DownloadManagerImpl::DownloadRenamedToFinalName( |
| 1178 DownloadItem* download) { | 1175 DownloadItem* download) { |
| 1179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1180 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1177 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1181 // receive the DownloadRenamedToFinalName() call. | 1178 // receive the DownloadRenamedToFinalName() call. |
| 1182 if (delegate_) { | 1179 if (delegate_) { |
| 1183 delegate_->UpdatePathForItemInPersistentStore( | 1180 delegate_->UpdatePathForItemInPersistentStore( |
| 1184 download, download->GetFullPath()); | 1181 download, download->GetFullPath()); |
| 1185 } | 1182 } |
| 1186 } | 1183 } |
| OLD | NEW |