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

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

Issue 2874013002: Add GetWakeLockWithoutContext() in WakeLockContextProvider mojo interface. (Closed)
Patch Set: Add GetWakeLockWithoutContext in WakeLockContextProvider mojo interface. Created 3 years, 7 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/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_context.mojom.h"
blundell 2017/05/12 12:42:18 Not needed now.
ke.he 2017/05/12 16:09:38 Done.
36 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h"
35 #include "net/base/elements_upload_data_stream.h" 37 #include "net/base/elements_upload_data_stream.h"
36 #include "net/base/io_buffer.h" 38 #include "net/base/io_buffer.h"
37 #include "net/base/load_flags.h" 39 #include "net/base/load_flags.h"
38 #include "net/base/net_errors.h" 40 #include "net/base/net_errors.h"
39 #include "net/base/upload_bytes_element_reader.h" 41 #include "net/base/upload_bytes_element_reader.h"
40 #include "net/http/http_request_headers.h" 42 #include "net/http/http_request_headers.h"
41 #include "net/http/http_response_headers.h" 43 #include "net/http/http_response_headers.h"
42 #include "net/http/http_status_code.h" 44 #include "net/http/http_status_code.h"
43 #include "net/url_request/url_request_context.h" 45 #include "net/url_request/url_request_context.h"
46 #include "services/device/public/interfaces/constants.mojom.h"
47 #include "services/service_manager/public/cpp/connector.h"
44 48
45 namespace content { 49 namespace content {
46 50
47 namespace { 51 namespace {
48 52
49 // This is a UserData::Data that will be attached to a URLRequest as a 53 // This is a UserData::Data that will be attached to a URLRequest as a
50 // side-channel for passing download parameters. 54 // side-channel for passing download parameters.
51 class DownloadRequestData : public base::SupportsUserData::Data { 55 class DownloadRequestData : public base::SupportsUserData::Data {
52 public: 56 public:
53 ~DownloadRequestData() override {} 57 ~DownloadRequestData() override {}
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 bytes_read_(0), 193 bytes_read_(0),
190 pause_count_(0), 194 pause_count_(0),
191 was_deferred_(false), 195 was_deferred_(false),
192 is_partial_request_(false), 196 is_partial_request_(false),
193 started_(false), 197 started_(false),
194 abort_reason_(DOWNLOAD_INTERRUPT_REASON_NONE) { 198 abort_reason_(DOWNLOAD_INTERRUPT_REASON_NONE) {
195 DCHECK(request_); 199 DCHECK(request_);
196 DCHECK(delegate_); 200 DCHECK(delegate_);
197 if (!is_parallel_request) 201 if (!is_parallel_request)
198 RecordDownloadCount(UNTHROTTLED_COUNT); 202 RecordDownloadCount(UNTHROTTLED_COUNT);
199 power_save_blocker_.reset(new device::PowerSaveBlocker( 203
200 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 204 // Request Wake Lock.
201 device::PowerSaveBlocker::kReasonOther, "Download in progress", 205 service_manager::Connector* connector =
202 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), 206 ServiceManagerContext::GetConnectorForIOThread();
203 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); 207 if (connector) {
blundell 2017/05/12 12:42:18 I think we should elide this instead you have evid
ke.he 2017/05/12 16:09:38 I noticed in wake_lock_context_host.cc, line 35, t
208 device::mojom::WakeLockProviderPtr wake_lock_provider;
209 connector->BindInterface(device::mojom::kServiceName,
210 mojo::MakeRequest(&wake_lock_provider));
211 wake_lock_provider->GetWakeLockWithoutContext(
212 device::mojom::WakeLockType::PreventAppSuspension,
213 device::mojom::WakeLockReason::ReasonOther, "Download in progress",
214 mojo::MakeRequest(&wake_lock_));
215
216 wake_lock_->RequestWakeLock();
217 }
218
204 DownloadRequestData* request_data = DownloadRequestData::Get(request_); 219 DownloadRequestData* request_data = DownloadRequestData::Get(request_);
205 if (request_data) { 220 if (request_data) {
206 save_info_ = request_data->TakeSaveInfo(); 221 save_info_ = request_data->TakeSaveInfo();
207 download_id_ = request_data->download_id(); 222 download_id_ = request_data->download_id();
208 transient_ = request_data->is_transient(); 223 transient_ = request_data->is_transient();
209 on_started_callback_ = request_data->callback(); 224 on_started_callback_ = request_data->callback();
210 DownloadRequestData::Detach(request_); 225 DownloadRequestData::Detach(request_);
211 is_partial_request_ = save_info_->offset > 0; 226 is_partial_request_ = save_info_->offset > 0;
212 } else { 227 } else {
213 save_info_.reset(new DownloadSaveInfo); 228 save_info_.reset(new DownloadSaveInfo);
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 // old servers that didn't implement "If-Match" and must be ignored when 712 // old servers that didn't implement "If-Match" and must be ignored when
698 // "If-Match" presents. 713 // "If-Match" presents.
699 if (has_last_modified) { 714 if (has_last_modified) {
700 request->SetExtraRequestHeaderByName( 715 request->SetExtraRequestHeaderByName(
701 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(), 716 net::HttpRequestHeaders::kIfUnmodifiedSince, params->last_modified(),
702 true); 717 true);
703 } 718 }
704 } 719 }
705 720
706 } // namespace content 721 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698