OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/system_logs/touch_log_source.h" | 5 #include "chrome/browser/chromeos/system_logs/touch_log_source.h" |
6 | 6 |
7 #include "ash/touch/touch_hud_debug.h" | 7 #include "ash/touch/touch_hud_debug.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | |
13 #include "base/files/file_util.h" | |
12 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
15 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
16 #include "components/feedback/feedback_util.h" | 18 #include "components/feedback/feedback_util.h" |
17 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
18 #include "ui/ozone/public/input_controller.h" | 20 #include "ui/ozone/public/input_controller.h" |
19 #include "ui/ozone/public/ozone_platform.h" | 21 #include "ui/ozone/public/ozone_platform.h" |
20 | 22 |
21 using content::BrowserThread; | 23 using content::BrowserThread; |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const char kHUDLogDataKey[] = "hud_log"; | 27 const char kHUDLogDataKey[] = "hud_log"; |
26 | 28 |
27 // The prefix "hack-33025" was historically chosen in http://crbug.com/139715. | 29 // The prefix "hack-33025" was historically chosen in http://crbug.com/139715. |
28 // We continue to go with it in order to be compatible with the existing touch | 30 // We continue to go with it in order to be compatible with the existing touch |
29 // log processing toolchain. | 31 // log processing toolchain. |
30 const char kDeviceStatusLogDataKey[] = "hack-33025-touchpad"; | 32 const char kDeviceStatusLogDataKey[] = "hack-33025-touchpad"; |
33 const char kTouchpadEventLogDataKey[] = "hack-33025-touchpad_activity"; | |
31 | 34 |
32 // Callback for handing the outcome of GetTouchDeviceStatus(). Appends the | 35 // Directory for temp touch event logs. |
33 // collected log to the SystemLogsResponse map. | 36 const char kTouchEventLogDir[] = "/home/chronos/user/log"; |
37 | |
38 // Prefixes of touch event logs. | |
39 const char kTouchpadGestureLogPrefix[] = "touchpad_activity_"; | |
40 const char kTouchpadEvdevLogPrefix[] = "cmt_input_events_"; | |
41 | |
42 // Binary paths. | |
43 const char kShellCommand[] = "/bin/sh"; | |
44 const char kTarCommand[] = "/bin/tar cf -"; | |
45 const char kUuencodeCommand[] = "/usr/bin/uuencode"; | |
46 | |
47 const int kMaxDeviceTouchEventLogs = 7; | |
48 | |
49 // Clean up intermediate log files dumped during feedback creation. | |
50 void CleanupEventLog(scoped_ptr<std::vector<base::FilePath>> log_paths) { | |
51 for (size_t i = 0; i < log_paths->size(); ++i) | |
52 base::DeleteFile((*log_paths)[i], false); | |
53 } | |
54 | |
55 // Check for all known log paths and find the ones whose filenames match a | |
56 // prefix. Concatenate their filenames into one string. |max_log_count| is | |
57 // the maximum number of logs that we will collect. | |
58 // | |
59 // This is used to distinguish touchpad/mice logs from touchscreen logs. | |
60 std::string GetEventLogListOfOnePrefix( | |
61 const std::vector<base::FilePath>& log_paths, | |
62 const std::string& prefix, | |
63 const int max_log_count) { | |
64 int collected = 0; | |
65 std::string log_list; | |
66 for (size_t i = 0; i < log_paths.size(); ++i) { | |
67 const std::string basename = log_paths[i].BaseName().value(); | |
68 if (StartsWithASCII(basename, prefix, true)) { | |
69 log_list.append(" " + log_paths[i].value()); | |
70 | |
71 // Limit the max number of collected logs to shorten the log collection | |
72 // process. | |
73 if (++collected >= max_log_count) | |
74 break; | |
75 } | |
76 } | |
77 | |
78 return log_list; | |
79 } | |
80 | |
81 // Pack the collected event logs in a way that is compatible with the log | |
82 // analysis tools. | |
83 void PackEventLog(system_logs::SystemLogsResponse* response, | |
84 scoped_ptr<std::vector<base::FilePath>> log_paths) { | |
85 CHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
achuithb
2015/02/24 19:32:07
Let's just make this a DCHECK similar to other thr
Shecky Lin
2015/02/25 06:21:46
Yep, sorry for the typo.
| |
86 | |
87 // Combine logs with a command line call that tars them up and uuencode the | |
88 // result in one string. This is to be compatible with the X11 behavior. | |
89 std::vector<std::pair<std::string, base::CommandLine>> commands; | |
90 base::CommandLine command = base::CommandLine(base::FilePath(kShellCommand)); | |
91 command.AppendArg("-c"); | |
92 | |
93 // Make a list that contains touchpad (and mouse) event logs only. | |
94 const std::string touchpad_log_list = | |
95 GetEventLogListOfOnePrefix(*log_paths, kTouchpadGestureLogPrefix, | |
96 kMaxDeviceTouchEventLogs) + | |
97 GetEventLogListOfOnePrefix(*log_paths, kTouchpadEvdevLogPrefix, | |
98 kMaxDeviceTouchEventLogs); | |
99 command.AppendArg(std::string(kTarCommand) + touchpad_log_list + | |
100 " 2>/dev/null | " + kUuencodeCommand + | |
101 " -m touchpad_activity_log.tar"); | |
102 commands.push_back(std::make_pair(kTouchpadEventLogDataKey, command)); | |
103 | |
104 // For now only touchpad (and mouse) logs are actually collected. | |
105 for (size_t i = 0; i < commands.size(); ++i) { | |
106 std::string output; | |
107 base::GetAppOutput(commands[i].second, &output); | |
108 (*response)[commands[i].first] = output; | |
109 } | |
110 | |
111 // Cleanup these temporary log files. | |
112 BrowserThread::PostBlockingPoolTask( | |
113 FROM_HERE, base::Bind(CleanupEventLog, base::Passed(&log_paths))); | |
114 } | |
115 | |
116 // Callback for handing the outcome of GetTouchEventLog(). | |
117 // | |
118 // This is the end of the whole touch log collection process. | |
119 void OnEventLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, | |
120 const system_logs::SysLogsSourceCallback& callback, | |
121 scoped_ptr<std::vector<base::FilePath>> log_paths) { | |
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
123 | |
124 // Put tasks in closures so that the compiler may not call release() before | |
125 // get()/Passed(). | |
achuithb
2015/02/24 19:32:07
Not sure if this is clear enough. How about:
// We
Shecky Lin
2015/02/25 06:21:46
Done.
| |
126 base::Closure pack_closure = | |
achuithb
2015/02/24 19:32:07
Make this const
Shecky Lin
2015/02/25 06:21:46
Done.
| |
127 base::Bind(&PackEventLog, base::Unretained(response.get()), | |
128 base::Passed(&log_paths)); | |
129 base::Closure callback_closure = | |
achuithb
2015/02/24 19:32:07
Make this const
Shecky Lin
2015/02/25 06:21:46
Done.
| |
130 base::Bind(callback, base::Owned(response.release())); | |
131 BrowserThread::PostBlockingPoolTaskAndReply(FROM_HERE, pack_closure, | |
132 callback_closure); | |
133 } | |
134 | |
135 // Callback for handing the outcome of GetTouchDeviceStatus(). | |
136 // | |
137 // Appends the collected log to the SystemLogsResponse map. Also goes on to | |
138 // collect touch event logs. | |
34 void OnStatusLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, | 139 void OnStatusLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, |
35 const system_logs::SysLogsSourceCallback& callback, | 140 const system_logs::SysLogsSourceCallback& callback, |
36 scoped_ptr<std::string> log) { | 141 scoped_ptr<std::string> log) { |
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
38 (*response)[kDeviceStatusLogDataKey] = *log; | 143 (*response)[kDeviceStatusLogDataKey] = *log; |
39 | 144 |
40 BrowserThread::PostTask( | 145 // Collect touch event logs. |
41 BrowserThread::UI, FROM_HERE, | 146 const base::FilePath kBaseLogPath(kTouchEventLogDir); |
42 base::Bind(callback, base::Owned(response.release()))); | 147 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchEventLog( |
148 kBaseLogPath, | |
149 base::Bind(&OnEventLogCollected, base::Passed(&response), callback)); | |
43 } | 150 } |
44 | 151 |
45 // Collect touch HUD debug logs. This needs to be done on the UI thread. | 152 // Collect touch HUD debug logs. This needs to be done on the UI thread. |
46 void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) { | 153 void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) { |
47 scoped_ptr<base::DictionaryValue> dictionary = | 154 scoped_ptr<base::DictionaryValue> dictionary = |
48 ash::TouchHudDebug::GetAllAsDictionary(); | 155 ash::TouchHudDebug::GetAllAsDictionary(); |
49 if (!dictionary->empty()) { | 156 if (!dictionary->empty()) { |
50 std::string touch_log; | 157 std::string touch_log; |
51 JSONStringValueSerializer json(&touch_log); | 158 JSONStringValueSerializer json(&touch_log); |
52 json.set_pretty_print(true); | 159 json.set_pretty_print(true); |
(...skipping 12 matching lines...) Expand all Loading... | |
65 | 172 |
66 scoped_ptr<SystemLogsResponse> response(new SystemLogsResponse); | 173 scoped_ptr<SystemLogsResponse> response(new SystemLogsResponse); |
67 CollectTouchHudDebugLog(response.get()); | 174 CollectTouchHudDebugLog(response.get()); |
68 | 175 |
69 // Collect touch device status logs. | 176 // Collect touch device status logs. |
70 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchDeviceStatus( | 177 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchDeviceStatus( |
71 base::Bind(&OnStatusLogCollected, base::Passed(&response), callback)); | 178 base::Bind(&OnStatusLogCollected, base::Passed(&response), callback)); |
72 } | 179 } |
73 | 180 |
74 } // namespace system_logs | 181 } // namespace system_logs |
OLD | NEW |