| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/test/chrome_process_util.h" | 5 #include "chrome/test/chrome_process_util.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/process_util.h" | 14 #include "base/process_util.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
| 17 | 17 |
| 18 base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { | 18 base::ProcessId ChromeBrowserProcessId(const FilePath& data_dir) { |
| 19 FilePath socket_name = data_dir.Append(chrome::kSingletonSocketFilename); | 19 FilePath socket_name = data_dir.Append(chrome::kSingletonSocketFilename); |
| 20 | 20 |
| 21 std::vector<std::string> argv; | 21 std::vector<std::string> argv; |
| 22 argv.push_back("fuser"); | 22 argv.push_back("fuser"); |
| 23 argv.push_back(socket_name.value()); | 23 argv.push_back(socket_name.value()); |
| 24 | 24 |
| 25 std::string fuser_output; | 25 std::string fuser_output; |
| 26 if (!base::GetAppOutput(CommandLine(argv), &fuser_output)) | 26 if (!base::GetAppOutput(CommandLine(argv), &fuser_output)) |
| 27 return -1; | 27 return -1; |
| 28 | 28 |
| 29 std::string trimmed_output; | 29 std::string trimmed_output; |
| 30 TrimWhitespace(fuser_output, TRIM_ALL, &trimmed_output); | 30 TrimWhitespaceASCII(fuser_output, TRIM_ALL, &trimmed_output); |
| 31 | 31 |
| 32 if (trimmed_output.find(' ') != std::string::npos) { | 32 if (trimmed_output.find(' ') != std::string::npos) { |
| 33 LOG(FATAL) << "Expected exactly 1 process to have socket open: " << | 33 LOG(FATAL) << "Expected exactly 1 process to have socket open: " << |
| 34 fuser_output; | 34 fuser_output; |
| 35 return -1; | 35 return -1; |
| 36 } | 36 } |
| 37 | 37 |
| 38 int pid; | 38 int pid; |
| 39 if (!StringToInt(trimmed_output, &pid)) { | 39 if (!StringToInt(trimmed_output, &pid)) { |
| 40 LOG(FATAL) << "Unexpected fuser output: " << fuser_output; | 40 LOG(FATAL) << "Unexpected fuser output: " << fuser_output; |
| 41 return -1; | 41 return -1; |
| 42 } | 42 } |
| 43 return pid; | 43 return pid; |
| 44 } | 44 } |
| OLD | NEW |