| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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/syslogs/debugd_log_fetcher.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/chromeos/syslogs/syslogs_fetcher.h" |
| 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 #include "chromeos/dbus/debug_daemon_client.h" |
| 17 #include "content/public/browser/browser_thread.h" |
| 18 |
| 19 namespace { |
| 20 |
| 21 const char kNotAvailable[] = "<not available>"; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 namespace chromeos { |
| 26 |
| 27 // Fetches logs from the debug daemon over DBus. When all the logs have been |
| 28 // fetched, forwards the results to the supplied Request. Used like: |
| 29 // DebugDaemonLogFetcher* fetcher = new DebugDaemonLogFetcher(request); |
| 30 // fetcher->Fetch(); |
| 31 // Note that you do not need to delete the fetcher; it will delete itself after |
| 32 // Fetch() has forwarded the result to the request handler. |
| 33 |
| 34 |
| 35 DebugDaemonLogFetcher::DebugDaemonLogFetcher() |
| 36 : response_(new SystemLogsResponse()), |
| 37 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {} |
| 38 |
| 39 DebugDaemonLogFetcher::~DebugDaemonLogFetcher() {} |
| 40 |
| 41 void DebugDaemonLogFetcher::Fetch(const SysLogsFetcherCallback& request) { |
| 42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 43 |
| 44 request_ = request; |
| 45 DebugDaemonClient* client = DBusThreadManager::Get()->GetDebugDaemonClient(); |
| 46 pending_requests_ = 4; |
| 47 |
| 48 client->GetRoutes(true, // Numeric |
| 49 false, // No IPv6 |
| 50 base::Bind(&DebugDaemonLogFetcher::GotRoutes, |
| 51 weak_ptr_factory_.GetWeakPtr())); |
| 52 client->GetNetworkStatus(base::Bind(&DebugDaemonLogFetcher::GotNetworkStatus, |
| 53 weak_ptr_factory_.GetWeakPtr())); |
| 54 client->GetModemStatus(base::Bind(&DebugDaemonLogFetcher::GotModemStatus, |
| 55 weak_ptr_factory_.GetWeakPtr())); |
| 56 client->GetAllLogs(base::Bind(&DebugDaemonLogFetcher::GotLogs, |
| 57 weak_ptr_factory_.GetWeakPtr())); |
| 58 } |
| 59 |
| 60 void DebugDaemonLogFetcher::GotRoutes(bool succeeded, |
| 61 const std::vector<std::string>& routes) { |
| 62 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 63 |
| 64 if (succeeded) |
| 65 (*response_)["routes"] = JoinString(routes, '\n'); |
| 66 else |
| 67 (*response_)["routes"] = kNotAvailable; |
| 68 RequestCompleted(); |
| 69 } |
| 70 |
| 71 void DebugDaemonLogFetcher::GotNetworkStatus(bool succeeded, |
| 72 const std::string& status) { |
| 73 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 74 |
| 75 if (succeeded) |
| 76 (*response_)["network-status"] = status; |
| 77 else |
| 78 (*response_)["network-status"] = kNotAvailable; |
| 79 RequestCompleted(); |
| 80 } |
| 81 |
| 82 void DebugDaemonLogFetcher::GotModemStatus(bool succeeded, |
| 83 const std::string& status) { |
| 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 85 |
| 86 if (succeeded) |
| 87 (*response_)["modem-status"] = status; |
| 88 else |
| 89 (*response_)["modem-status"] = kNotAvailable; |
| 90 RequestCompleted(); |
| 91 } |
| 92 |
| 93 void DebugDaemonLogFetcher::GotLogs(bool /* succeeded */, |
| 94 const std::map<std::string, |
| 95 std::string>& logs) { |
| 96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 97 |
| 98 // We ignore 'succeeded' for this callback - we want to display as much of the |
| 99 // debug info as we can even if we failed partway through parsing, and if we |
| 100 // couldn't fetch any of it, none of the fields will even appear. |
| 101 for (std::map<std::string, std::string>::const_iterator it = logs.begin(); |
| 102 it != logs.end(); ++it) |
| 103 (*response_)[it->first] = it->second; |
| 104 RequestCompleted(); |
| 105 } |
| 106 |
| 107 void DebugDaemonLogFetcher::RequestCompleted() { |
| 108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 109 if (--pending_requests_) |
| 110 return; |
| 111 request_.Run(response_); |
| 112 } |
| 113 |
| 114 } // namespace chromeos |
| OLD | NEW |