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

Side by Side Diff: chrome/browser/chromeos/power/freezer_cgroup_process_manager.cc

Issue 2575933002: chromeos: Avoid crash on thaw failure if freezing failed. (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/power/freezer_cgroup_process_manager.h" 5 #include "chrome/browser/chromeos/power/freezer_cgroup_process_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 16 matching lines...) Expand all
27 const char kThawCommand[] = "THAWED"; 27 const char kThawCommand[] = "THAWED";
28 28
29 } // namespace 29 } // namespace
30 30
31 class FreezerCgroupProcessManager::FileWorker { 31 class FreezerCgroupProcessManager::FileWorker {
32 public: 32 public:
33 // Called on UI thread. 33 // Called on UI thread.
34 explicit FileWorker(scoped_refptr<base::SequencedTaskRunner> file_thread) 34 explicit FileWorker(scoped_refptr<base::SequencedTaskRunner> file_thread)
35 : ui_thread_(content::BrowserThread::GetTaskRunnerForThread( 35 : ui_thread_(content::BrowserThread::GetTaskRunnerForThread(
36 content::BrowserThread::UI)), 36 content::BrowserThread::UI)),
37 file_thread_(file_thread) { 37 file_thread_(file_thread),
38 enabled_(false),
39 froze_successfully_(false) {
38 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 40 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
39 } 41 }
40 42
41 // Called on FILE thread. 43 // Called on FILE thread.
42 virtual ~FileWorker() { DCHECK(file_thread_->RunsTasksOnCurrentThread()); } 44 virtual ~FileWorker() { DCHECK(file_thread_->RunsTasksOnCurrentThread()); }
43 45
44 void Start() { 46 void Start() {
45 DCHECK(file_thread_->RunsTasksOnCurrentThread()); 47 DCHECK(file_thread_->RunsTasksOnCurrentThread());
46 48
47 default_control_path_ = base::FilePath(kFreezerPath).Append(kCgroupProcs); 49 default_control_path_ = base::FilePath(kFreezerPath).Append(kCgroupProcs);
(...skipping 23 matching lines...) Expand all
71 73
72 void FreezeRenderers() { 74 void FreezeRenderers() {
73 DCHECK(file_thread_->RunsTasksOnCurrentThread()); 75 DCHECK(file_thread_->RunsTasksOnCurrentThread());
74 76
75 if (!enabled_) { 77 if (!enabled_) {
76 LOG(ERROR) << "Attempting to freeze renderers when the freezer cgroup is " 78 LOG(ERROR) << "Attempting to freeze renderers when the freezer cgroup is "
77 << "not available."; 79 << "not available.";
78 return; 80 return;
79 } 81 }
80 82
81 WriteCommandToFile(kFreezeCommand, to_be_frozen_state_path_); 83 froze_successfully_ =
84 WriteCommandToFile(kFreezeCommand, to_be_frozen_state_path_);
82 } 85 }
83 86
84 void ThawRenderers(ResultCallback callback) { 87 void ThawRenderers(ResultCallback callback) {
85 DCHECK(file_thread_->RunsTasksOnCurrentThread()); 88 DCHECK(file_thread_->RunsTasksOnCurrentThread());
86 89
87 if (!enabled_) { 90 if (!enabled_) {
88 LOG(ERROR) << "Attempting to thaw renderers when the freezer cgroup is " 91 LOG(ERROR) << "Attempting to thaw renderers when the freezer cgroup is "
89 << "not available."; 92 << "not available.";
90 return; 93 return;
91 } 94 }
92 95
93 bool result = WriteCommandToFile(kThawCommand, to_be_frozen_state_path_); 96 bool result = WriteCommandToFile(kThawCommand, to_be_frozen_state_path_);
97
98 // TODO(derat): For now, lie and report success if thawing failed but
99 // freezing also failed previously. Remove after weird EBADF and ENOENT
100 // problems tracked at http://crbug.com/661310 are fixed.
101 if (!result && !froze_successfully_)
102 result = true;
103
94 ui_thread_->PostTask(FROM_HERE, base::Bind(callback, result)); 104 ui_thread_->PostTask(FROM_HERE, base::Bind(callback, result));
95 } 105 }
96 106
97 void CheckCanFreezeRenderers(ResultCallback callback) { 107 void CheckCanFreezeRenderers(ResultCallback callback) {
98 DCHECK(file_thread_->RunsTasksOnCurrentThread()); 108 DCHECK(file_thread_->RunsTasksOnCurrentThread());
99 109
100 ui_thread_->PostTask(FROM_HERE, base::Bind(callback, enabled_)); 110 ui_thread_->PostTask(FROM_HERE, base::Bind(callback, enabled_));
101 } 111 }
102 112
103 private: 113 private:
(...skipping 17 matching lines...) Expand all
121 131
122 // Control path for the cgroup that is not frozen. 132 // Control path for the cgroup that is not frozen.
123 base::FilePath default_control_path_; 133 base::FilePath default_control_path_;
124 134
125 // Control and state paths for the cgroup whose processes will be frozen. 135 // Control and state paths for the cgroup whose processes will be frozen.
126 base::FilePath to_be_frozen_control_path_; 136 base::FilePath to_be_frozen_control_path_;
127 base::FilePath to_be_frozen_state_path_; 137 base::FilePath to_be_frozen_state_path_;
128 138
129 bool enabled_; 139 bool enabled_;
130 140
141 // True iff FreezeRenderers() wrote its command successfully the last time it
142 // was called.
143 bool froze_successfully_;
144
131 DISALLOW_COPY_AND_ASSIGN(FileWorker); 145 DISALLOW_COPY_AND_ASSIGN(FileWorker);
132 }; 146 };
133 147
134 FreezerCgroupProcessManager::FreezerCgroupProcessManager() 148 FreezerCgroupProcessManager::FreezerCgroupProcessManager()
135 : file_thread_(content::BrowserThread::GetTaskRunnerForThread( 149 : file_thread_(content::BrowserThread::GetTaskRunnerForThread(
136 content::BrowserThread::FILE)), 150 content::BrowserThread::FILE)),
137 file_worker_(new FileWorker(file_thread_)) { 151 file_worker_(new FileWorker(file_thread_)) {
138 file_thread_->PostTask(FROM_HERE, 152 file_thread_->PostTask(FROM_HERE,
139 base::Bind(&FileWorker::Start, 153 base::Bind(&FileWorker::Start,
140 base::Unretained(file_worker_.get()))); 154 base::Unretained(file_worker_.get())));
(...skipping 27 matching lines...) Expand all
168 182
169 void FreezerCgroupProcessManager::CheckCanFreezeRenderers( 183 void FreezerCgroupProcessManager::CheckCanFreezeRenderers(
170 ResultCallback callback) { 184 ResultCallback callback) {
171 file_thread_->PostTask(FROM_HERE, 185 file_thread_->PostTask(FROM_HERE,
172 base::Bind(&FileWorker::CheckCanFreezeRenderers, 186 base::Bind(&FileWorker::CheckCanFreezeRenderers,
173 base::Unretained(file_worker_.get()), 187 base::Unretained(file_worker_.get()),
174 callback)); 188 callback));
175 } 189 }
176 190
177 } // namespace chromeos 191 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698