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

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()),
37 num_pending_requests_(0),
38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
39
40 DebugDaemonLogSource::~DebugDaemonLogSource() {}
41
42 void DebugDaemonLogSource::Fetch(const SysLogsFetcherCallback& callback) {
43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
44 DCHECK(!callback.is_null());
satorux1 2012/08/16 10:50:57 might also want to add DCHECK(callback_.is_null()
tudalex(Chromium) 2012/08/16 22:33:03 Done.
45
46 callback_ = callback;
47 DebugDaemonClient* client = DBusThreadManager::Get()->GetDebugDaemonClient();
48
49 client->GetRoutes(true, // Numeric
50 false, // No IPv6
51 base::Bind(&DebugDaemonLogSource::OnGetRoutes,
52 weak_ptr_factory_.GetWeakPtr()));
53 ++num_pending_requests_;
54 client->GetNetworkStatus(base::Bind(&DebugDaemonLogSource::OnGetNetworkStatus,
55 weak_ptr_factory_.GetWeakPtr()));
56 ++num_pending_requests_;
57 client->GetModemStatus(base::Bind(&DebugDaemonLogSource::OnGetModemStatus,
58 weak_ptr_factory_.GetWeakPtr()));
59 ++num_pending_requests_;
60 client->GetAllLogs(base::Bind(&DebugDaemonLogSource::OnGetLogs,
61 weak_ptr_factory_.GetWeakPtr()));
62 ++num_pending_requests_;
63 }
64
65 void DebugDaemonLogSource::OnGetRoutes(bool succeeded,
66 const std::vector<std::string>& routes) {
67 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
68
69 if (succeeded)
70 (*response_)["routes"] = JoinString(routes, '\n');
71 else
72 (*response_)["routes"] = kNotAvailable;
73 RequestCompleted();
74 }
75
76 void DebugDaemonLogSource::OnGetNetworkStatus(bool succeeded,
77 const std::string& status) {
78 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
79
80 if (succeeded)
81 (*response_)["network-status"] = status;
82 else
83 (*response_)["network-status"] = kNotAvailable;
84 RequestCompleted();
85 }
86
87 void DebugDaemonLogSource::OnGetModemStatus(bool succeeded,
88 const std::string& status) {
89 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
90
91 if (succeeded)
92 (*response_)["modem-status"] = status;
93 else
94 (*response_)["modem-status"] = kNotAvailable;
95 RequestCompleted();
96 }
97
98 void DebugDaemonLogSource::OnGetLogs(bool /* succeeded */,
99 const std::map<std::string,
100 std::string>& logs) {
101 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
102
103 // We ignore 'succeeded' for this callback - we want to display as much of the
104 // debug info as we can even if we failed partway through parsing, and if we
105 // couldn't fetch any of it, none of the fields will even appear.
106 for (std::map<std::string, std::string>::const_iterator it = logs.begin();
107 it != logs.end(); ++it)
108 (*response_)[it->first] = it->second;
109 RequestCompleted();
110 }
111
112 void DebugDaemonLogSource::RequestCompleted() {
113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
114 DCHECK(!callback_.is_null());
115
116 --num_pending_requests_;
117 if (num_pending_requests_ > 0)
118 return;
119 callback_.Run(response_.get());
120 }
121
122 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698