Chromium Code Reviews| 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_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/loader/resource_dispatcher_host_impl.h" | 26 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 27 #include "content/browser/service_manager/service_manager_context.h" | |
| 27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/download_interrupt_reasons.h" | 29 #include "content/public/browser/download_interrupt_reasons.h" |
| 29 #include "content/public/browser/download_item.h" | 30 #include "content/public/browser/download_item.h" |
| 30 #include "content/public/browser/download_manager_delegate.h" | 31 #include "content/public/browser/download_manager_delegate.h" |
| 31 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
| 32 #include "content/public/browser/resource_context.h" | 33 #include "content/public/browser/resource_context.h" |
| 33 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 34 #include "device/power_save_blocker/power_save_blocker.h" | 35 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h" |
| 35 #include "net/base/elements_upload_data_stream.h" | 36 #include "net/base/elements_upload_data_stream.h" |
| 36 #include "net/base/io_buffer.h" | 37 #include "net/base/io_buffer.h" |
| 37 #include "net/base/load_flags.h" | 38 #include "net/base/load_flags.h" |
| 38 #include "net/base/net_errors.h" | 39 #include "net/base/net_errors.h" |
| 39 #include "net/base/upload_bytes_element_reader.h" | 40 #include "net/base/upload_bytes_element_reader.h" |
| 40 #include "net/http/http_request_headers.h" | 41 #include "net/http/http_request_headers.h" |
| 41 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
| 42 #include "net/http/http_status_code.h" | 43 #include "net/http/http_status_code.h" |
| 43 #include "net/url_request/url_request_context.h" | 44 #include "net/url_request/url_request_context.h" |
| 45 #include "services/device/public/interfaces/constants.mojom.h" | |
| 46 #include "services/service_manager/public/cpp/connector.h" | |
| 44 | 47 |
| 45 namespace content { | 48 namespace content { |
| 46 | 49 |
| 47 namespace { | 50 namespace { |
| 48 | 51 |
| 49 // This is a UserData::Data that will be attached to a URLRequest as a | 52 // This is a UserData::Data that will be attached to a URLRequest as a |
| 50 // side-channel for passing download parameters. | 53 // side-channel for passing download parameters. |
| 51 class DownloadRequestData : public base::SupportsUserData::Data { | 54 class DownloadRequestData : public base::SupportsUserData::Data { |
| 52 public: | 55 public: |
| 53 ~DownloadRequestData() override {} | 56 ~DownloadRequestData() override {} |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 bytes_read_(0), | 192 bytes_read_(0), |
| 190 pause_count_(0), | 193 pause_count_(0), |
| 191 was_deferred_(false), | 194 was_deferred_(false), |
| 192 is_partial_request_(false), | 195 is_partial_request_(false), |
| 193 started_(false), | 196 started_(false), |
| 194 abort_reason_(DOWNLOAD_INTERRUPT_REASON_NONE) { | 197 abort_reason_(DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 195 DCHECK(request_); | 198 DCHECK(request_); |
| 196 DCHECK(delegate_); | 199 DCHECK(delegate_); |
| 197 if (!is_parallel_request) | 200 if (!is_parallel_request) |
| 198 RecordDownloadCount(UNTHROTTLED_COUNT); | 201 RecordDownloadCount(UNTHROTTLED_COUNT); |
| 199 power_save_blocker_.reset(new device::PowerSaveBlocker( | 202 |
| 200 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 203 // Request Wake Lock. |
| 201 device::PowerSaveBlocker::kReasonOther, "Download in progress", | 204 service_manager::Connector* connector = |
| 202 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 205 ServiceManagerContext::GetConnectorForIOThread(); |
| 203 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 206 // |connector| might be nullptr in some testing contexts, in which thei |
|
David Trainor- moved to gerrit
2017/05/14 05:52:40
thei -> the?
ke.he
2017/05/14 12:05:00
Done.
| |
| 207 // service manager connection isn't initialized. | |
| 208 if (connector) { | |
| 209 device::mojom::WakeLockProviderPtr wake_lock_provider; | |
| 210 connector->BindInterface(device::mojom::kServiceName, | |
| 211 mojo::MakeRequest(&wake_lock_provider)); | |
| 212 wake_lock_provider->GetWakeLockWithoutContext( | |
| 213 device::mojom::WakeLockType::PreventAppSuspension, | |
| 214 device::mojom::WakeLockReason::ReasonOther, "Download in progress", | |
| 215 mojo::MakeRequest(&wake_lock_)); | |
| 216 | |
| 217 wake_lock_->RequestWakeLock(); | |
| 218 } | |
| 219 | |
| 204 DownloadRequestData* request_data = DownloadRequestData::Get(request_); | 220 DownloadRequestData* request_data = DownloadRequestData::Get(request_); |
| 205 if (request_data) { | 221 if (request_data) { |
| 206 save_info_ = request_data->TakeSaveInfo(); | 222 save_info_ = request_data->TakeSaveInfo(); |
| 207 download_id_ = request_data->download_id(); | 223 download_id_ = request_data->download_id(); |
| 208 transient_ = request_data->is_transient(); | 224 transient_ = request_data->is_transient(); |
| 209 on_started_callback_ = request_data->callback(); | 225 on_started_callback_ = request_data->callback(); |
| 210 DownloadRequestData::Detach(request_); | 226 DownloadRequestData::Detach(request_); |
| 211 is_partial_request_ = save_info_->offset > 0; | 227 is_partial_request_ = save_info_->offset > 0; |
| 212 } else { | 228 } else { |
| 213 save_info_.reset(new DownloadSaveInfo); | 229 save_info_.reset(new DownloadSaveInfo); |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 // old servers that didn't implement "If-Match" and must be ignored when | 713 // old servers that didn't implement "If-Match" and must be ignored when |
| 698 // "If-Match" presents. | 714 // "If-Match" presents. |
| 699 if (has_last_modified) { | 715 if (has_last_modified) { |
| 700 request->SetExtraRequestHeaderByName( | 716 request->SetExtraRequestHeaderByName( |
| 701 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(), | 717 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(), |
| 702 true); | 718 true); |
| 703 } | 719 } |
| 704 } | 720 } |
| 705 | 721 |
| 706 } // namespace content | 722 } // namespace content |
| OLD | NEW |