Chromium Code Reviews| 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/system_logs/debugd_log_source.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/system_logs/system_logs_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 // DebugDaemonLogSource* fetcher = new DebugDaemonLogSource(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 DebugDaemonLogSource::DebugDaemonLogSource() | |
| 36 : response_(new SystemLogsResponse()), num_pending_requests_(0), | |
|
satorux1
2012/08/14 05:51:52
please move num_pending_requests_(0) to the next l
tudalex(Chromium)
2012/08/15 01:54:33
Done.
| |
| 37 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {} | |
|
satorux1
2012/08/14 05:51:52
please also initialize request_(NULL).
Be sure to
tudalex(Chromium)
2012/08/15 01:54:33
Request is a callback and can't initialize it to n
satorux1
2012/08/15 02:11:32
Sorry, I thought request_ was just a pointer. If
satorux1
2012/08/15 02:22:43
or just callback_
tudalex(Chromium)
2012/08/15 17:20:21
Done. Renamed everything with callback_. Also did
| |
| 38 | |
| 39 DebugDaemonLogSource::~DebugDaemonLogSource() {} | |
| 40 | |
| 41 void DebugDaemonLogSource::Fetch(const SysLogsFetcherCallback& request) { | |
| 42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
|
satorux1
2012/08/14 05:51:52
DCHECK(!request_);
tudalex(Chromium)
2012/08/15 01:54:33
Says error: no match for 'operator!' in '!request'
satorux1
2012/08/15 22:01:09
DCHECK(callback.is_null());
tudalex(Chromium)
2012/08/16 01:08:57
Done.
| |
| 43 | |
| 44 request_ = request; | |
| 45 DebugDaemonClient* client = DBusThreadManager::Get()->GetDebugDaemonClient(); | |
| 46 | |
| 47 client->GetRoutes(true, // Numeric | |
| 48 false, // No IPv6 | |
| 49 base::Bind(&DebugDaemonLogSource::OnGetRoutes, | |
| 50 weak_ptr_factory_.GetWeakPtr())); | |
| 51 ++num_pending_requests_; | |
| 52 client->GetNetworkStatus(base::Bind(&DebugDaemonLogSource::OnGetNetworkStatus, | |
| 53 weak_ptr_factory_.GetWeakPtr())); | |
| 54 ++num_pending_requests_; | |
| 55 client->GetModemStatus(base::Bind(&DebugDaemonLogSource::OnGetModemStatus, | |
| 56 weak_ptr_factory_.GetWeakPtr())); | |
| 57 ++num_pending_requests_; | |
| 58 client->GetAllLogs(base::Bind(&DebugDaemonLogSource::OnGetLogs, | |
| 59 weak_ptr_factory_.GetWeakPtr())); | |
| 60 ++num_pending_requests_; | |
| 61 } | |
| 62 | |
| 63 void DebugDaemonLogSource::OnGetRoutes(bool succeeded, | |
| 64 const std::vector<std::string>& routes) { | |
| 65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 66 | |
| 67 if (succeeded) | |
| 68 (*response_)["routes"] = JoinString(routes, '\n'); | |
| 69 else | |
| 70 (*response_)["routes"] = kNotAvailable; | |
| 71 RequestCompleted(); | |
| 72 } | |
| 73 | |
| 74 void DebugDaemonLogSource::OnGetNetworkStatus(bool succeeded, | |
| 75 const std::string& status) { | |
| 76 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 77 | |
| 78 if (succeeded) | |
| 79 (*response_)["network-status"] = status; | |
| 80 else | |
| 81 (*response_)["network-status"] = kNotAvailable; | |
| 82 RequestCompleted(); | |
| 83 } | |
| 84 | |
| 85 void DebugDaemonLogSource::OnGetModemStatus(bool succeeded, | |
| 86 const std::string& status) { | |
| 87 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 88 | |
| 89 if (succeeded) | |
| 90 (*response_)["modem-status"] = status; | |
| 91 else | |
| 92 (*response_)["modem-status"] = kNotAvailable; | |
| 93 RequestCompleted(); | |
| 94 } | |
| 95 | |
| 96 void DebugDaemonLogSource::OnGetLogs(bool /* succeeded */, | |
| 97 const std::map<std::string, | |
| 98 std::string>& logs) { | |
| 99 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 100 | |
| 101 // We ignore 'succeeded' for this callback - we want to display as much of the | |
| 102 // debug info as we can even if we failed partway through parsing, and if we | |
| 103 // couldn't fetch any of it, none of the fields will even appear. | |
| 104 for (std::map<std::string, std::string>::const_iterator it = logs.begin(); | |
| 105 it != logs.end(); ++it) | |
| 106 (*response_)[it->first] = it->second; | |
| 107 RequestCompleted(); | |
| 108 } | |
| 109 | |
| 110 void DebugDaemonLogSource::RequestCompleted() { | |
| 111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 112 --num_pending_requests_; | |
| 113 if (num_pending_requests_ > 0) | |
| 114 return; | |
| 115 request_.Run(response_.get()); | |
| 116 } | |
| 117 | |
| 118 } // namespace chromeos | |
| OLD | NEW |