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

Unified Diff: content/browser/power_save_blocker_chromeos.cc

Issue 2075973002: Revert of Move content/browser/power_save_blocker to //device/power_save_blocker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@power-save-next-2
Patch Set: Created 4 years, 6 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/power_save_blocker_android.cc ('k') | content/browser/power_save_blocker_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/power_save_blocker_chromeos.cc
diff --git a/content/browser/power_save_blocker_chromeos.cc b/content/browser/power_save_blocker_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2913f093c0f59ffcabbec5c3507708aa559c50ba
--- /dev/null
+++ b/content/browser/power_save_blocker_chromeos.cc
@@ -0,0 +1,112 @@
+// Copyright (c) 2012 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/power_save_blocker_impl.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "chromeos/dbus/power_policy_controller.h"
+
+namespace content {
+
+namespace {
+
+// Converts a PowerSaveBlocker::Reason to a
+// chromeos::PowerPolicyController::WakeLockReason.
+chromeos::PowerPolicyController::WakeLockReason GetWakeLockReason(
+ PowerSaveBlocker::Reason reason) {
+ switch (reason) {
+ case PowerSaveBlocker::kReasonAudioPlayback:
+ return chromeos::PowerPolicyController::REASON_AUDIO_PLAYBACK;
+ case PowerSaveBlocker::kReasonVideoPlayback:
+ return chromeos::PowerPolicyController::REASON_VIDEO_PLAYBACK;
+ case PowerSaveBlocker::kReasonOther:
+ return chromeos::PowerPolicyController::REASON_OTHER;
+ }
+ return chromeos::PowerPolicyController::REASON_OTHER;
+}
+
+} // namespace
+
+class PowerSaveBlockerImpl::Delegate
+ : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> {
+ public:
+ Delegate(PowerSaveBlockerType type,
+ Reason reason,
+ const std::string& description,
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner)
+ : type_(type),
+ reason_(reason),
+ description_(description),
+ block_id_(0),
+ ui_task_runner_(ui_task_runner) {}
+
+ void ApplyBlock() {
+ DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
+ if (!chromeos::PowerPolicyController::IsInitialized())
+ return;
+
+ auto* controller = chromeos::PowerPolicyController::Get();
+ switch (type_) {
+ case kPowerSaveBlockPreventAppSuspension:
+ block_id_ = controller->AddSystemWakeLock(GetWakeLockReason(reason_),
+ description_);
+ break;
+ case kPowerSaveBlockPreventDisplaySleep:
+ block_id_ = controller->AddScreenWakeLock(GetWakeLockReason(reason_),
+ description_);
+ break;
+ default:
+ NOTREACHED() << "Unhandled block type " << type_;
+ }
+ }
+
+ void RemoveBlock() {
+ DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
+ if (!chromeos::PowerPolicyController::IsInitialized())
+ return;
+
+ chromeos::PowerPolicyController::Get()->RemoveWakeLock(block_id_);
+ }
+
+ private:
+ friend class base::RefCountedThreadSafe<Delegate>;
+ virtual ~Delegate() {}
+
+ PowerSaveBlockerType type_;
+ Reason reason_;
+ std::string description_;
+
+ // ID corresponding to the block request in PowerPolicyController.
+ int block_id_;
+
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(Delegate);
+};
+
+PowerSaveBlockerImpl::PowerSaveBlockerImpl(
+ PowerSaveBlockerType type,
+ Reason reason,
+ const std::string& description,
+ scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner)
+ : delegate_(new Delegate(type, reason, description, ui_task_runner)),
+ ui_task_runner_(ui_task_runner),
+ blocking_task_runner_(blocking_task_runner) {
+ ui_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&Delegate::ApplyBlock, delegate_));
+}
+
+PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
+ ui_task_runner_->PostTask(FROM_HERE,
+ base::Bind(&Delegate::RemoveBlock, delegate_));
+}
+
+} // namespace content
« no previous file with comments | « content/browser/power_save_blocker_android.cc ('k') | content/browser/power_save_blocker_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698