command_line_log_source.cc revision 58537e28ecd584eab876aee8be7156509866d23a
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_logs/command_line_log_source.h" 6 7#include <string> 8#include <vector> 9 10#include "base/bind.h" 11#include "base/command_line.h" 12#include "base/files/file_path.h" 13#include "base/logging.h" 14#include "base/process/launch.h" 15#include "content/public/browser/browser_thread.h" 16 17using content::BrowserThread; 18 19namespace { 20 21// Gathers log data from various scripts/programs. 22void ExecuteCommandLines(chromeos::SystemLogsResponse* response) { 23 // TODO(tudalex): Move program calling in a array or something similar to make 24 // it more easier to modify and understand. 25 std::vector<std::pair<std::string, CommandLine> > commands; 26 27 CommandLine command(base::FilePath("/usr/bin/amixer")); 28 command.AppendArg("-c0"); 29 command.AppendArg("contents"); 30 commands.push_back(std::make_pair("alsa controls", command)); 31 32 command = CommandLine((base::FilePath("/usr/bin/cras_test_client"))); 33 command.AppendArg("--dump_server_info"); 34 commands.push_back(std::make_pair("cras", command)); 35 36 command = CommandLine((base::FilePath("/usr/bin/cras_test_client"))); 37 command.AppendArg("--loopback_file"); 38 command.AppendArg("/dev/null"); 39 command.AppendArg("--rate"); 40 command.AppendArg("44100"); 41 command.AppendArg("--duration_seconds"); 42 command.AppendArg("0.01"); 43 command.AppendArg("--show_total_rms"); 44 commands.push_back(std::make_pair("cras_rms", command)); 45 46 command = CommandLine((base::FilePath("/usr/bin/printenv"))); 47 commands.push_back(std::make_pair("env", command)); 48 49 command = CommandLine(base::FilePath("/usr/bin/setxkbmap")); 50 command.AppendArg("-print"); 51 command.AppendArg("-query"); 52 commands.push_back(std::make_pair("setxkbmap", command)); 53 54 command = CommandLine(base::FilePath("/usr/bin/xinput")); 55 command.AppendArg("list"); 56 command.AppendArg("--long"); 57 commands.push_back(std::make_pair("xinput", command)); 58 59 command = CommandLine(base::FilePath("/usr/bin/xrandr")); 60 command.AppendArg("--verbose"); 61 commands.push_back(std::make_pair("xrandr", command)); 62 63 // Get a list of file sizes for the logged in user (excluding the names of 64 // the files in the Downloads directory for privay reasons). 65 command = CommandLine(base::FilePath("/bin/sh")); 66 command.AppendArg("-c"); 67 command.AppendArg("/usr/bin/du -h /home/chronos/user |" 68 " grep -v -e \\/home\\/chronos\\/user\\/Downloads\\/"); 69 commands.push_back(std::make_pair("user_files", command)); 70 71 for (size_t i = 0; i < commands.size(); ++i) { 72 std::string output; 73 base::GetAppOutput(commands[i].second, &output); 74 (*response)[commands[i].first] = output; 75 } 76} 77 78} // namespace 79 80namespace chromeos { 81 82void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) { 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 84 DCHECK(!callback.is_null()); 85 86 SystemLogsResponse* response = new SystemLogsResponse; 87 BrowserThread::PostBlockingPoolTaskAndReply( 88 FROM_HERE, 89 base::Bind(&ExecuteCommandLines, response), 90 base::Bind(callback, base::Owned(response))); 91} 92 93} // namespace chromeos 94