1 // Copyright (c) 2013 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/touch_log_source.h"
7 #include "ash/touch/touch_hud_debug.h"
9 #include "base/command_line.h"
10 #include "base/json/json_string_value_serializer.h"
11 #include "base/process/launch.h"
12 #include "chrome/browser/feedback/feedback_util.h"
13 #include "content/public/browser/browser_thread.h"
15 using content::BrowserThread
;
19 const char kHUDLogDataKey
[] = "hud_log";
21 void GetTouchLogs(system_logs::SystemLogsResponse
* response
) {
22 scoped_ptr
<base::DictionaryValue
> dictionary
=
23 ash::internal::TouchHudDebug::GetAllAsDictionary();
24 if (!dictionary
->empty()) {
25 std::string touch_log
;
26 JSONStringValueSerializer
json(&touch_log
);
27 json
.set_pretty_print(true);
28 if (json
.Serialize(*dictionary
) && !touch_log
.empty())
29 (*response
)[kHUDLogDataKey
] = touch_log
;
32 std::vector
<std::pair
<std::string
, CommandLine
> > commands
;
34 CommandLine(base::FilePath("/opt/google/touchpad/tpcontrol"));
35 command
.AppendArg("status");
36 commands
.push_back(std::make_pair("hack-33025-touchpad", command
));
39 CommandLine(base::FilePath("/opt/google/touchpad/generate_userfeedback"));
40 commands
.push_back(std::make_pair("hack-33025-touchpad_activity", command
));
42 command
= CommandLine(
43 base::FilePath("/opt/google/touchscreen/touchscreen_feedback"));
45 std::make_pair("hack-33025-touchscreen_activity", command
));
47 for (size_t i
= 0; i
< commands
.size(); ++i
) {
49 base::GetAppOutput(commands
[i
].second
, &output
);
50 (*response
)[commands
[i
].first
] = output
;
56 namespace system_logs
{
58 TouchLogSource::TouchLogSource() {
61 TouchLogSource::~TouchLogSource() {
64 void TouchLogSource::Fetch(const SysLogsSourceCallback
& callback
) {
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
66 DCHECK(!callback
.is_null());
68 SystemLogsResponse
* response
= new SystemLogsResponse
;
69 BrowserThread::PostBlockingPoolTaskAndReply(
71 base::Bind(&GetTouchLogs
, response
),
72 base::Bind(callback
, base::Owned(response
)));
75 } // namespace system_logs