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

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: 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
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
Charlie Harrison 2017/05/18 13:56:42 Copyright 2017
ke.he 2017/05/18 14:13:11 Actually this file is renamed from the original po
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 "services/device/public/interfaces/constants.mojom.h"
11 #include "services/service_manager/public/cpp/connector.h"
12
13 namespace content {
14
15 namespace {
16
17 const int kWakeLockDelaySeconds = 30;
18
19 } // namespace
20
21 WakeLockResourceThrottle::WakeLockResourceThrottle(const std::string& host)
22 : host_(host) {}
23
24 WakeLockResourceThrottle::~WakeLockResourceThrottle() {}
25
26 void WakeLockResourceThrottle::WillStartRequest(bool* defer) {
27 DCHECK_CURRENTLY_ON(BrowserThread::IO);
28
29 // Delay wake lock activation to dismiss small requests.
30 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kWakeLockDelaySeconds),
31 this, &WakeLockResourceThrottle::ActivateWakeLock);
32 }
33
34 void WakeLockResourceThrottle::WillProcessResponse(bool* defer) {
35 DCHECK_CURRENTLY_ON(BrowserThread::IO);
36
37 // Cancel wake lock after request finishes.
38 if (wake_lock_)
39 wake_lock_->CancelWakeLock();
40
41 timer_.Stop();
42 }
43
44 const char* WakeLockResourceThrottle::GetNameForLogging() const {
45 return "WakeLockResourceThrottle";
46 }
47
48 void WakeLockResourceThrottle::ActivateWakeLock() {
Charlie Harrison 2017/05/18 14:46:17 Maybe s/Activate/Request ?
ke.he 2017/05/18 15:35:15 Done.
49 DCHECK_CURRENTLY_ON(BrowserThread::IO);
ke.he 2017/05/18 13:40:09 I think the original PowerSaveBlockResourceThrottl
Charlie Harrison 2017/05/18 13:56:42 Yep, all ResourceThrottles run on the IO thread.
ke.he 2017/05/18 14:13:11 Thanks!
50 DCHECK(!wake_lock_);
ke.he 2017/05/18 13:40:09 This ActivateWakeLock() will never be called twice
Charlie Harrison 2017/05/18 13:56:42 Yep, WillStartRequest should only be called once.
51
52 service_manager::Connector* connector =
53 ServiceManagerContext::GetConnectorForIOThread();
54 // |connector| might be nullptr in some testing contexts, in which the
55 // service manager connection isn't initialized.
56 if (connector) {
57 device::mojom::WakeLockProviderPtr wake_lock_provider;
58 connector->BindInterface(device::mojom::kServiceName,
59 mojo::MakeRequest(&wake_lock_provider));
Charlie Harrison 2017/05/18 14:46:17 Do we need to include mojo/public/cpp/bindings/int
ke.he 2017/05/18 15:35:15 Done.
60 wake_lock_provider->GetWakeLockWithoutContext(
61 device::mojom::WakeLockType::PreventAppSuspension,
62 device::mojom::WakeLockReason::ReasonOther,
63 "Uploading data to " + host_, mojo::MakeRequest(&wake_lock_));
64
65 wake_lock_->RequestWakeLock();
66 }
67 }
68
69 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698