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