summaryrefslogtreecommitdiff
path: root/content/browser/download
diff options
context:
space:
mode:
authorTorne (Richard Coles) <torne@google.com>2013-11-28 11:55:43 +0000
committerTorne (Richard Coles) <torne@google.com>2013-11-28 11:55:43 +0000
commitf2477e01787aa58f445919b809d89e252beef54f (patch)
tree2db962b4af39f0db3a5f83b314373d0530c484b8 /content/browser/download
parent7daea1dd5ff7e419322de831b642d81af3247912 (diff)
downloadchromium_org-f2477e01787aa58f445919b809d89e252beef54f.tar.gz
Merge from Chromium at DEPS revision 237746
This commit was generated by merge_to_master.py. Change-Id: I8997af4cddfeb09a7c26f7e8e672c712cab461ea
Diffstat (limited to 'content/browser/download')
-rw-r--r--content/browser/download/download_create_info.cc17
-rw-r--r--content/browser/download/download_create_info.h3
-rw-r--r--content/browser/download/download_manager_impl.cc9
-rw-r--r--content/browser/download/download_resource_handler.cc98
-rw-r--r--content/browser/download/download_resource_handler.h16
-rw-r--r--content/browser/download/download_stats.cc8
-rw-r--r--content/browser/download/download_stats.h21
-rw-r--r--content/browser/download/drag_download_file_browsertest.cc13
-rw-r--r--content/browser/download/file_metadata_unittest_linux.cc2
-rw-r--r--content/browser/download/save_file_resource_handler.cc6
-rw-r--r--content/browser/download/save_file_resource_handler.h5
-rw-r--r--content/browser/download/save_package.cc2
12 files changed, 85 insertions, 115 deletions
diff --git a/content/browser/download/download_create_info.cc b/content/browser/download/download_create_info.cc
index 8c47cabd03..e381fa854b 100644
--- a/content/browser/download/download_create_info.cc
+++ b/content/browser/download/download_create_info.cc
@@ -11,20 +11,19 @@
namespace content {
-DownloadCreateInfo::DownloadCreateInfo(
- const base::Time& start_time,
- int64 total_bytes,
- const net::BoundNetLog& bound_net_log,
- bool has_user_gesture,
- PageTransition transition_type)
+DownloadCreateInfo::DownloadCreateInfo(const base::Time& start_time,
+ int64 total_bytes,
+ const net::BoundNetLog& bound_net_log,
+ bool has_user_gesture,
+ PageTransition transition_type,
+ scoped_ptr<DownloadSaveInfo> save_info)
: start_time(start_time),
total_bytes(total_bytes),
download_id(DownloadItem::kInvalidId),
has_user_gesture(has_user_gesture),
transition_type(transition_type),
- save_info(new DownloadSaveInfo()),
- request_bound_net_log(bound_net_log) {
-}
+ save_info(save_info.Pass()),
+ request_bound_net_log(bound_net_log) {}
DownloadCreateInfo::DownloadCreateInfo()
: total_bytes(0),
diff --git a/content/browser/download/download_create_info.h b/content/browser/download/download_create_info.h
index 4326b2428b..e032fbf293 100644
--- a/content/browser/download/download_create_info.h
+++ b/content/browser/download/download_create_info.h
@@ -28,7 +28,8 @@ struct CONTENT_EXPORT DownloadCreateInfo {
int64 total_bytes,
const net::BoundNetLog& bound_net_log,
bool has_user_gesture,
- PageTransition transition_type);
+ PageTransition transition_type,
+ scoped_ptr<DownloadSaveInfo> save_info);
DownloadCreateInfo();
~DownloadCreateInfo();
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index bd66f0677e..ea0f305a5a 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -57,7 +57,7 @@ void BeginDownload(scoped_ptr<DownloadUrlParameters> params,
scoped_ptr<net::URLRequest> request(
params->resource_context()->GetRequestContext()->CreateRequest(
params->url(), net::DEFAULT_PRIORITY, NULL));
- request->set_load_flags(request->load_flags() | params->load_flags());
+ request->SetLoadFlags(request->load_flags() | params->load_flags());
request->set_method(params->method());
if (!params->post_body().empty()) {
const std::string& body = params->post_body();
@@ -157,13 +157,6 @@ class MapValueIteratorAdapter {
// Allow copy and assign.
};
-void EnsureNoPendingDownloadJobsOnFile(bool* result) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- *result = (DownloadFile::GetNumberOfDownloadFiles() == 0);
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
-}
-
class DownloadItemFactoryImpl : public DownloadItemFactory {
public:
DownloadItemFactoryImpl() {}
diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc
index fded1ebce9..9f00ef660b 100644
--- a/content/browser/download/download_resource_handler.cc
+++ b/content/browser/download/download_resource_handler.cc
@@ -76,7 +76,6 @@ DownloadResourceHandler::DownloadResourceHandler(
scoped_ptr<DownloadSaveInfo> save_info)
: ResourceHandler(request),
download_id_(id),
- content_length_(0),
started_cb_(started_cb),
save_info_(save_info.Pass()),
last_buffer_size_(0),
@@ -125,19 +124,22 @@ bool DownloadResourceHandler::OnResponseStarted(
// with main frames.
request()->SetPriority(net::IDLE);
- std::string content_disposition;
- request()->GetResponseHeaderByName("content-disposition",
- &content_disposition);
- SetContentDisposition(content_disposition);
- SetContentLength(response->head.content_length);
+ // If the content-length header is not present (or contains something other
+ // than numbers), the incoming content_length is -1 (unknown size).
+ // Set the content length to 0 to indicate unknown size to DownloadManager.
+ int64 content_length =
+ response->head.content_length > 0 ? response->head.content_length : 0;
const ResourceRequestInfoImpl* request_info = GetRequestInfo();
// Deleted in DownloadManager.
- scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo(
- base::Time::Now(), content_length_,
- request()->net_log(), request_info->HasUserGesture(),
- request_info->GetPageTransition()));
+ scoped_ptr<DownloadCreateInfo> info(
+ new DownloadCreateInfo(base::Time::Now(),
+ content_length,
+ request()->net_log(),
+ request_info->HasUserGesture(),
+ request_info->GetPageTransition(),
+ save_info_.Pass()));
// Create the ByteStream for sending data to the download sink.
scoped_ptr<ByteStreamReader> stream_reader;
@@ -151,12 +153,10 @@ bool DownloadResourceHandler::OnResponseStarted(
info->download_id = download_id_;
info->url_chain = request()->url_chain();
info->referrer_url = GURL(request()->referrer());
- info->start_time = base::Time::Now();
- info->total_bytes = content_length_;
- info->has_user_gesture = request_info->HasUserGesture();
- info->content_disposition = content_disposition_;
info->mime_type = response->head.mime_type;
info->remote_address = request()->GetSocketAddress().host();
+ request()->GetResponseHeaderByName("content-disposition",
+ &info->content_disposition);
RecordDownloadMimeType(info->mime_type);
RecordDownloadContentDisposition(info->content_disposition);
@@ -168,35 +168,28 @@ bool DownloadResourceHandler::OnResponseStarted(
// Get the last modified time and etag.
const net::HttpResponseHeaders* headers = request()->response_headers();
if (headers) {
- std::string last_modified_hdr;
- if (headers->EnumerateHeader(NULL, "Last-Modified", &last_modified_hdr))
- info->last_modified = last_modified_hdr;
- if (headers->EnumerateHeader(NULL, "ETag", &etag_))
- info->etag = etag_;
+ if (headers->HasStrongValidators()) {
+ // If we don't have strong validators as per RFC 2616 section 13.3.3, then
+ // we neither store nor use them for range requests.
+ if (!headers->EnumerateHeader(NULL, "Last-Modified",
+ &info->last_modified))
+ info->last_modified.clear();
+ if (!headers->EnumerateHeader(NULL, "ETag", &info->etag))
+ info->etag.clear();
+ }
int status = headers->response_code();
if (2 == status / 100 && status != net::HTTP_PARTIAL_CONTENT) {
// Success & not range response; if we asked for a range, we didn't
// get it--reset the file pointers to reflect that.
- save_info_->offset = 0;
- save_info_->hash_state = "";
+ info->save_info->offset = 0;
+ info->save_info->hash_state = "";
}
- }
- std::string content_type_header;
- if (!response->head.headers.get() ||
- !response->head.headers->GetMimeType(&content_type_header))
- content_type_header = "";
- info->original_mime_type = content_type_header;
-
- if (!response->head.headers.get() ||
- !response->head.headers->EnumerateHeader(
- NULL, "Accept-Ranges", &accept_ranges_)) {
- accept_ranges_ = "";
+ if (!headers->GetMimeType(&info->original_mime_type))
+ info->original_mime_type.clear();
}
- info->save_info = save_info_.Pass();
-
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&StartOnUIThread,
@@ -287,10 +280,11 @@ bool DownloadResourceHandler::OnReadCompleted(int request_id, int bytes_read,
return true;
}
-bool DownloadResourceHandler::OnResponseCompleted(
+void DownloadResourceHandler::OnResponseCompleted(
int request_id,
const net::URLRequestStatus& status,
- const std::string& security_info) {
+ const std::string& security_info,
+ bool* defer) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
int response_code = status.is_success() ? request()->GetResponseCode() : 0;
VLOG(20) << __FUNCTION__ << "()" << DebugString()
@@ -372,9 +366,17 @@ bool DownloadResourceHandler::OnResponseCompleted(
}
}
- RecordAcceptsRanges(accept_ranges_, bytes_read_, etag_);
- RecordNetworkBlockage(
- base::TimeTicks::Now() - download_start_time_, total_pause_time_);
+ std::string accept_ranges;
+ bool has_strong_validators = false;
+ if (request()->response_headers()) {
+ request()->response_headers()->EnumerateHeader(
+ NULL, "Accept-Ranges", &accept_ranges);
+ has_strong_validators =
+ request()->response_headers()->HasStrongValidators();
+ }
+ RecordAcceptsRanges(accept_ranges, bytes_read_, has_strong_validators);
+ RecordNetworkBlockage(base::TimeTicks::Now() - download_start_time_,
+ total_pause_time_);
CallStartedCB(NULL, error_code);
@@ -393,8 +395,6 @@ bool DownloadResourceHandler::OnResponseCompleted(
stream_writer_.reset(); // We no longer need the stream.
read_buffer_ = NULL;
-
- return true;
}
void DownloadResourceHandler::OnDataDownloaded(
@@ -403,22 +403,6 @@ void DownloadResourceHandler::OnDataDownloaded(
NOTREACHED();
}
-// If the content-length header is not present (or contains something other
-// than numbers), the incoming content_length is -1 (unknown size).
-// Set the content length to 0 to indicate unknown size to DownloadManager.
-void DownloadResourceHandler::SetContentLength(const int64& content_length) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- content_length_ = 0;
- if (content_length > 0)
- content_length_ = content_length;
-}
-
-void DownloadResourceHandler::SetContentDisposition(
- const std::string& content_disposition) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- content_disposition_ = content_disposition;
-}
-
void DownloadResourceHandler::PauseRequest() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
diff --git a/content/browser/download/download_resource_handler.h b/content/browser/download/download_resource_handler.h
index 11982d7f67..36bb0d2700 100644
--- a/content/browser/download/download_resource_handler.h
+++ b/content/browser/download/download_resource_handler.h
@@ -74,9 +74,10 @@ class CONTENT_EXPORT DownloadResourceHandler
virtual bool OnReadCompleted(int request_id, int bytes_read,
bool* defer) OVERRIDE;
- virtual bool OnResponseCompleted(int request_id,
+ virtual void OnResponseCompleted(int request_id,
const net::URLRequestStatus& status,
- const std::string& security_info) OVERRIDE;
+ const std::string& security_info,
+ bool* defer) OVERRIDE;
// N/A to this flavor of DownloadHandler.
virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE;
@@ -95,16 +96,7 @@ class CONTENT_EXPORT DownloadResourceHandler
// on the IO thread.
void CallStartedCB(DownloadItem* item, net::Error error);
- // If the content-length header is not present (or contains something other
- // than numbers), the incoming content_length is -1 (unknown size).
- // Set the content length to 0 to indicate unknown size to DownloadManager.
- void SetContentLength(const int64& content_length);
-
- void SetContentDisposition(const std::string& content_disposition);
-
uint32 download_id_;
- std::string content_disposition_;
- int64 content_length_;
// This is read only on the IO thread, but may only
// be called on the UI thread.
DownloadUrlParameters::OnStartedCallback started_cb_;
@@ -121,8 +113,6 @@ class CONTENT_EXPORT DownloadResourceHandler
base::TimeDelta total_pause_time_;
size_t last_buffer_size_;
int64 bytes_read_;
- std::string accept_ranges_;
- std::string etag_;
int pause_count_;
bool was_deferred_;
diff --git a/content/browser/download/download_stats.cc b/content/browser/download/download_stats.cc
index 5b5f893c2f..df3a059f5c 100644
--- a/content/browser/download/download_stats.cc
+++ b/content/browser/download/download_stats.cc
@@ -332,7 +332,7 @@ void RecordDownloadWriteLoopCount(int count) {
void RecordAcceptsRanges(const std::string& accepts_ranges,
int64 download_len,
- const std::string& etag) {
+ bool has_strong_validator) {
int64 max = 1024 * 1024 * 1024; // One Terabyte.
download_len /= 1024; // In Kilobytes
static const int kBuckets = 50;
@@ -349,10 +349,8 @@ void RecordAcceptsRanges(const std::string& accepts_ranges,
1,
max,
kBuckets);
- // ETags that start with "W/" are considered weak ETags which don't imply
- // byte-wise equality.
- if (!StartsWithASCII(etag, "w/", false))
- RecordDownloadCount(STRONG_ETAG_AND_ACCEPTS_RANGES);
+ if (has_strong_validator)
+ RecordDownloadCount(STRONG_VALIDATOR_AND_ACCEPTS_RANGES);
} else {
UMA_HISTOGRAM_CUSTOM_COUNTS("Download.AcceptRangesMissingOrInvalid.KBytes",
download_len,
diff --git a/content/browser/download/download_stats.h b/content/browser/download/download_stats.h
index 9a9b1f28b4..b1307d3400 100644
--- a/content/browser/download/download_stats.h
+++ b/content/browser/download/download_stats.h
@@ -72,14 +72,19 @@ enum DownloadCountTypes {
// successful invocation of ScanAndSaveDownloadedFile().
FILE_MISSING_AFTER_SUCCESSFUL_SCAN_COUNT,
- // Count of downloads that supplies a strong ETag and has a 'Accept-Ranges:
- // bytes' header. These downloads are candidates for partial resumption.
- STRONG_ETAG_AND_ACCEPTS_RANGES,
+ // (Deprecated) Count of downloads with a strong ETag and specified
+ // 'Accept-Ranges: bytes'.
+ DOWNLOAD_COUNT_UNUSED_15,
// Count of downloads that didn't have a valid WebContents at the time it was
// interrupted.
INTERRUPTED_WITHOUT_WEBCONTENTS,
+ // Count of downloads that supplies a strong validator (implying byte-wise
+ // equivalence) and has a 'Accept-Ranges: bytes' header. These downloads are
+ // candidates for partial resumption.
+ STRONG_VALIDATOR_AND_ACCEPTS_RANGES,
+
DOWNLOAD_COUNT_TYPES_LAST_ENTRY
};
@@ -165,10 +170,12 @@ void RecordBandwidth(double actual_bandwidth, double potential_bandwidth);
void RecordOpen(const base::Time& end, bool first);
// Record whether or not the server accepts ranges, and the download size. Also
-// counts if a strong ETag is supplied. The combination of range request support
-// and ETag indicates downloads that are candidates for partial resumption.
-void RecordAcceptsRanges(const std::string& accepts_ranges, int64 download_len,
- const std::string& etag);
+// counts if a strong validator is supplied. The combination of range request
+// support and ETag indicates downloads that are candidates for partial
+// resumption.
+void RecordAcceptsRanges(const std::string& accepts_ranges,
+ int64 download_len,
+ bool has_strong_validator);
// Record the number of downloads removed by ClearAll.
void RecordClearAllSize(int size);
diff --git a/content/browser/download/drag_download_file_browsertest.cc b/content/browser/download/drag_download_file_browsertest.cc
index a4f50056ad..5ea0e576af 100644
--- a/content/browser/download/drag_download_file_browsertest.cc
+++ b/content/browser/download/drag_download_file_browsertest.cc
@@ -94,12 +94,9 @@ IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_NetError) {
"download-test.lib"))));
Referrer referrer;
std::string referrer_encoding;
- DragDownloadFile* file = new DragDownloadFile(name,
- scoped_ptr<net::FileStream>(),
- url,
- referrer,
- referrer_encoding,
- shell()->web_contents());
+ scoped_refptr<DragDownloadFile> file(
+ new DragDownloadFile(name, scoped_ptr<net::FileStream>(), url, referrer,
+ referrer_encoding, shell()->web_contents()));
scoped_refptr<MockDownloadFileObserver> observer(
new MockDownloadFileObserver());
EXPECT_CALL(*observer.get(), OnDownloadAborted())
@@ -119,9 +116,9 @@ IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_Complete) {
std::string referrer_encoding;
net::FileStream* stream = NULL;
SetUpServer();
- DragDownloadFile* file = new DragDownloadFile(
+ scoped_refptr<DragDownloadFile> file(new DragDownloadFile(
name, scoped_ptr<net::FileStream>(stream), url, referrer,
- referrer_encoding, shell()->web_contents());
+ referrer_encoding, shell()->web_contents()));
scoped_refptr<MockDownloadFileObserver> observer(
new MockDownloadFileObserver());
EXPECT_CALL(*observer.get(), OnDownloadCompleted(_))
diff --git a/content/browser/download/file_metadata_unittest_linux.cc b/content/browser/download/file_metadata_unittest_linux.cc
index 4a3ebca5a2..4f223519c4 100644
--- a/content/browser/download/file_metadata_unittest_linux.cc
+++ b/content/browser/download/file_metadata_unittest_linux.cc
@@ -58,7 +58,7 @@ class FileMetadataLinuxTest : public testing::Test {
"user.test", "test", 4, 0);
is_xattr_supported_ = (!result) || (errno != ENOTSUP);
if (!is_xattr_supported_) {
- LOG(INFO) << "Test will be skipped because extended attributes are not "
+ VLOG(0) << "Test will be skipped because extended attributes are not "
<< "supported on this OS/file system.";
}
}
diff --git a/content/browser/download/save_file_resource_handler.cc b/content/browser/download/save_file_resource_handler.cc
index b71be48f60..d6405ffdb7 100644
--- a/content/browser/download/save_file_resource_handler.cc
+++ b/content/browser/download/save_file_resource_handler.cc
@@ -100,16 +100,16 @@ bool SaveFileResourceHandler::OnReadCompleted(int request_id, int bytes_read,
return true;
}
-bool SaveFileResourceHandler::OnResponseCompleted(
+void SaveFileResourceHandler::OnResponseCompleted(
int request_id,
const net::URLRequestStatus& status,
- const std::string& security_info) {
+ const std::string& security_info,
+ bool* defer) {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&SaveFileManager::SaveFinished, save_manager_, save_id_, url_,
render_process_id_, status.is_success() && !status.is_io_pending()));
read_buffer_ = NULL;
- return true;
}
void SaveFileResourceHandler::OnDataDownloaded(
diff --git a/content/browser/download/save_file_resource_handler.h b/content/browser/download/save_file_resource_handler.h
index 5813d52386..2079431f9d 100644
--- a/content/browser/download/save_file_resource_handler.h
+++ b/content/browser/download/save_file_resource_handler.h
@@ -56,9 +56,10 @@ class SaveFileResourceHandler : public ResourceHandler {
virtual bool OnReadCompleted(int request_id, int bytes_read,
bool* defer) OVERRIDE;
- virtual bool OnResponseCompleted(int request_id,
+ virtual void OnResponseCompleted(int request_id,
const net::URLRequestStatus& status,
- const std::string& security_info) OVERRIDE;
+ const std::string& security_info,
+ bool* defer) OVERRIDE;
// N/A to this flavor of SaveFileResourceHandler.
virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE;
diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc
index f38f9cdb1e..2fc68dff55 100644
--- a/content/browser/download/save_package.cc
+++ b/content/browser/download/save_package.cc
@@ -46,7 +46,7 @@
#include "third_party/WebKit/public/web/WebPageSerializerClient.h"
using base::Time;
-using WebKit::WebPageSerializerClient;
+using blink::WebPageSerializerClient;
namespace content {
namespace {