| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/touch/touch_hud_debug.h" | 9 #include "ash/touch/touch_hud_debug.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 const char kTouchpadEvdevLogPrefix[] = "cmt_input_events_"; | 44 const char kTouchpadEvdevLogPrefix[] = "cmt_input_events_"; |
| 45 | 45 |
| 46 // Binary paths. | 46 // Binary paths. |
| 47 const char kShellCommand[] = "/bin/sh"; | 47 const char kShellCommand[] = "/bin/sh"; |
| 48 const char kTarCommand[] = "/bin/tar cf -"; | 48 const char kTarCommand[] = "/bin/tar cf -"; |
| 49 const char kUuencodeCommand[] = "/usr/bin/uuencode"; | 49 const char kUuencodeCommand[] = "/usr/bin/uuencode"; |
| 50 | 50 |
| 51 const int kMaxDeviceTouchEventLogs = 7; | 51 const int kMaxDeviceTouchEventLogs = 7; |
| 52 | 52 |
| 53 // Clean up intermediate log files dumped during feedback creation. | 53 // Clean up intermediate log files dumped during feedback creation. |
| 54 void CleanupEventLog(scoped_ptr<std::vector<base::FilePath>> log_paths) { | 54 void CleanupEventLog(std::unique_ptr<std::vector<base::FilePath>> log_paths) { |
| 55 for (size_t i = 0; i < log_paths->size(); ++i) | 55 for (size_t i = 0; i < log_paths->size(); ++i) |
| 56 base::DeleteFile((*log_paths)[i], false); | 56 base::DeleteFile((*log_paths)[i], false); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Check for all known log paths and find the ones whose filenames match a | 59 // Check for all known log paths and find the ones whose filenames match a |
| 60 // prefix. Concatenate their filenames into one string. |max_log_count| is | 60 // prefix. Concatenate their filenames into one string. |max_log_count| is |
| 61 // the maximum number of logs that we will collect. | 61 // the maximum number of logs that we will collect. |
| 62 // | 62 // |
| 63 // This is used to distinguish touchpad/mice logs from touchscreen logs. | 63 // This is used to distinguish touchpad/mice logs from touchscreen logs. |
| 64 std::string GetEventLogListOfOnePrefix( | 64 std::string GetEventLogListOfOnePrefix( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 78 break; | 78 break; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 return log_list; | 82 return log_list; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Pack the collected event logs in a way that is compatible with the log | 85 // Pack the collected event logs in a way that is compatible with the log |
| 86 // analysis tools. | 86 // analysis tools. |
| 87 void PackEventLog(system_logs::SystemLogsResponse* response, | 87 void PackEventLog(system_logs::SystemLogsResponse* response, |
| 88 scoped_ptr<std::vector<base::FilePath>> log_paths) { | 88 std::unique_ptr<std::vector<base::FilePath>> log_paths) { |
| 89 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 89 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 90 | 90 |
| 91 // Combine logs with a command line call that tars them up and uuencode the | 91 // Combine logs with a command line call that tars them up and uuencode the |
| 92 // result in one string. This is to be compatible with the X11 behavior. | 92 // result in one string. This is to be compatible with the X11 behavior. |
| 93 std::vector<std::pair<std::string, base::CommandLine>> commands; | 93 std::vector<std::pair<std::string, base::CommandLine>> commands; |
| 94 base::CommandLine command = base::CommandLine(base::FilePath(kShellCommand)); | 94 base::CommandLine command = base::CommandLine(base::FilePath(kShellCommand)); |
| 95 command.AppendArg("-c"); | 95 command.AppendArg("-c"); |
| 96 | 96 |
| 97 // Make a list that contains touchpad (and mouse) event logs only. | 97 // Make a list that contains touchpad (and mouse) event logs only. |
| 98 const std::string touchpad_log_list = | 98 const std::string touchpad_log_list = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Cleanup these temporary log files. | 129 // Cleanup these temporary log files. |
| 130 BrowserThread::PostBlockingPoolTask( | 130 BrowserThread::PostBlockingPoolTask( |
| 131 FROM_HERE, base::Bind(CleanupEventLog, base::Passed(&log_paths))); | 131 FROM_HERE, base::Bind(CleanupEventLog, base::Passed(&log_paths))); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Callback for handing the outcome of GetTouchEventLog(). | 134 // Callback for handing the outcome of GetTouchEventLog(). |
| 135 // | 135 // |
| 136 // This is the end of the whole touch log collection process. | 136 // This is the end of the whole touch log collection process. |
| 137 void OnEventLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, | 137 void OnEventLogCollected( |
| 138 const system_logs::SysLogsSourceCallback& callback, | 138 std::unique_ptr<system_logs::SystemLogsResponse> response, |
| 139 scoped_ptr<std::vector<base::FilePath>> log_paths) { | 139 const system_logs::SysLogsSourceCallback& callback, |
| 140 std::unique_ptr<std::vector<base::FilePath>> log_paths) { |
| 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 141 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 141 | 142 |
| 142 // We cannot eliminate these temporaries and inline these closures because the | 143 // We cannot eliminate these temporaries and inline these closures because the |
| 143 // compiler may call release() before get(). | 144 // compiler may call release() before get(). |
| 144 const base::Closure pack_closure = | 145 const base::Closure pack_closure = |
| 145 base::Bind(&PackEventLog, base::Unretained(response.get()), | 146 base::Bind(&PackEventLog, base::Unretained(response.get()), |
| 146 base::Passed(&log_paths)); | 147 base::Passed(&log_paths)); |
| 147 const base::Closure callback_closure = | 148 const base::Closure callback_closure = |
| 148 base::Bind(callback, base::Owned(response.release())); | 149 base::Bind(callback, base::Owned(response.release())); |
| 149 BrowserThread::PostBlockingPoolTaskAndReply(FROM_HERE, pack_closure, | 150 BrowserThread::PostBlockingPoolTaskAndReply(FROM_HERE, pack_closure, |
| 150 callback_closure); | 151 callback_closure); |
| 151 } | 152 } |
| 152 | 153 |
| 153 // Callback for handing the outcome of GetTouchDeviceStatus(). | 154 // Callback for handing the outcome of GetTouchDeviceStatus(). |
| 154 // | 155 // |
| 155 // Appends the collected log to the SystemLogsResponse map. Also goes on to | 156 // Appends the collected log to the SystemLogsResponse map. Also goes on to |
| 156 // collect touch event logs. | 157 // collect touch event logs. |
| 157 void OnStatusLogCollected(scoped_ptr<system_logs::SystemLogsResponse> response, | 158 void OnStatusLogCollected( |
| 158 const system_logs::SysLogsSourceCallback& callback, | 159 std::unique_ptr<system_logs::SystemLogsResponse> response, |
| 159 scoped_ptr<std::string> log) { | 160 const system_logs::SysLogsSourceCallback& callback, |
| 161 std::unique_ptr<std::string> log) { |
| 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 162 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 161 (*response)[kDeviceStatusLogDataKey] = *log; | 163 (*response)[kDeviceStatusLogDataKey] = *log; |
| 162 | 164 |
| 163 // Collect touch event logs. | 165 // Collect touch event logs. |
| 164 const base::FilePath kBaseLogPath(kTouchEventLogDir); | 166 const base::FilePath kBaseLogPath(kTouchEventLogDir); |
| 165 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchEventLog( | 167 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchEventLog( |
| 166 kBaseLogPath, | 168 kBaseLogPath, |
| 167 base::Bind(&OnEventLogCollected, base::Passed(&response), callback)); | 169 base::Bind(&OnEventLogCollected, base::Passed(&response), callback)); |
| 168 } | 170 } |
| 169 | 171 |
| 170 // Collect touch HUD debug logs. This needs to be done on the UI thread. | 172 // Collect touch HUD debug logs. This needs to be done on the UI thread. |
| 171 void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) { | 173 void CollectTouchHudDebugLog(system_logs::SystemLogsResponse* response) { |
| 172 scoped_ptr<base::DictionaryValue> dictionary = | 174 std::unique_ptr<base::DictionaryValue> dictionary = |
| 173 ash::TouchHudDebug::GetAllAsDictionary(); | 175 ash::TouchHudDebug::GetAllAsDictionary(); |
| 174 if (!dictionary->empty()) { | 176 if (!dictionary->empty()) { |
| 175 std::string touch_log; | 177 std::string touch_log; |
| 176 JSONStringValueSerializer json(&touch_log); | 178 JSONStringValueSerializer json(&touch_log); |
| 177 json.set_pretty_print(true); | 179 json.set_pretty_print(true); |
| 178 if (json.Serialize(*dictionary) && !touch_log.empty()) | 180 if (json.Serialize(*dictionary) && !touch_log.empty()) |
| 179 (*response)[kHUDLogDataKey] = touch_log; | 181 (*response)[kHUDLogDataKey] = touch_log; |
| 180 } | 182 } |
| 181 } | 183 } |
| 182 | 184 |
| 183 } // namespace | 185 } // namespace |
| 184 | 186 |
| 185 namespace system_logs { | 187 namespace system_logs { |
| 186 | 188 |
| 187 void TouchLogSource::Fetch(const SysLogsSourceCallback& callback) { | 189 void TouchLogSource::Fetch(const SysLogsSourceCallback& callback) { |
| 188 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 189 DCHECK(!callback.is_null()); | 191 DCHECK(!callback.is_null()); |
| 190 | 192 |
| 191 scoped_ptr<SystemLogsResponse> response(new SystemLogsResponse); | 193 std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse); |
| 192 CollectTouchHudDebugLog(response.get()); | 194 CollectTouchHudDebugLog(response.get()); |
| 193 | 195 |
| 194 // Collect touch device status logs. | 196 // Collect touch device status logs. |
| 195 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchDeviceStatus( | 197 ui::OzonePlatform::GetInstance()->GetInputController()->GetTouchDeviceStatus( |
| 196 base::Bind(&OnStatusLogCollected, base::Passed(&response), callback)); | 198 base::Bind(&OnStatusLogCollected, base::Passed(&response), callback)); |
| 197 } | 199 } |
| 198 | 200 |
| 199 } // namespace system_logs | 201 } // namespace system_logs |
| OLD | NEW |