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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Address Avi's comments. Created 3 years, 5 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
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_request_core.h" 5 #include "content/browser/download/download_request_core.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/metrics/sparse_histogram.h" 16 #include "base/metrics/sparse_histogram.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "content/browser/byte_stream.h" 20 #include "content/browser/byte_stream.h"
21 #include "content/browser/download/download_create_info.h" 21 #include "content/browser/download/download_create_info.h"
22 #include "content/browser/download/download_interrupt_reasons_impl.h" 22 #include "content/browser/download/download_interrupt_reasons_impl.h"
23 #include "content/browser/download/download_manager_impl.h" 23 #include "content/browser/download/download_manager_impl.h"
24 #include "content/browser/download/download_request_handle.h" 24 #include "content/browser/download/download_request_handle.h"
25 #include "content/browser/download/download_stats.h" 25 #include "content/browser/download/download_stats.h"
26 #include "content/browser/download/download_task_runner.h"
26 #include "content/browser/loader/resource_dispatcher_host_impl.h" 27 #include "content/browser/loader/resource_dispatcher_host_impl.h"
27 #include "content/browser/service_manager/service_manager_context.h" 28 #include "content/browser/service_manager/service_manager_context.h"
28 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/download_interrupt_reasons.h" 30 #include "content/public/browser/download_interrupt_reasons.h"
30 #include "content/public/browser/download_item.h" 31 #include "content/public/browser/download_item.h"
31 #include "content/public/browser/download_manager_delegate.h" 32 #include "content/public/browser/download_manager_delegate.h"
32 #include "content/public/browser/navigation_entry.h" 33 #include "content/public/browser/navigation_entry.h"
33 #include "content/public/browser/resource_context.h" 34 #include "content/public/browser/resource_context.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "net/base/elements_upload_data_stream.h" 36 #include "net/base/elements_upload_data_stream.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // If the content-length header is not present (or contains something other 301 // If the content-length header is not present (or contains something other
301 // than numbers), the incoming content_length is -1 (unknown size). 302 // than numbers), the incoming content_length is -1 (unknown size).
302 // Set the content length to 0 to indicate unknown size to DownloadManager. 303 // Set the content length to 0 to indicate unknown size to DownloadManager.
303 int64_t content_length = request()->GetExpectedContentSize() > 0 304 int64_t content_length = request()->GetExpectedContentSize() > 0
304 ? request()->GetExpectedContentSize() 305 ? request()->GetExpectedContentSize()
305 : 0; 306 : 0;
306 create_info->total_bytes = content_length; 307 create_info->total_bytes = content_length;
307 308
308 // Create the ByteStream for sending data to the download sink. 309 // Create the ByteStream for sending data to the download sink.
309 std::unique_ptr<ByteStreamReader> stream_reader; 310 std::unique_ptr<ByteStreamReader> stream_reader;
310 CreateByteStream(base::ThreadTaskRunnerHandle::Get(), 311 CreateByteStream(base::ThreadTaskRunnerHandle::Get(), GetDownloadTaskRunner(),
311 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
312 kDownloadByteStreamSize, &stream_writer_, &stream_reader); 312 kDownloadByteStreamSize, &stream_writer_, &stream_reader);
313 stream_writer_->RegisterCallback( 313 stream_writer_->RegisterCallback(
314 base::Bind(&DownloadRequestCore::ResumeRequest, AsWeakPtr())); 314 base::Bind(&DownloadRequestCore::ResumeRequest, AsWeakPtr()));
315 315
316 if (!override_mime_type.empty()) 316 if (!override_mime_type.empty())
317 create_info->mime_type = override_mime_type; 317 create_info->mime_type = override_mime_type;
318 else 318 else
319 request()->GetMimeType(&create_info->mime_type); 319 request()->GetMimeType(&create_info->mime_type);
320 320
321 // Get the last modified time and etag. 321 // Get the last modified time and etag.
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 // old servers that didn't implement "If-Match" and must be ignored when 724 // old servers that didn't implement "If-Match" and must be ignored when
725 // "If-Match" presents. 725 // "If-Match" presents.
726 if (has_last_modified) { 726 if (has_last_modified) {
727 request->SetExtraRequestHeaderByName( 727 request->SetExtraRequestHeaderByName(
728 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(), 728 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(),
729 true); 729 true);
730 } 730 }
731 } 731 }
732 732
733 } // namespace content 733 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl_unittest.cc ('k') | content/browser/download/download_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698