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 22 matching lines...) Expand all Loading... |
33 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/download_interrupt_reasons.h" | 34 #include "content/public/browser/download_interrupt_reasons.h" |
35 #include "content/public/browser/download_manager_delegate.h" | 35 #include "content/public/browser/download_manager_delegate.h" |
36 #include "content/public/browser/download_url_parameters.h" | 36 #include "content/public/browser/download_url_parameters.h" |
37 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
38 #include "content/public/browser/notification_types.h" | 38 #include "content/public/browser/notification_types.h" |
39 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
40 #include "content/public/browser/resource_context.h" | 40 #include "content/public/browser/resource_context.h" |
41 #include "content/public/browser/web_contents_delegate.h" | 41 #include "content/public/browser/web_contents_delegate.h" |
42 #include "net/base/load_flags.h" | 42 #include "net/base/load_flags.h" |
43 #include "net/base/upload_data.h" | 43 #include "net/base/upload_bytes_element_reader.h" |
| 44 #include "net/base/upload_data_stream.h" |
44 #include "net/url_request/url_request_context.h" | 45 #include "net/url_request/url_request_context.h" |
45 #include "webkit/glue/webkit_glue.h" | 46 #include "webkit/glue/webkit_glue.h" |
46 | 47 |
47 namespace content { | 48 namespace content { |
48 namespace { | 49 namespace { |
49 | 50 |
50 void BeginDownload(scoped_ptr<DownloadUrlParameters> params) { | 51 void BeginDownload(scoped_ptr<DownloadUrlParameters> params) { |
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
52 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and | 53 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and |
53 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so | 54 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so |
54 // 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. |
55 scoped_ptr<net::URLRequest> request( | 56 scoped_ptr<net::URLRequest> request( |
56 params->resource_context()->GetRequestContext()->CreateRequest( | 57 params->resource_context()->GetRequestContext()->CreateRequest( |
57 params->url(), NULL)); | 58 params->url(), NULL)); |
58 request->set_referrer(params->referrer().url.spec()); | 59 request->set_referrer(params->referrer().url.spec()); |
59 webkit_glue::ConfigureURLRequestForReferrerPolicy( | 60 webkit_glue::ConfigureURLRequestForReferrerPolicy( |
60 request.get(), params->referrer().policy); | 61 request.get(), params->referrer().policy); |
61 request->set_load_flags(request->load_flags() | params->load_flags()); | 62 request->set_load_flags(request->load_flags() | params->load_flags()); |
62 request->set_method(params->method()); | 63 request->set_method(params->method()); |
63 if (!params->post_body().empty()) { | 64 if (!params->post_body().empty()) { |
64 scoped_refptr<net::UploadData> upload_data(new net::UploadData()); | 65 const std::string& body = params->post_body(); |
65 upload_data->AppendBytes(params->post_body().data(), | 66 scoped_ptr<net::UploadElementReader> reader( |
66 params->post_body().size()); | 67 net::UploadOwnedBytesElementReader::CreateWithString(body)); |
67 request->set_upload(upload_data); | 68 request->set_upload(make_scoped_ptr( |
| 69 net::UploadDataStream::CreateWithReader(reader.Pass(), 0))); |
68 } | 70 } |
69 if (params->post_id() >= 0) { | 71 if (params->post_id() >= 0) { |
70 // The POST in this case does not have an actual body, and only works | 72 // 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 | 73 // 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 | 74 // 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. | 75 // plan on how to display the UI for that. |
74 DCHECK(params->prefer_cache()); | 76 DCHECK(params->prefer_cache()); |
75 DCHECK(params->method() == "POST"); | 77 DCHECK(params->method() == "POST"); |
76 scoped_refptr<net::UploadData> upload_data = new net::UploadData(); | 78 ScopedVector<net::UploadElementReader> element_readers; |
77 upload_data->set_identifier(params->post_id()); | 79 request->set_upload(make_scoped_ptr( |
78 request->set_upload(upload_data); | 80 new net::UploadDataStream(&element_readers, params->post_id()))); |
79 } | 81 } |
80 for (DownloadUrlParameters::RequestHeadersType::const_iterator iter | 82 for (DownloadUrlParameters::RequestHeadersType::const_iterator iter |
81 = params->request_headers_begin(); | 83 = params->request_headers_begin(); |
82 iter != params->request_headers_end(); | 84 iter != params->request_headers_end(); |
83 ++iter) { | 85 ++iter) { |
84 request->SetExtraRequestHeaderByName( | 86 request->SetExtraRequestHeaderByName( |
85 iter->first, iter->second, false/*overwrite*/); | 87 iter->first, iter->second, false/*overwrite*/); |
86 } | 88 } |
87 | 89 |
88 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); | 90 scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 it != downloads_.end(); ++it) { | 627 it != downloads_.end(); ++it) { |
626 DownloadItemImpl* item = it->second; | 628 DownloadItemImpl* item = it->second; |
627 if (item->IsComplete() && | 629 if (item->IsComplete() && |
628 !item->GetOpened()) | 630 !item->GetOpened()) |
629 ++num_unopened; | 631 ++num_unopened; |
630 } | 632 } |
631 RecordOpensOutstanding(num_unopened); | 633 RecordOpensOutstanding(num_unopened); |
632 } | 634 } |
633 | 635 |
634 } // namespace content | 636 } // namespace content |
OLD | NEW |