Chromium Code Reviews| 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"; |
|
achuithb
2015/02/12 22:42:04
Shouldn't this be kTouchpadEventLogDir?
Shecky Lin
2015/02/13 05:12:22
This will be used for all touchpad/mice/touchscree
| |
| 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"; | |
| 45 const char kUuencodeCommand[] = "/usr/bin/uuencode"; | |
| 46 | |
| 47 const int kMaxDeviceTouchEventLogs = 7; | |
| 48 | |
| 49 void CleanupEventLog(scoped_ptr<std::vector<base::FilePath>> log_paths) { | |
|
achuithb
2015/02/12 22:42:04
Function comment please
Shecky Lin
2015/02/13 05:12:22
Done.
| |
| 50 for (size_t i = 0; i < log_paths->size(); ++i) | |
| 51 base::DeleteFile((*log_paths)[i], false); | |
| 52 } | |
| 53 | |
| 54 std::string GetEventLogListOfOnePrefix( | |
|
achuithb
2015/02/12 22:42:04
Please add a function comment explaining the input
Shecky Lin
2015/02/13 05:12:22
Done.
| |
| 55 const std::vector<base::FilePath>* log_paths, | |
|
achuithb
2015/02/12 22:42:04
Shouldn't this be const std::vector<base::FilePath
Shecky Lin
2015/02/13 05:12:22
Done.
| |
| 56 const std::string& prefix) { | |
| 57 int collected = 0; | |
| 58 std::string log_list; | |
| 59 for (size_t i = 0; i < log_paths->size(); ++i) { | |
| 60 std::string basename = (*log_paths)[i].BaseName().value(); | |
|
achuithb
2015/02/12 22:42:04
const std::string
Shecky Lin
2015/02/13 05:12:22
Done.
| |
| 61 if (StartsWithASCII(basename, prefix, true)) { | |
| 62 log_list.append(" " + (*log_paths)[i].value()); | |
| 63 | |
| 64 // Limit the max number of collected logs to shorten the log collection | |
| 65 // process. | |
| 66 ++collected; | |
| 67 if (collected >= kMaxDeviceTouchEventLogs) | |
|
achuithb
2015/02/12 22:42:04
Feel like kMaxDeviceTouchEventLogs should be an in
Shecky Lin
2015/02/13 05:12:22
Done.
| |
| 68 break; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 return log_list; | |
| 73 } | |
| 74 | |
| 75 // Pack the collected event logs in a way that is compatible with the log | |
| 76 // analysis tools. | |
| 77 void PackEventLog(system_logs::SystemLogsResponse* response, | |
| 78 scoped_ptr<std::vector<base::FilePath>> log_paths) { | |
| 79 // Combine logs with a command line call that tars them up and uuencode the | |
| 80 // result in one string. This is to be compatible with the X11 behavior. | |
| 81 std::vector<std::pair<std::string, base::CommandLine>> commands; | |
|
achuithb
2015/02/12 22:42:04
You should have a DCHECK to ensure this is running
Shecky Lin
2015/02/13 05:12:22
This function is supposed to be run on the blockin
achuithb
2015/02/17 21:21:06
Something like this?
https://code.google.com/p/chr
Shecky Lin
2015/02/24 08:28:40
Didn't know there is such a thing. Thanks!
| |
| 82 base::CommandLine command = base::CommandLine(base::FilePath(kShellCommand)); | |
|
achuithb
2015/02/12 22:42:04
Might be more readable as:
base::CommandLine comma
Shecky Lin
2015/02/13 05:12:22
Unfortunately, it would result in compile error be
| |
| 83 command.AppendArg("-c"); | |
|
achuithb
2015/02/12 22:42:04
Why not add this to kShellCommand?
const char kShe
Shecky Lin
2015/02/13 05:12:22
I won't be able to pass it to base::FilePath in th
| |
| 84 | |
| 85 // Make a list that contains touchpad (and mouse) event logs only. | |
| 86 std::string touchpad_log_list = | |
|
achuithb
2015/02/12 22:42:04
const
Shecky Lin
2015/02/13 05:12:22
Done.
| |
| 87 GetEventLogListOfOnePrefix(log_paths.get(), kTouchpadGestureLogPrefix) + | |
| 88 GetEventLogListOfOnePrefix(log_paths.get(), kTouchpadEvdevLogPrefix); | |
| 89 command.AppendArg(std::string(kTarCommand) + " cf -" + touchpad_log_list + | |
|
achuithb
2015/02/12 22:42:05
I'd propose
const char kTarCommand[] = "/bin/tar c
Shecky Lin
2015/02/13 05:12:22
Done.
| |
| 90 " 2>/dev/null | " + kUuencodeCommand + | |
| 91 " -m touchpad_activity_log.tar"); | |
| 92 commands.push_back(std::make_pair(kTouchpadEventLogDataKey, command)); | |
| 93 | |
| 94 // For now only touchpad (and mouse) logs are actually collected. | |
| 95 for (size_t i = 0; i < commands.size(); ++i) { | |
| 96 std::string output; | |
| 97 base::GetAppOutput(commands[i].second, &output); | |
| 98 (*response)[commands[i].first] = output; | |
| 99 } | |
| 100 | |
| 101 // Cleanup these temporary log files. | |
| 102 BrowserThread::PostBlockingPoolTask( | |
| 103 FROM_HERE, base::Bind(CleanupEventLog, base::Passed(&log_paths))); | |
| 104 } | |
| 105 | |
| 106 // Callback for handing the outcome of GetTouchEventLog(). | |
| 107 // | |
| 108 // This is the end of the whole touch log collection process. | |
| 109 void OnEventLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, | |
| 110 const system_logs::SysLogsSourceCallback& callback, | |
| 111 scoped_ptr<std::vector<base::FilePath>> log_paths) { | |
| 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 113 | |
| 114 base::Closure pack_closure = | |
|
achuithb
2015/02/12 22:42:05
Personally I don't think these temporaries pack_cl
spang
2015/02/13 02:15:13
Unfortunately in-lining both closures would be wro
Shecky Lin
2015/02/13 05:12:22
Yes, I do this for the specific reason.
achuithb
2015/02/17 21:21:06
Perhaps we should add a comment here then in case
Shecky Lin
2015/02/24 08:28:40
Done.
| |
| 115 base::Bind(&PackEventLog, base::Unretained(response.get()), | |
| 116 base::Passed(&log_paths)); | |
| 117 base::Closure callback_closure = | |
| 118 base::Bind(callback, base::Owned(response.release())); | |
| 119 BrowserThread::PostBlockingPoolTaskAndReply(FROM_HERE, pack_closure, | |
| 120 callback_closure); | |
| 121 } | |
| 122 | |
| 123 // Callback for handing the outcome of GetTouchDeviceStatus(). | |
| 124 // | |
| 125 // Appends the collected log to the SystemLogsResponse map. Also goes on to | |
| 126 // collect touch event logs. | |
| 34 void OnStatusLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, | 127 void OnStatusLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, |
| 35 const system_logs::SysLogsSourceCallback& callback, | 128 const system_logs::SysLogsSourceCallback& callback, |
| 36 scoped_ptr<std::string> log) { | 129 scoped_ptr<std::string> log) { |
| 37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 38 (*response)[kDeviceStatusLogDataKey] = *log; | 131 (*response)[kDeviceStatusLogDataKey] = *log; |
| 39 | 132 |
| 40 BrowserThread::PostTask( | 133 // Collect touch event logs. |
| 41 BrowserThread::UI, FROM_HERE, | 134 const base::FilePath kBaseLogPath(kTouchEventLogDir); |
| 42 base::Bind(callback, base::Owned(response.release()))); | 135 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchEventLog( |
| 136 kBaseLogPath, | |
| 137 base::Bind(&OnEventLogCollected, base::Passed(&response), callback)); | |
| 43 } | 138 } |
| 44 | 139 |
| 45 // Collect touch HUD debug logs. This needs to be done on the UI thread. | 140 // Collect touch HUD debug logs. This needs to be done on the UI thread. |
| 46 void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) { | 141 void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) { |
| 47 scoped_ptr<base::DictionaryValue> dictionary = | 142 scoped_ptr<base::DictionaryValue> dictionary = |
| 48 ash::TouchHudDebug::GetAllAsDictionary(); | 143 ash::TouchHudDebug::GetAllAsDictionary(); |
| 49 if (!dictionary->empty()) { | 144 if (!dictionary->empty()) { |
| 50 std::string touch_log; | 145 std::string touch_log; |
| 51 JSONStringValueSerializer json(&touch_log); | 146 JSONStringValueSerializer json(&touch_log); |
| 52 json.set_pretty_print(true); | 147 json.set_pretty_print(true); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 65 | 160 |
| 66 scoped_ptr<SystemLogsResponse> response(new SystemLogsResponse); | 161 scoped_ptr<SystemLogsResponse> response(new SystemLogsResponse); |
| 67 CollectTouchHudDebugLog(response.get()); | 162 CollectTouchHudDebugLog(response.get()); |
| 68 | 163 |
| 69 // Collect touch device status logs. | 164 // Collect touch device status logs. |
| 70 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchDeviceStatus( | 165 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchDeviceStatus( |
| 71 base::Bind(&OnStatusLogCollected, base::Passed(&response), callback)); | 166 base::Bind(&OnStatusLogCollected, base::Passed(&response), callback)); |
| 72 } | 167 } |
| 73 | 168 |
| 74 } // namespace system_logs | 169 } // namespace system_logs |
| OLD | NEW |