| 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 59f14d226af5e73023d3e582dab4a4547dfe81a7..7c77836ab0df3475312bf0e5ffbfafff614821b4 100644
|
| --- a/chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc
|
| +++ b/chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc
|
| @@ -8,20 +8,32 @@
|
|
|
| #include "base/files/file_util.h"
|
| #include "base/logging.h"
|
| +#include "base/strings/stringprintf.h"
|
|
|
| namespace chromeos {
|
|
|
| namespace {
|
| -const char kFreezerStatePath[] =
|
| - "/sys/fs/cgroup/freezer/chrome_renderers/freezer.state";
|
| +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 kFreezeCommand[] = "FROZEN";
|
| const char kThawCommand[] = "THAWED";
|
|
|
| } // namespace
|
|
|
| FreezerCgroupProcessManager::FreezerCgroupProcessManager()
|
| - : state_path_(base::FilePath(kFreezerStatePath)),
|
| - enabled_(base::PathIsWritable(state_path_)) {
|
| + : 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_)) {
|
| if (!enabled_) {
|
| LOG(WARNING) << "Cgroup freezer does not exist or is not writable. "
|
| << "Unable to freeze renderer processes.";
|
| @@ -31,6 +43,15 @@ FreezerCgroupProcessManager::FreezerCgroupProcessManager()
|
| 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 "
|
| @@ -38,7 +59,7 @@ bool FreezerCgroupProcessManager::FreezeRenderers() {
|
| return false;
|
| }
|
|
|
| - return WriteCommandToStateFile(kFreezeCommand);
|
| + return WriteCommandToFile(kFreezeCommand, to_be_frozen_state_path_);
|
| }
|
|
|
| bool FreezerCgroupProcessManager::ThawRenderers() {
|
| @@ -48,23 +69,23 @@ bool FreezerCgroupProcessManager::ThawRenderers() {
|
| return false;
|
| }
|
|
|
| - return WriteCommandToStateFile(kThawCommand);
|
| + return WriteCommandToFile(kThawCommand, to_be_frozen_state_path_);
|
| }
|
|
|
| bool FreezerCgroupProcessManager::CanFreezeRenderers() {
|
| return enabled_;
|
| }
|
|
|
| -bool FreezerCgroupProcessManager::WriteCommandToStateFile(
|
| - const std::string& command) {
|
| - int bytes = base::WriteFile(state_path_, command.c_str(), command.size());
|
| +bool FreezerCgroupProcessManager::WriteCommandToFile(
|
| + const std::string& command,
|
| + const base::FilePath& file) {
|
| + int bytes = base::WriteFile(file, command.c_str(), command.size());
|
| if (bytes == -1) {
|
| - PLOG(ERROR) << "Writing " << command << " to " << state_path_.value()
|
| - << " failed";
|
| + PLOG(ERROR) << "Writing " << command << " to " << file.value() << " failed";
|
| return false;
|
| } else if (bytes != static_cast<int>(command.size())) {
|
| - LOG(ERROR) << "Only wrote " << bytes << " byte(s) when writing "
|
| - << command << " to " << state_path_.value();
|
| + LOG(ERROR) << "Only wrote " << bytes << " byte(s) when writing " << command
|
| + << " to " << file.value();
|
| return false;
|
| }
|
| return true;
|
|
|