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

Side by Side Diff: base/process/memory_linux.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/prefs/json_pref_store_unittest.cc ('k') | base/test/test_file_util_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/process/memory.h" 5 #include "base/process/memory.h"
6 6
7 #include <new> 7 #include <new>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // the setuid sandbox (in process_util_linux.c, in the sandbox source) 143 // the setuid sandbox (in process_util_linux.c, in the sandbox source)
144 // also has its own C version. 144 // also has its own C version.
145 bool AdjustOOMScore(ProcessId process, int score) { 145 bool AdjustOOMScore(ProcessId process, int score) {
146 if (score < 0 || score > kMaxOomScore) 146 if (score < 0 || score > kMaxOomScore)
147 return false; 147 return false;
148 148
149 FilePath oom_path(internal::GetProcPidDir(process)); 149 FilePath oom_path(internal::GetProcPidDir(process));
150 150
151 // Attempt to write the newer oom_score_adj file first. 151 // Attempt to write the newer oom_score_adj file first.
152 FilePath oom_file = oom_path.AppendASCII("oom_score_adj"); 152 FilePath oom_file = oom_path.AppendASCII("oom_score_adj");
153 if (file_util::PathExists(oom_file)) { 153 if (PathExists(oom_file)) {
154 std::string score_str = IntToString(score); 154 std::string score_str = IntToString(score);
155 DVLOG(1) << "Adjusting oom_score_adj of " << process << " to " 155 DVLOG(1) << "Adjusting oom_score_adj of " << process << " to "
156 << score_str; 156 << score_str;
157 int score_len = static_cast<int>(score_str.length()); 157 int score_len = static_cast<int>(score_str.length());
158 return (score_len == file_util::WriteFile(oom_file, 158 return (score_len == file_util::WriteFile(oom_file,
159 score_str.c_str(), 159 score_str.c_str(),
160 score_len)); 160 score_len));
161 } 161 }
162 162
163 // If the oom_score_adj file doesn't exist, then we write the old 163 // If the oom_score_adj file doesn't exist, then we write the old
164 // style file and translate the oom_adj score to the range 0-15. 164 // style file and translate the oom_adj score to the range 0-15.
165 oom_file = oom_path.AppendASCII("oom_adj"); 165 oom_file = oom_path.AppendASCII("oom_adj");
166 if (file_util::PathExists(oom_file)) { 166 if (PathExists(oom_file)) {
167 // Max score for the old oom_adj range. Used for conversion of new 167 // Max score for the old oom_adj range. Used for conversion of new
168 // values to old values. 168 // values to old values.
169 const int kMaxOldOomScore = 15; 169 const int kMaxOldOomScore = 15;
170 170
171 int converted_score = score * kMaxOldOomScore / kMaxOomScore; 171 int converted_score = score * kMaxOldOomScore / kMaxOomScore;
172 std::string score_str = IntToString(converted_score); 172 std::string score_str = IntToString(converted_score);
173 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str; 173 DVLOG(1) << "Adjusting oom_adj of " << process << " to " << score_str;
174 int score_len = static_cast<int>(score_str.length()); 174 int score_len = static_cast<int>(score_str.length());
175 return (score_len == file_util::WriteFile(oom_file, 175 return (score_len == file_util::WriteFile(oom_file,
176 score_str.c_str(), 176 score_str.c_str(),
177 score_len)); 177 score_len));
178 } 178 }
179 179
180 return false; 180 return false;
181 } 181 }
182 182
183 } // namespace base 183 } // namespace base
OLDNEW
« no previous file with comments | « base/prefs/json_pref_store_unittest.cc ('k') | base/test/test_file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698