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.
5 #include "chrome/browser/chromeos/system_logs/command_line_log_source.h"
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"
17 using content::BrowserThread;
21 // Gathers log data from various scripts/programs.
22 void 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;
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));
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));
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));
46 command = CommandLine((base::FilePath("/usr/bin/printenv")));
47 commands.push_back(std::make_pair("env", command));
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));
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));
59 command = CommandLine(base::FilePath("/usr/bin/xrandr"));
60 command.AppendArg("--verbose");
61 commands.push_back(std::make_pair("xrandr", command));
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));
71 for (size_t i = 0; i < commands.size(); ++i) {
73 base::GetAppOutput(commands[i].second, &output);
74 (*response)[commands[i].first] = output;
82 void CommandLineLogSource::Fetch(const SysLogsSourceCallback& callback) {
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
84 DCHECK(!callback.is_null());
86 SystemLogsResponse* response = new SystemLogsResponse;
87 BrowserThread::PostBlockingPoolTaskAndReply(
89 base::Bind(&ExecuteCommandLines, response),
90 base::Bind(callback, base::Owned(response)));
93 } // namespace chromeos