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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/loader/wake_lock_resource_throttle.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/wake_lock_resource_throttle.cc
diff --git a/content/browser/loader/wake_lock_resource_throttle.cc b/content/browser/loader/wake_lock_resource_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6d9594fcb59ae774b93e1971343fe469fc8ad2e5
--- /dev/null
+++ b/content/browser/loader/wake_lock_resource_throttle.cc
@@ -0,0 +1,70 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/loader/wake_lock_resource_throttle.h"
+
+#include "content/browser/service_manager/service_manager_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "services/device/public/interfaces/constants.mojom.h"
+#include "services/service_manager/public/cpp/connector.h"
+
+namespace content {
+
+namespace {
+
+const int kWakeLockDelaySeconds = 30;
+
+} // namespace
+
+WakeLockResourceThrottle::WakeLockResourceThrottle(const std::string& host)
+ : host_(host) {}
+
+WakeLockResourceThrottle::~WakeLockResourceThrottle() {}
+
+void WakeLockResourceThrottle::WillStartRequest(bool* defer) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ // Delay wake lock request to dismiss small requests.
+ timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kWakeLockDelaySeconds),
+ this, &WakeLockResourceThrottle::RequestWakeLock);
+}
+
+void WakeLockResourceThrottle::WillProcessResponse(bool* defer) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ // Cancel wake lock after request finishes.
+ if (wake_lock_)
+ wake_lock_->CancelWakeLock();
+
+ timer_.Stop();
+}
+
+const char* WakeLockResourceThrottle::GetNameForLogging() const {
+ return "WakeLockResourceThrottle";
+}
+
+void WakeLockResourceThrottle::RequestWakeLock() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(!wake_lock_);
+
+ service_manager::Connector* connector =
+ ServiceManagerContext::GetConnectorForIOThread();
+ // |connector| might be nullptr in some testing contexts, in which the
+ // service manager connection isn't initialized.
+ if (connector) {
+ device::mojom::WakeLockProviderPtr wake_lock_provider;
+ connector->BindInterface(device::mojom::kServiceName,
+ mojo::MakeRequest(&wake_lock_provider));
+ wake_lock_provider->GetWakeLockWithoutContext(
+ device::mojom::WakeLockType::PreventAppSuspension,
+ device::mojom::WakeLockReason::ReasonOther,
+ "Uploading data to " + host_, mojo::MakeRequest(&wake_lock_));
+
+ wake_lock_->RequestWakeLock();
+ }
+}
+
+} // namespace content
« 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