| Index: chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc
|
| diff --git a/chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc b/chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc
|
| index 7c77836ab0df3475312bf0e5ffbfafff614821b4..59f14d226af5e73023d3e582dab4a4547dfe81a7 100644
|
| --- a/chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc
|
| +++ b/chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc
|
| @@ -8,32 +8,20 @@
|
|
|
| #include "base/files/file_util.h"
|
| #include "base/logging.h"
|
| -#include "base/strings/stringprintf.h"
|
|
|
| namespace chromeos {
|
|
|
| namespace {
|
| -const char kFreezerPath[] = "/sys/fs/cgroup/freezer/chrome_renderers";
|
| -const char kToBeFrozen[] = "to_be_frozen";
|
| -const char kFreezerState[] = "freezer.state";
|
| -const char kCgroupProcs[] = "cgroup.procs";
|
| -
|
| +const char kFreezerStatePath[] =
|
| + "/sys/fs/cgroup/freezer/chrome_renderers/freezer.state";
|
| const char kFreezeCommand[] = "FROZEN";
|
| const char kThawCommand[] = "THAWED";
|
|
|
| } // namespace
|
|
|
| FreezerCgroupProcessManager::FreezerCgroupProcessManager()
|
| - : default_control_path_(base::FilePath(kFreezerPath).Append(kCgroupProcs)),
|
| - to_be_frozen_control_path_(base::FilePath(kFreezerPath)
|
| - .AppendASCII(kToBeFrozen)
|
| - .AppendASCII(kCgroupProcs)),
|
| - to_be_frozen_state_path_(base::FilePath(kFreezerPath)
|
| - .AppendASCII(kToBeFrozen)
|
| - .AppendASCII(kFreezerState)),
|
| - enabled_(base::PathIsWritable(default_control_path_) &&
|
| - base::PathIsWritable(to_be_frozen_control_path_) &&
|
| - base::PathIsWritable(to_be_frozen_state_path_)) {
|
| + : state_path_(base::FilePath(kFreezerStatePath)),
|
| + enabled_(base::PathIsWritable(state_path_)) {
|
| if (!enabled_) {
|
| LOG(WARNING) << "Cgroup freezer does not exist or is not writable. "
|
| << "Unable to freeze renderer processes.";
|
| @@ -43,15 +31,6 @@
|
| FreezerCgroupProcessManager::~FreezerCgroupProcessManager() {
|
| }
|
|
|
| -void FreezerCgroupProcessManager::SetShouldFreezeRenderer(
|
| - base::ProcessHandle handle,
|
| - bool frozen) {
|
| - std::string pid = base::StringPrintf("%d", handle);
|
| -
|
| - WriteCommandToFile(
|
| - pid, frozen ? to_be_frozen_control_path_ : default_control_path_);
|
| -}
|
| -
|
| bool FreezerCgroupProcessManager::FreezeRenderers() {
|
| if (!enabled_) {
|
| LOG(ERROR) << "Attempting to freeze renderers when the freezer cgroup is "
|
| @@ -59,7 +38,7 @@
|
| return false;
|
| }
|
|
|
| - return WriteCommandToFile(kFreezeCommand, to_be_frozen_state_path_);
|
| + return WriteCommandToStateFile(kFreezeCommand);
|
| }
|
|
|
| bool FreezerCgroupProcessManager::ThawRenderers() {
|
| @@ -69,23 +48,23 @@
|
| return false;
|
| }
|
|
|
| - return WriteCommandToFile(kThawCommand, to_be_frozen_state_path_);
|
| + return WriteCommandToStateFile(kThawCommand);
|
| }
|
|
|
| bool FreezerCgroupProcessManager::CanFreezeRenderers() {
|
| return enabled_;
|
| }
|
|
|
| -bool FreezerCgroupProcessManager::WriteCommandToFile(
|
| - const std::string& command,
|
| - const base::FilePath& file) {
|
| - int bytes = base::WriteFile(file, command.c_str(), command.size());
|
| +bool FreezerCgroupProcessManager::WriteCommandToStateFile(
|
| + const std::string& command) {
|
| + int bytes = base::WriteFile(state_path_, command.c_str(), command.size());
|
| if (bytes == -1) {
|
| - PLOG(ERROR) << "Writing " << command << " to " << file.value() << " failed";
|
| + PLOG(ERROR) << "Writing " << command << " to " << state_path_.value()
|
| + << " failed";
|
| return false;
|
| } else if (bytes != static_cast<int>(command.size())) {
|
| - LOG(ERROR) << "Only wrote " << bytes << " byte(s) when writing " << command
|
| - << " to " << file.value();
|
| + LOG(ERROR) << "Only wrote " << bytes << " byte(s) when writing "
|
| + << command << " to " << state_path_.value();
|
| return false;
|
| }
|
| return true;
|
|
|