Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: content/browser/download/download_manager_impl.cc

Issue 9314037: Save As for content retrieved via POST works in most circumstances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test page Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
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/download_query.h" 34 #include "content/public/browser/download_query.h"
35 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/notification_types.h" 36 #include "content/public/browser/notification_types.h"
37 #include "content/public/browser/render_process_host.h" 37 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/web_contents_delegate.h" 38 #include "content/public/browser/web_contents_delegate.h"
39 #include "net/base/upload_data.h"
39 40
40 // TODO(benjhayden): Change this to DCHECK when we have more debugging 41 // TODO(benjhayden): Change this to DCHECK when we have more debugging
41 // information from the next dev cycle, before the next stable/beta branch is 42 // information from the next dev cycle, before the next stable/beta branch is
42 // cut, in order to prevent unnecessary crashes on those channels. If we still 43 // cut, in order to prevent unnecessary crashes on those channels. If we still
43 // don't have root cause before the dev cycle after the next stable/beta 44 // don't have root cause before the dev cycle after the next stable/beta
44 // releases, uncomment it out to re-enable debugging checks. Whenever this macro 45 // releases, uncomment it out to re-enable debugging checks. Whenever this macro
45 // is toggled, the corresponding macro in download_database.cc should also 46 // is toggled, the corresponding macro in download_database.cc should also
46 // be toggled. When 96627 is fixed, this macro and all its usages can be 47 // be toggled. When 96627 is fixed, this macro and all its usages can be
47 // deleted or permanently changed to DCHECK as appropriate. 48 // deleted or permanently changed to DCHECK as appropriate.
48 #define CHECK_96627 CHECK 49 #define CHECK_96627 CHECK
49 50
50 using content::BrowserThread; 51 using content::BrowserThread;
51 using content::DownloadId; 52 using content::DownloadId;
52 using content::DownloadItem; 53 using content::DownloadItem;
53 using content::WebContents; 54 using content::WebContents;
54 55
55 namespace { 56 namespace {
56 57
57 // Param structs exist because base::Bind can only handle 6 args. 58 // Param structs exist because base::Bind can only handle 6 args.
58 struct URLParams { 59 struct URLParams {
59 URLParams(const GURL& url, const GURL& referrer) 60 URLParams(const GURL& url, const GURL& referrer, int64 post_id)
60 : url_(url), referrer_(referrer) {} 61 : url_(url), referrer_(referrer), post_id_(post_id) {}
61 GURL url_; 62 GURL url_;
62 GURL referrer_; 63 GURL referrer_;
64 int64 post_id_;
63 }; 65 };
64 66
65 struct RenderParams { 67 struct RenderParams {
66 RenderParams(int rpi, int rvi) 68 RenderParams(int rpi, int rvi)
67 : render_process_id_(rpi), render_view_id_(rvi) {} 69 : render_process_id_(rpi), render_view_id_(rvi) {}
68 int render_process_id_; 70 int render_process_id_;
69 int render_view_id_; 71 int render_view_id_;
70 }; 72 };
71 73
72 void BeginDownload(const URLParams& url_params, 74 void BeginDownload(const URLParams& url_params,
73 bool prefer_cache, 75 bool prefer_cache,
74 const DownloadSaveInfo& save_info, 76 const DownloadSaveInfo& save_info,
75 ResourceDispatcherHost* resource_dispatcher_host, 77 ResourceDispatcherHost* resource_dispatcher_host,
76 const RenderParams& render_params, 78 const RenderParams& render_params,
77 const content::ResourceContext* context) { 79 const content::ResourceContext* context) {
78 scoped_ptr<net::URLRequest> request( 80 scoped_ptr<net::URLRequest> request(
79 new net::URLRequest(url_params.url_, resource_dispatcher_host)); 81 new net::URLRequest(url_params.url_, resource_dispatcher_host));
80 request->set_referrer(url_params.referrer_.spec()); 82 request->set_referrer(url_params.referrer_.spec());
83 if (url_params.post_id_ >= 0) {
Randy Smith (Not in Mondays) 2012/02/02 19:46:10 If we decide that we eventually want to support PO
cbentzel 2012/02/03 15:54:47 Done.
84 // The POST in this case does not have an actual body, and only works
85 // when retrieving data from cache.
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 }
81 resource_dispatcher_host->BeginDownload( 92 resource_dispatcher_host->BeginDownload(
82 request.Pass(), prefer_cache, save_info, 93 request.Pass(), prefer_cache, save_info,
83 DownloadResourceHandler::OnStartedCallback(), 94 DownloadResourceHandler::OnStartedCallback(),
84 render_params.render_process_id_, 95 render_params.render_process_id_,
85 render_params.render_view_id_, 96 render_params.render_view_id_,
86 *context); 97 *context);
87 } 98 }
88 99
89 class MapValueIteratorAdapter { 100 class MapValueIteratorAdapter {
90 public: 101 public:
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 } 839 }
829 840
830 // Initiate a download of a specific URL. We send the request to the 841 // Initiate a download of a specific URL. We send the request to the
831 // ResourceDispatcherHost, and let it send us responses like a regular 842 // ResourceDispatcherHost, and let it send us responses like a regular
832 // download. 843 // download.
833 void DownloadManagerImpl::DownloadUrl( 844 void DownloadManagerImpl::DownloadUrl(
834 const GURL& url, 845 const GURL& url,
835 const GURL& referrer, 846 const GURL& referrer,
836 const std::string& referrer_charset, 847 const std::string& referrer_charset,
837 bool prefer_cache, 848 bool prefer_cache,
849 int64 post_id,
838 const DownloadSaveInfo& save_info, 850 const DownloadSaveInfo& save_info,
839 WebContents* web_contents) { 851 WebContents* web_contents) {
840 ResourceDispatcherHost* resource_dispatcher_host = 852 ResourceDispatcherHost* resource_dispatcher_host =
841 ResourceDispatcherHost::Get(); 853 ResourceDispatcherHost::Get();
842 854
843 // We send a pointer to content::ResourceContext, instead of the usual 855 // We send a pointer to content::ResourceContext, instead of the usual
844 // reference, so that a copy of the object isn't made. 856 // reference, so that a copy of the object isn't made.
845 // base::Bind can't handle 7 args, so we use URLParams and RenderParams. 857 // base::Bind can't handle 7 args, so we use URLParams and RenderParams.
846 BrowserThread::PostTask( 858 BrowserThread::PostTask(
847 BrowserThread::IO, FROM_HERE, 859 BrowserThread::IO, FROM_HERE,
848 base::Bind( 860 base::Bind(
849 &BeginDownload, 861 &BeginDownload,
850 URLParams(url, referrer), 862 URLParams(url, referrer, post_id),
851 prefer_cache, 863 prefer_cache,
852 save_info, 864 save_info,
853 resource_dispatcher_host, 865 resource_dispatcher_host,
854 RenderParams(web_contents->GetRenderProcessHost()->GetID(), 866 RenderParams(web_contents->GetRenderProcessHost()->GetID(),
855 web_contents->GetRenderViewHost()->routing_id()), 867 web_contents->GetRenderViewHost()->routing_id()),
856 &web_contents->GetBrowserContext()->GetResourceContext())); 868 &web_contents->GetBrowserContext()->GetResourceContext()));
857 } 869 }
858 870
859 void DownloadManagerImpl::AddObserver(Observer* observer) { 871 void DownloadManagerImpl::AddObserver(Observer* observer) {
860 observers_.AddObserver(observer); 872 observers_.AddObserver(observer);
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 it != history_downloads_.end(); ++it) { 1219 it != history_downloads_.end(); ++it) {
1208 if (it->second->IsComplete() && !it->second->GetOpened()) 1220 if (it->second->IsComplete() && !it->second->GetOpened())
1209 ++num_unopened; 1221 ++num_unopened;
1210 } 1222 }
1211 download_stats::RecordOpensOutstanding(num_unopened); 1223 download_stats::RecordOpensOutstanding(num_unopened);
1212 } 1224 }
1213 1225
1214 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) { 1226 void DownloadManagerImpl::SetFileManager(DownloadFileManager* file_manager) {
1215 file_manager_ = file_manager; 1227 file_manager_ = file_manager;
1216 } 1228 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698