Commit 6c773bec authored by Martin Robinson's avatar Martin Robinson Committed by Commit Bot

Use logging infrastructure for accessibility tools

Bug: 879147
Change-Id: I861ceb38370a0de959c6881735819097a030cb09
Reviewed-on: https://chromium-review.googlesource.com/1202542
Commit-Queue: Martin Robinson <mrobinson@igalia.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589615}
parent cbdb8bd6
......@@ -27,16 +27,26 @@ bool StringToInt(std::string str, int* result) {
: base::StringToInt(str, result);
}
bool AXDumpEventsLogMessageHandler(int severity,
const char* file,
int line,
size_t message_start,
const std::string& str) {
printf("%s", str.substr(message_start).c_str());
return true;
}
} // namespace
int main(int argc, char** argv) {
logging::SetLogMessageHandler(AXDumpEventsLogMessageHandler);
base::CommandLine::Init(argc, argv);
const std::string pid_str =
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kPidSwitch);
int pid;
if (pid_str.empty() || !StringToInt(pid_str, &pid)) {
std::cout << "* Error: No process id provided via --pid=[process-id]."
<< std::endl;
LOG(ERROR) << "* Error: No process id provided via --pid=[process-id].";
return 1;
}
......
......@@ -7,6 +7,7 @@
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "tools/accessibility/inspect/ax_tree_server.h"
......@@ -26,6 +27,15 @@ bool StringToInt(std::string str, unsigned* result) {
: base::StringToUint(str, result);
}
bool AXDumpTreeLogMessageHandler(int severity,
const char* file,
int line,
size_t message_start,
const std::string& str) {
printf("%s", str.substr(message_start).c_str());
return true;
}
gfx::AcceleratedWidget CastToAcceleratedWidget(unsigned window_id) {
#if defined(USE_OZONE) || defined(USE_X11) || defined(OS_MACOSX)
return static_cast<gfx::AcceleratedWidget>(window_id);
......@@ -35,6 +45,8 @@ gfx::AcceleratedWidget CastToAcceleratedWidget(unsigned window_id) {
}
int main(int argc, char** argv) {
logging::SetLogMessageHandler(AXDumpTreeLogMessageHandler);
base::AtExitManager at_exit_manager;
base::CommandLine::Init(argc, argv);
......@@ -52,8 +64,7 @@ int main(int argc, char** argv) {
if (!window_str.empty()) {
unsigned window_id;
if (!StringToInt(window_str, &window_id)) {
std::cout << "* Error: Could not convert window id string to integer."
<< std::endl;
LOG(ERROR) << "* Error: Could not convert window id string to integer.";
return 1;
}
gfx::AcceleratedWidget widget(CastToAcceleratedWidget(window_id));
......@@ -72,7 +83,7 @@ int main(int argc, char** argv) {
return 0;
}
std::cout << "* Error: Neither window handle (--window=[window-handle]) "
<< "nor pattern (--pattern=[pattern]) provided." << std::endl;
LOG(ERROR) << "* Error: Neither window handle (--window=[window-handle]) "
"nor pattern (--pattern=[pattern]) provided.";
return 1;
}
......@@ -16,13 +16,16 @@ AXEventServer::AXEventServer(base::ProcessId pid)
content::AccessibilityEventRecorder::GetInstance(nullptr, pid)) {
recorder_.ListenToEvents(
base::BindRepeating(&AXEventServer::OnEvent, base::Unretained(this)));
std::cout << "Events for process id: " << pid << std::endl;
std::stringstream output;
output << "Events for process id: " << pid;
printf("%s", output.str().c_str());
}
AXEventServer::~AXEventServer() = default;
void AXEventServer::OnEvent(const std::string& event) const {
std::cout << event << std::endl;
printf("%s\n", event.c_str());
}
} // namespace tools
......@@ -35,7 +35,7 @@ AXTreeServer::AXTreeServer(const base::StringPiece& pattern,
formatter->BuildAccessibilityTreeForPattern(pattern);
if (!dict) {
std::cout << "Error: Failed to get accessibility tree" << std::endl;
LOG(ERROR) << "Error: Failed to get accessibility tree";
return;
}
......@@ -54,7 +54,7 @@ AXTreeServer::AXTreeServer(base::ProcessId pid,
formatter->BuildAccessibilityTreeForProcess(pid);
if (!dict) {
std::cout << "Error: Failed to get accessibility tree" << std::endl;
LOG(ERROR) << "Error: Failed to get accessibility tree";
return;
}
......@@ -72,7 +72,7 @@ AXTreeServer::AXTreeServer(gfx::AcceleratedWidget widget,
formatter->BuildAccessibilityTreeForWindow(widget);
if (!dict) {
std::cout << "Failed to get accessibility tree" << std::endl;
LOG(ERROR) << "Failed to get accessibility tree";
return;
}
......@@ -143,7 +143,7 @@ void AXTreeServer::Format(AccessibilityTreeFormatter& formatter,
}
// Write to console.
std::cout << accessibility_contents_utf8;
printf("%s", accessibility_contents_utf8.c_str());
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment