OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/system_logs/single_debug_daemon_log_source.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/debug_daemon_client.h" |
| 10 #include "components/feedback/anonymizer_tool.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 |
| 13 namespace system_logs { |
| 14 |
| 15 namespace { |
| 16 |
| 17 using SupportedSource = SingleDebugDaemonLogSource::SupportedSource; |
| 18 |
| 19 // Converts a logs source type to the corresponding debugd log name. |
| 20 std::string GetLogName(SupportedSource source_type) { |
| 21 switch (source_type) { |
| 22 case SupportedSource::kModetest: |
| 23 return "modetest"; |
| 24 case SupportedSource::kLsusb: |
| 25 return "lsusb"; |
| 26 } |
| 27 NOTREACHED(); |
| 28 return ""; |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 33 SingleDebugDaemonLogSource::SingleDebugDaemonLogSource( |
| 34 SupportedSource source_type) |
| 35 : SystemLogsSource(GetLogName(source_type)), weak_ptr_factory_(this) {} |
| 36 |
| 37 SingleDebugDaemonLogSource::~SingleDebugDaemonLogSource() {} |
| 38 |
| 39 void SingleDebugDaemonLogSource::Fetch(const SysLogsSourceCallback& callback) { |
| 40 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 41 DCHECK(!callback.is_null()); |
| 42 |
| 43 chromeos::DebugDaemonClient* client = |
| 44 chromeos::DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 45 |
| 46 client->GetLog( |
| 47 source_name(), |
| 48 base::Bind(&SingleDebugDaemonLogSource::OnFetchComplete, |
| 49 weak_ptr_factory_.GetWeakPtr(), source_name(), callback)); |
| 50 } |
| 51 |
| 52 void SingleDebugDaemonLogSource::OnFetchComplete( |
| 53 const std::string& log_name, |
| 54 const SysLogsSourceCallback& callback, |
| 55 bool success, |
| 56 const std::string& result) const { |
| 57 // |result| and |response| are the same type, but |result| is passed in from |
| 58 // DebugDaemonClient, which does not use the SystemLogsResponse alias. |
| 59 SystemLogsResponse response; |
| 60 // Return an empty result if the call to GetLog() failed. |
| 61 std::string final_result; |
| 62 if (success) |
| 63 response.emplace(log_name, feedback::AnonymizerTool().Anonymize(result)); |
| 64 |
| 65 callback.Run(&response); |
| 66 } |
| 67 |
| 68 } // namespace system_logs |
OLD | NEW |