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

Unified Diff: chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc

Issue 10827130: Refactoring the SysInfoProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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/syslogs/debugd_log_fetcher.cc
diff --git a/chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc b/chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fe76584f658192e743517b6022e186aa6e2835e3
--- /dev/null
+++ b/chrome/browser/chromeos/syslogs/debugd_log_fetcher.cc
@@ -0,0 +1,114 @@
+// Copyright (c) 2012 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/syslogs/debugd_log_fetcher.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/string_util.h"
+#include "chrome/browser/chromeos/syslogs/syslogs_fetcher.h"
+#include "chrome/common/chrome_switches.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/debug_daemon_client.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace {
+
+const char kNotAvailable[] = "<not available>";
+
+} // namespace
+
+namespace chromeos {
+
+// Fetches logs from the debug daemon over DBus. When all the logs have been
+// fetched, forwards the results to the supplied Request. Used like:
+// DebugDaemonLogFetcher* fetcher = new DebugDaemonLogFetcher(request);
+// fetcher->Fetch();
+// Note that you do not need to delete the fetcher; it will delete itself after
+// Fetch() has forwarded the result to the request handler.
+
+
+DebugDaemonLogFetcher::DebugDaemonLogFetcher()
+ : response_(new SystemLogsResponse()),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
+
+DebugDaemonLogFetcher::~DebugDaemonLogFetcher() {}
+
+void DebugDaemonLogFetcher::Fetch(const SysLogsFetcherCallback& request) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ request_ = request;
+ DebugDaemonClient* client = DBusThreadManager::Get()->GetDebugDaemonClient();
+ pending_requests_ = 4;
+
+ client->GetRoutes(true, // Numeric
+ false, // No IPv6
+ base::Bind(&DebugDaemonLogFetcher::GotRoutes,
+ weak_ptr_factory_.GetWeakPtr()));
+ client->GetNetworkStatus(base::Bind(&DebugDaemonLogFetcher::GotNetworkStatus,
+ weak_ptr_factory_.GetWeakPtr()));
+ client->GetModemStatus(base::Bind(&DebugDaemonLogFetcher::GotModemStatus,
+ weak_ptr_factory_.GetWeakPtr()));
+ client->GetAllLogs(base::Bind(&DebugDaemonLogFetcher::GotLogs,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void DebugDaemonLogFetcher::GotRoutes(bool succeeded,
+ const std::vector<std::string>& routes) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ if (succeeded)
+ (*response_)["routes"] = JoinString(routes, '\n');
+ else
+ (*response_)["routes"] = kNotAvailable;
+ RequestCompleted();
+}
+
+void DebugDaemonLogFetcher::GotNetworkStatus(bool succeeded,
+ const std::string& status) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ if (succeeded)
+ (*response_)["network-status"] = status;
+ else
+ (*response_)["network-status"] = kNotAvailable;
+ RequestCompleted();
+}
+
+void DebugDaemonLogFetcher::GotModemStatus(bool succeeded,
+ const std::string& status) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ if (succeeded)
+ (*response_)["modem-status"] = status;
+ else
+ (*response_)["modem-status"] = kNotAvailable;
+ RequestCompleted();
+}
+
+void DebugDaemonLogFetcher::GotLogs(bool /* succeeded */,
+ const std::map<std::string,
+ std::string>& logs) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // We ignore 'succeeded' for this callback - we want to display as much of the
+ // debug info as we can even if we failed partway through parsing, and if we
+ // couldn't fetch any of it, none of the fields will even appear.
+ for (std::map<std::string, std::string>::const_iterator it = logs.begin();
+ it != logs.end(); ++it)
+ (*response_)[it->first] = it->second;
+ RequestCompleted();
+}
+
+void DebugDaemonLogFetcher::RequestCompleted() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ if (--pending_requests_)
+ return;
+ request_.Run(response_);
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698