Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/system/commandline_fetcher.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/command_line.h" | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/file_util.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "base/string_util.h" | |
| 14 | |
| 15 namespace chromeos { | |
| 16 namespace system { | |
| 17 | |
| 18 void CommandLineFetcher::Fetch(SysLogsFetcherCallback request) | |
| 19 { | |
| 20 FilePath temp_filename; | |
| 21 SysInfoResponse* response = new SysInfoResponse; | |
| 22 if (!file_util::CreateTemporaryFile(&temp_filename)) | |
|
rkc1
2012/08/04 01:15:05
Change this to use base::GetAppOutput.
tudalex(Chromium)
2012/08/05 01:15:12
Done.
| |
| 23 { | |
| 24 request.Run(response); | |
| 25 return; | |
| 26 } | |
| 27 std::string cmd = command_ + " >> " + | |
| 28 temp_filename.value(); | |
| 29 | |
| 30 // Ignore the return value - if the script execution didn't work | |
| 31 // stderr won't go into the output file anyway. | |
| 32 if (::system(cmd.c_str()) == -1) | |
| 33 LOG(WARNING) << "Command " << cmd << " failed to run"; | |
| 34 // Read logs from the temp file | |
| 35 std::string data; | |
| 36 bool read_success = file_util::ReadFileToString(temp_filename, | |
| 37 &data); | |
| 38 // if we were using an internal temp file, the user does not need the | |
| 39 // logs to stay past the ReadFile call - delete the file | |
| 40 if (!read_success) | |
| 41 { | |
| 42 request.Run(response); | |
| 43 return; | |
| 44 } | |
| 45 file_util::Delete(temp_filename, false); | |
| 46 (*response)[key_] = data; | |
| 47 request.Run(response); | |
| 48 } | |
| 49 | |
| 50 } // namespace system | |
| 51 } // namespace chromeos | |
| OLD | NEW |