OLD | NEW |
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/process_iterator.h" | 5 #include "base/process/process_iterator.h" |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/process/internal_linux.h" | 9 #include "base/process/internal_linux.h" |
| 10 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // Reads the |field_num|th field from |proc_stats|. | 18 // Reads the |field_num|th field from |proc_stats|. |
18 // Returns an empty string on failure. | 19 // Returns an empty string on failure. |
19 // This version only handles VM_COMM and VM_STATE, which are the only fields | 20 // This version only handles VM_COMM and VM_STATE, which are the only fields |
(...skipping 21 matching lines...) Expand all Loading... |
41 bool GetProcCmdline(pid_t pid, std::vector<std::string>* proc_cmd_line_args) { | 42 bool GetProcCmdline(pid_t pid, std::vector<std::string>* proc_cmd_line_args) { |
42 // Synchronously reading files in /proc is safe. | 43 // Synchronously reading files in /proc is safe. |
43 ThreadRestrictions::ScopedAllowIO allow_io; | 44 ThreadRestrictions::ScopedAllowIO allow_io; |
44 | 45 |
45 FilePath cmd_line_file = internal::GetProcPidDir(pid).Append("cmdline"); | 46 FilePath cmd_line_file = internal::GetProcPidDir(pid).Append("cmdline"); |
46 std::string cmd_line; | 47 std::string cmd_line; |
47 if (!ReadFileToString(cmd_line_file, &cmd_line)) | 48 if (!ReadFileToString(cmd_line_file, &cmd_line)) |
48 return false; | 49 return false; |
49 std::string delimiters; | 50 std::string delimiters; |
50 delimiters.push_back('\0'); | 51 delimiters.push_back('\0'); |
51 Tokenize(cmd_line, delimiters, proc_cmd_line_args); | 52 *proc_cmd_line_args = SplitString(cmd_line, delimiters, KEEP_WHITESPACE, |
| 53 SPLIT_WANT_NONEMPTY); |
52 return true; | 54 return true; |
53 } | 55 } |
54 | 56 |
55 } // namespace | 57 } // namespace |
56 | 58 |
57 ProcessIterator::ProcessIterator(const ProcessFilter* filter) | 59 ProcessIterator::ProcessIterator(const ProcessFilter* filter) |
58 : filter_(filter) { | 60 : filter_(filter) { |
59 procfs_dir_ = opendir(internal::kProcDir); | 61 procfs_dir_ = opendir(internal::kProcDir); |
60 } | 62 } |
61 | 63 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return true; | 130 return true; |
129 } | 131 } |
130 | 132 |
131 bool NamedProcessIterator::IncludeEntry() { | 133 bool NamedProcessIterator::IncludeEntry() { |
132 if (executable_name_ != entry().exe_file()) | 134 if (executable_name_ != entry().exe_file()) |
133 return false; | 135 return false; |
134 return ProcessIterator::IncludeEntry(); | 136 return ProcessIterator::IncludeEntry(); |
135 } | 137 } |
136 | 138 |
137 } // namespace base | 139 } // namespace base |
OLD | NEW |