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

Side by Side Diff: chrome/browser/chromeos/system_logs/debug_daemon_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/debug_daemon_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 const char kRoutesKeyName[] = "routes";
23 const char kNetworkStatusKeyName[] = "network-status";
24 const char kModemStatusKeyName[] = "modem-status";
25 } // namespace
26
27 namespace chromeos {
28
29 // Fetches logs from the debug daemon over DBus. When all the logs have been
30 // fetched, forwards the results to the supplied Request. Used like:
31 // DebugDaemonLogSource* fetcher = new DebugDaemonLogSource(request);
32 // fetcher->Fetch();
33 // Note that you do not need to delete the fetcher; it will delete itself after
34 // Fetch() has forwarded the result to the request handler.
35
36
37 DebugDaemonLogSource::DebugDaemonLogSource()
38 : response_(new SystemLogsResponse()),
39 num_pending_requests_(0),
40 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {}
41
42 DebugDaemonLogSource::~DebugDaemonLogSource() {}
43
44 void DebugDaemonLogSource::Fetch(const SysLogsSourceCallback& callback) {
45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
46 DCHECK(!callback.is_null());
47 DCHECK(callback_.is_null());
48
49 callback_ = callback;
50 DebugDaemonClient* client = DBusThreadManager::Get()->GetDebugDaemonClient();
51
52 client->GetRoutes(true, // Numeric
53 false, // No IPv6
54 base::Bind(&DebugDaemonLogSource::OnGetRoutes,
55 weak_ptr_factory_.GetWeakPtr()));
56 ++num_pending_requests_;
57 client->GetNetworkStatus(base::Bind(&DebugDaemonLogSource::OnGetNetworkStatus,
58 weak_ptr_factory_.GetWeakPtr()));
59 ++num_pending_requests_;
60 client->GetModemStatus(base::Bind(&DebugDaemonLogSource::OnGetModemStatus,
61 weak_ptr_factory_.GetWeakPtr()));
62 ++num_pending_requests_;
63 client->GetAllLogs(base::Bind(&DebugDaemonLogSource::OnGetLogs,
64 weak_ptr_factory_.GetWeakPtr()));
65 ++num_pending_requests_;
66 }
67
68 void DebugDaemonLogSource::OnGetRoutes(bool succeeded,
69 const std::vector<std::string>& routes) {
70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
71
72 if (succeeded)
73 (*response_)[kRoutesKeyName] = JoinString(routes, '\n');
74 else
75 (*response_)[kRoutesKeyName] = kNotAvailable;
76 RequestCompleted();
77 }
78
79 void DebugDaemonLogSource::OnGetNetworkStatus(bool succeeded,
80 const std::string& status) {
81 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
82
83 if (succeeded)
84 (*response_)[kNetworkStatusKeyName] = status;
85 else
86 (*response_)[kNetworkStatusKeyName] = kNotAvailable;
87 RequestCompleted();
88 }
89
90 void DebugDaemonLogSource::OnGetModemStatus(bool succeeded,
91 const std::string& status) {
92 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
93
94 if (succeeded)
95 (*response_)[kModemStatusKeyName] = status;
96 else
97 (*response_)[kModemStatusKeyName] = kNotAvailable;
98 RequestCompleted();
99 }
100
101 void DebugDaemonLogSource::OnGetLogs(bool /* succeeded */,
102 const std::map<std::string,
103 std::string>& logs) {
104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
105
106 // We ignore 'succeeded' for this callback - we want to display as much of the
107 // debug info as we can even if we failed partway through parsing, and if we
108 // couldn't fetch any of it, none of the fields will even appear.
109 response_->insert(logs.begin(), logs.end());
110 RequestCompleted();
111 }
112
113 void DebugDaemonLogSource::RequestCompleted() {
114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
115 DCHECK(!callback_.is_null());
116
117 --num_pending_requests_;
118 if (num_pending_requests_ > 0)
119 return;
120 callback_.Run(response_.get());
121 }
122
123 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698