Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Unified Diff: chrome/browser/chromeos/system_logs/single_debug_daemon_log_source.cc

Issue 2955463002: Add log source to read from one DebugDaemon log (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/system_logs/single_debug_daemon_log_source.cc
diff --git a/chrome/browser/chromeos/system_logs/single_debug_daemon_log_source.cc b/chrome/browser/chromeos/system_logs/single_debug_daemon_log_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5dfddefc8429fd999ceb5a449937519bc89df34e
--- /dev/null
+++ b/chrome/browser/chromeos/system_logs/single_debug_daemon_log_source.cc
@@ -0,0 +1,67 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/system_logs/single_debug_daemon_log_source.h"
+
+#include "base/bind.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/debug_daemon_client.h"
+#include "components/feedback/anonymizer_tool.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace system_logs {
+
+namespace {
+
+using SupportedSource = SingleDebugDaemonLogSource::SupportedSource;
+
+// Converts a logs source type to the corresponding file path, relative to the
+// base system log directory path. In the future, if non-file source types are
+// added, this function should return an empty file path.
afakhry 2017/06/22 22:20:58 Copy-and-paste comment. Please modify! :)
Simon Que 2017/06/22 22:38:27 Done.
+std::string GetLogName(SupportedSource source_type) {
+ switch (source_type) {
+ case SupportedSource::kModetest:
+ return "modetest";
+ case SupportedSource::kLsusb:
+ return "lsusb";
+ }
+ NOTREACHED();
+ return "";
+}
+
+} // namespace
+
+SingleDebugDaemonLogSource::SingleDebugDaemonLogSource(
+ SupportedSource source_type)
+ : SystemLogsSource(GetLogName(source_type)), weak_ptr_factory_(this) {}
+
+SingleDebugDaemonLogSource::~SingleDebugDaemonLogSource() {}
+
+void SingleDebugDaemonLogSource::Fetch(const SysLogsSourceCallback& callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ DCHECK(!callback.is_null());
+
+ chromeos::DebugDaemonClient* client =
+ chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
+
+ client->GetLog(source_name(),
afakhry 2017/06/22 22:20:59 I don't see this function belonging to DebugDaemon
Simon Que 2017/06/22 22:38:27 That function is being added in a CL that this one
+ base::Bind(&SingleDebugDaemonLogSource::OnFetchComplete,
+ weak_ptr_factory_.GetWeakPtr(), callback));
+}
+
+void SingleDebugDaemonLogSource::OnFetchComplete(
+ const SysLogsSourceCallback& callback,
+ bool success,
afakhry 2017/06/22 22:20:59 Can you check "success" and add a test for that?
Simon Que 2017/06/22 22:38:27 I can return an empty result on !success, but I do
afakhry 2017/06/22 23:34:15 Forget about this test request. It's not worth it.
+ const std::map<std::string, std::string>& result) const {
+ // |result| and |response| are the same type, but |result| is passed in from
+ // DebugDaemonClient, which does not use the SystemLogsResponse alias.
+ SystemLogsResponse response;
+ feedback::AnonymizerTool anonymizer;
+ for (auto& entry : result)
+ response[entry.first] = anonymizer.Anonymize(entry.second);
afakhry 2017/06/22 22:20:58 Nit: emplace(key, val);
Simon Que 2017/06/22 22:38:27 Done.
+
+ callback.Run(&response);
+}
+
+} // namespace system_logs

Powered by Google App Engine
This is Rietveld 408576698