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

Unified Diff: chrome/browser/chromeos/power/renderer_freezer_delegate.cc

Issue 543303002: chromeos: power: Refactor RendererFreezer and add tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add more tests Created 6 years, 3 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
Index: chrome/browser/chromeos/power/renderer_freezer_delegate.cc
diff --git a/chrome/browser/chromeos/power/renderer_freezer_delegate.cc b/chrome/browser/chromeos/power/renderer_freezer_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..452286cd903f454065cccf5136c3d5a45bb04a31
--- /dev/null
+++ b/chrome/browser/chromeos/power/renderer_freezer_delegate.cc
@@ -0,0 +1,42 @@
+// Copyright 2014 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 "chrome/browser/chromeos/power/renderer_freezer_delegate.h"
+
+#include "base/files/file_util.h"
+
+namespace chromeos {
+
+namespace {
+const char kFreezerStatePath[] =
+ "/sys/fs/cgroup/freezer/chrome_renderers/freezer.state";
+const char kFreezeCommand[] = "FROZEN";
+const char kThawCommand[] = "THAWED";
+
+} // namespace
+
+RendererFreezerDelegate::RendererFreezerDelegate()
+ : state_path_(base::FilePath(kFreezerStatePath)),
+ enabled_(base::PathExists(state_path_) &&
Daniel Erat 2014/09/06 02:01:25 you should be able to just call PathIsWritable (wh
+ base::PathIsWritable(state_path_)) {
+}
+
+RendererFreezerDelegate::~RendererFreezerDelegate() {
+}
+
+bool RendererFreezerDelegate::FreezeRenderers() {
Daniel Erat 2014/09/06 02:01:25 maybe DCHECK() or LOG(ERROR) and return early or s
+ return base::WriteFile(state_path_, kFreezeCommand, strlen(kFreezeCommand)) ==
+ static_cast<int>(strlen(kFreezeCommand));
+}
+
+bool RendererFreezerDelegate::ThawRenderers() {
+ return base::WriteFile(state_path_, kThawCommand, strlen(kThawCommand)) ==
+ static_cast<int>(strlen(kThawCommand));
+}
+
+bool RendererFreezerDelegate::CanFreezeRenderers() {
+ return enabled_;
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698