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

Side by Side Diff: chrome/browser/chromeos/system_logs/debugd_log_source.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 unified diff | Download patch
OLDNEW
(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()),
satorux1 2012/08/13 18:29:03 where will it be deleted?
tudalex(Chromium) 2012/08/14 03:24:00 Made it a scoped_ptr so it is going to be deleted
37 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
38
39 DebugDaemonLogSource::~DebugDaemonLogSource() {}
40
41 void DebugDaemonLogSource::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;
satorux1 2012/08/13 18:29:03 4 looks cryptic. please define a constant with som
rkc 2012/08/13 18:50:14 Actually, this should get initialized to 0, then i
tudalex(Chromium) 2012/08/14 03:24:00 Done.
47
48 client->GetRoutes(true, // Numeric
49 false, // No IPv6
50 base::Bind(&DebugDaemonLogSource::GotRoutes,
51 weak_ptr_factory_.GetWeakPtr()));
52 client->GetNetworkStatus(base::Bind(&DebugDaemonLogSource::GotNetworkStatus,
53 weak_ptr_factory_.GetWeakPtr()));
54 client->GetModemStatus(base::Bind(&DebugDaemonLogSource::GotModemStatus,
55 weak_ptr_factory_.GetWeakPtr()));
56 client->GetAllLogs(base::Bind(&DebugDaemonLogSource::GotLogs,
57 weak_ptr_factory_.GetWeakPtr()));
58 }
59
60 void DebugDaemonLogSource::GotRoutes(bool succeeded,
satorux1 2012/08/13 18:29:03 OnGetRoutes() would be better. this way, it's easi
tudalex(Chromium) 2012/08/14 03:24:00 Done.
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 DebugDaemonLogSource::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 DebugDaemonLogSource::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 DebugDaemonLogSource::GotLogs(bool /* succeeded */,
94 const std::map<std::string,
satorux1 2012/08/13 18:29:03 indentation
tudalex(Chromium) 2012/08/14 03:24:00 Done.
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 DebugDaemonLogSource::RequestCompleted() {
108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
109 if (--pending_requests_)
110 return;
111 request_.Run(response_);
112 }
113
114 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698