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

Side by Side Diff: content/browser/loader/wake_lock_resource_throttle.cc

Issue 2893873002: Convert PowerSaveBlockResourceThrottle to be client of WakeLock mojo service. (Closed)
Patch Set: Convert PowerSaveBlockResourceThrottle to be client of WakeLock mojo service. 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
« no previous file with comments | « content/browser/loader/wake_lock_resource_throttle.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/loader/wake_lock_resource_throttle.h"
6
7 #include "content/browser/service_manager/service_manager_context.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h"
10 #include "mojo/public/cpp/bindings/interface_request.h"
11 #include "services/device/public/interfaces/constants.mojom.h"
12 #include "services/service_manager/public/cpp/connector.h"
13
14 namespace content {
15
16 namespace {
17
18 const int kWakeLockDelaySeconds = 30;
19
20 } // namespace
21
22 WakeLockResourceThrottle::WakeLockResourceThrottle(const std::string& host)
23 : host_(host) {}
24
25 WakeLockResourceThrottle::~WakeLockResourceThrottle() {}
26
27 void WakeLockResourceThrottle::WillStartRequest(bool* defer) {
28 DCHECK_CURRENTLY_ON(BrowserThread::IO);
29
30 // Delay wake lock request to dismiss small requests.
31 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kWakeLockDelaySeconds),
32 this, &WakeLockResourceThrottle::RequestWakeLock);
33 }
34
35 void WakeLockResourceThrottle::WillProcessResponse(bool* defer) {
36 DCHECK_CURRENTLY_ON(BrowserThread::IO);
37
38 // Cancel wake lock after request finishes.
39 if (wake_lock_)
40 wake_lock_->CancelWakeLock();
41
42 timer_.Stop();
43 }
44
45 const char* WakeLockResourceThrottle::GetNameForLogging() const {
46 return "WakeLockResourceThrottle";
47 }
48
49 void WakeLockResourceThrottle::RequestWakeLock() {
50 DCHECK_CURRENTLY_ON(BrowserThread::IO);
51 DCHECK(!wake_lock_);
52
53 service_manager::Connector* connector =
54 ServiceManagerContext::GetConnectorForIOThread();
55 // |connector| might be nullptr in some testing contexts, in which the
56 // service manager connection isn't initialized.
57 if (connector) {
58 device::mojom::WakeLockProviderPtr wake_lock_provider;
59 connector->BindInterface(device::mojom::kServiceName,
60 mojo::MakeRequest(&wake_lock_provider));
61 wake_lock_provider->GetWakeLockWithoutContext(
62 device::mojom::WakeLockType::PreventAppSuspension,
63 device::mojom::WakeLockReason::ReasonOther,
64 "Uploading data to " + host_, mojo::MakeRequest(&wake_lock_));
65
66 wake_lock_->RequestWakeLock();
67 }
68 }
69
70 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/wake_lock_resource_throttle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698