| 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 16 matching lines...) Expand all Loading... |
| 27 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 27 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 28 #include "content/browser/tab_contents/tab_contents.h" | 28 #include "content/browser/tab_contents/tab_contents.h" |
| 29 #include "content/public/browser/browser_context.h" | 29 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
| 32 #include "content/public/browser/download_manager_delegate.h" | 32 #include "content/public/browser/download_manager_delegate.h" |
| 33 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
| 34 #include "content/public/browser/notification_types.h" | 34 #include "content/public/browser/notification_types.h" |
| 35 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/web_contents_delegate.h" | 36 #include "content/public/browser/web_contents_delegate.h" |
| 37 #include "net/base/upload_data.h" |
| 37 | 38 |
| 38 // TODO(benjhayden): Change this to DCHECK when we have more debugging | 39 // TODO(benjhayden): Change this to DCHECK when we have more debugging |
| 39 // information from the next dev cycle, before the next stable/beta branch is | 40 // information from the next dev cycle, before the next stable/beta branch is |
| 40 // cut, in order to prevent unnecessary crashes on those channels. If we still | 41 // cut, in order to prevent unnecessary crashes on those channels. If we still |
| 41 // don't have root cause before the dev cycle after the next stable/beta | 42 // don't have root cause before the dev cycle after the next stable/beta |
| 42 // releases, uncomment it out to re-enable debugging checks. Whenever this macro | 43 // releases, uncomment it out to re-enable debugging checks. Whenever this macro |
| 43 // is toggled, the corresponding macro in download_database.cc should also | 44 // is toggled, the corresponding macro in download_database.cc should also |
| 44 // be toggled. When 96627 is fixed, this macro and all its usages can be | 45 // be toggled. When 96627 is fixed, this macro and all its usages can be |
| 45 // deleted or permanently changed to DCHECK as appropriate. | 46 // deleted or permanently changed to DCHECK as appropriate. |
| 46 #define CHECK_96627 CHECK | 47 #define CHECK_96627 CHECK |
| 47 | 48 |
| 48 using content::BrowserThread; | 49 using content::BrowserThread; |
| 49 using content::DownloadId; | 50 using content::DownloadId; |
| 50 using content::DownloadItem; | 51 using content::DownloadItem; |
| 51 using content::WebContents; | 52 using content::WebContents; |
| 52 | 53 |
| 53 namespace { | 54 namespace { |
| 54 | 55 |
| 55 // Param structs exist because base::Bind can only handle 6 args. | 56 // Param structs exist because base::Bind can only handle 6 args. |
| 56 struct URLParams { | 57 struct URLParams { |
| 57 URLParams(const GURL& url, const GURL& referrer) | 58 URLParams(const GURL& url, const GURL& referrer, int64 post_id) |
| 58 : url_(url), referrer_(referrer) {} | 59 : url_(url), referrer_(referrer), post_id_(post_id) {} |
| 59 GURL url_; | 60 GURL url_; |
| 60 GURL referrer_; | 61 GURL referrer_; |
| 62 int64 post_id_; |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 struct RenderParams { | 65 struct RenderParams { |
| 64 RenderParams(int rpi, int rvi) | 66 RenderParams(int rpi, int rvi) |
| 65 : render_process_id_(rpi), render_view_id_(rvi) {} | 67 : render_process_id_(rpi), render_view_id_(rvi) {} |
| 66 int render_process_id_; | 68 int render_process_id_; |
| 67 int render_view_id_; | 69 int render_view_id_; |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 void BeginDownload(const URLParams& url_params, | 72 void BeginDownload(const URLParams& url_params, |
| 71 bool prefer_cache, | 73 bool prefer_cache, |
| 72 const DownloadSaveInfo& save_info, | 74 const DownloadSaveInfo& save_info, |
| 73 ResourceDispatcherHost* resource_dispatcher_host, | 75 ResourceDispatcherHost* resource_dispatcher_host, |
| 74 const RenderParams& render_params, | 76 const RenderParams& render_params, |
| 75 const content::ResourceContext* context) { | 77 const content::ResourceContext* context) { |
| 76 scoped_ptr<net::URLRequest> request( | 78 scoped_ptr<net::URLRequest> request( |
| 77 new net::URLRequest(url_params.url_, resource_dispatcher_host)); | 79 new net::URLRequest(url_params.url_, resource_dispatcher_host)); |
| 78 request->set_referrer(url_params.referrer_.spec()); | 80 request->set_referrer(url_params.referrer_.spec()); |
| 81 if (url_params.post_id_ >= 0) { |
| 82 // The POST in this case does not have an actual body, and only works |
| 83 // when retrieving data from cache. This is done because we don't want |
| 84 // to do a re-POST without user consent, and currently don't have a good |
| 85 // plan on how to display the UI for that. |
| 86 DCHECK(prefer_cache); |
| 87 request->set_method("POST"); |
| 88 scoped_refptr<net::UploadData> upload_data = new net::UploadData(); |
| 89 upload_data->set_identifier(url_params.post_id_); |
| 90 request->set_upload(upload_data); |
| 91 } |
| 79 resource_dispatcher_host->BeginDownload( | 92 resource_dispatcher_host->BeginDownload( |
| 80 request.Pass(), prefer_cache, save_info, | 93 request.Pass(), prefer_cache, save_info, |
| 81 DownloadResourceHandler::OnStartedCallback(), | 94 DownloadResourceHandler::OnStartedCallback(), |
| 82 render_params.render_process_id_, | 95 render_params.render_process_id_, |
| 83 render_params.render_view_id_, | 96 render_params.render_view_id_, |
| 84 *context); | 97 *context); |
| 85 } | 98 } |
| 86 | 99 |
| 87 class MapValueIteratorAdapter { | 100 class MapValueIteratorAdapter { |
| 88 public: | 101 public: |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 } | 820 } |
| 808 | 821 |
| 809 // Initiate a download of a specific URL. We send the request to the | 822 // Initiate a download of a specific URL. We send the request to the |
| 810 // ResourceDispatcherHost, and let it send us responses like a regular | 823 // ResourceDispatcherHost, and let it send us responses like a regular |
| 811 // download. | 824 // download. |
| 812 void DownloadManagerImpl::DownloadUrl( | 825 void DownloadManagerImpl::DownloadUrl( |
| 813 const GURL& url, | 826 const GURL& url, |
| 814 const GURL& referrer, | 827 const GURL& referrer, |
| 815 const std::string& referrer_charset, | 828 const std::string& referrer_charset, |
| 816 bool prefer_cache, | 829 bool prefer_cache, |
| 830 int64 post_id, |
| 817 const DownloadSaveInfo& save_info, | 831 const DownloadSaveInfo& save_info, |
| 818 WebContents* web_contents) { | 832 WebContents* web_contents) { |
| 819 ResourceDispatcherHost* resource_dispatcher_host = | 833 ResourceDispatcherHost* resource_dispatcher_host = |
| 820 ResourceDispatcherHost::Get(); | 834 ResourceDispatcherHost::Get(); |
| 821 | 835 |
| 822 // We send a pointer to content::ResourceContext, instead of the usual | 836 // We send a pointer to content::ResourceContext, instead of the usual |
| 823 // reference, so that a copy of the object isn't made. | 837 // reference, so that a copy of the object isn't made. |
| 824 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. | 838 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. |
| 825 BrowserThread::PostTask( | 839 BrowserThread::PostTask( |
| 826 BrowserThread::IO, FROM_HERE, | 840 BrowserThread::IO, FROM_HERE, |
| 827 base::Bind( | 841 base::Bind( |
| 828 &BeginDownload, | 842 &BeginDownload, |
| 829 URLParams(url, referrer), | 843 URLParams(url, referrer, post_id), |
| 830 prefer_cache, | 844 prefer_cache, |
| 831 save_info, | 845 save_info, |
| 832 resource_dispatcher_host, | 846 resource_dispatcher_host, |
| 833 RenderParams(web_contents->GetRenderProcessHost()->GetID(), | 847 RenderParams(web_contents->GetRenderProcessHost()->GetID(), |
| 834 web_contents->GetRenderViewHost()->routing_id()), | 848 web_contents->GetRenderViewHost()->routing_id()), |
| 835 &web_contents->GetBrowserContext()->GetResourceContext())); | 849 &web_contents->GetBrowserContext()->GetResourceContext())); |
| 836 } | 850 } |
| 837 | 851 |
| 838 void DownloadManagerImpl::AddObserver(Observer* observer) { | 852 void DownloadManagerImpl::AddObserver(Observer* observer) { |
| 839 observers_.AddObserver(observer); | 853 observers_.AddObserver(observer); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 it != history_downloads_.end(); ++it) { | 1166 it != history_downloads_.end(); ++it) { |
| 1153 if (it->second->IsComplete() && !it->second->GetOpened()) | 1167 if (it->second->IsComplete() && !it->second->GetOpened()) |
| 1154 ++num_unopened; | 1168 ++num_unopened; |
| 1155 } | 1169 } |
| 1156 download_stats::RecordOpensOutstanding(num_unopened); | 1170 download_stats::RecordOpensOutstanding(num_unopened); |
| 1157 } | 1171 } |
| 1158 | 1172 |
| 1159 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { | 1173 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { |
| 1160 file_manager_ = file_manager; | 1174 file_manager_ = file_manager; |
| 1161 } | 1175 } |
| OLD | NEW |