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

Side by Side Diff: chrome/browser/chromeos/system_logs/debug_daemon_log_source.cc

Issue 11035014: Collect user logs that debugd can not access (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix indent Created 8 years, 1 month 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h" 5 #include "chrome/browser/chromeos/system_logs/debug_daemon_log_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h" 14 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/debug_daemon_client.h" 17 #include "chromeos/dbus/debug_daemon_client.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 19
19 namespace { 20 namespace {
20 21
21 const char kNotAvailable[] = "<not available>"; 22 const char kNotAvailable[] = "<not available>";
22 const char kRoutesKeyName[] = "routes"; 23 const char kRoutesKeyName[] = "routes";
23 const char kNetworkStatusKeyName[] = "network-status"; 24 const char kNetworkStatusKeyName[] = "network-status";
24 const char kModemStatusKeyName[] = "modem-status"; 25 const char kModemStatusKeyName[] = "modem-status";
26 const char kUserLogFileKeyName[] = "user_log_files";
25 } // namespace 27 } // namespace
26 28
27 namespace chromeos { 29 namespace chromeos {
28 30
29 // Fetches logs from the debug daemon over DBus. When all the logs have been 31 // 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: 32 // fetched, forwards the results to the supplied Request. Used like:
31 // DebugDaemonLogSource* fetcher = new DebugDaemonLogSource(request); 33 // DebugDaemonLogSource* fetcher = new DebugDaemonLogSource(request);
32 // fetcher->Fetch(); 34 // fetcher->Fetch();
33 // Note that you do not need to delete the fetcher; it will delete itself after 35 // 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. 36 // Fetch() has forwarded the result to the request handler.
(...skipping 21 matching lines...) Expand all
56 ++num_pending_requests_; 58 ++num_pending_requests_;
57 client->GetNetworkStatus(base::Bind(&DebugDaemonLogSource::OnGetNetworkStatus, 59 client->GetNetworkStatus(base::Bind(&DebugDaemonLogSource::OnGetNetworkStatus,
58 weak_ptr_factory_.GetWeakPtr())); 60 weak_ptr_factory_.GetWeakPtr()));
59 ++num_pending_requests_; 61 ++num_pending_requests_;
60 client->GetModemStatus(base::Bind(&DebugDaemonLogSource::OnGetModemStatus, 62 client->GetModemStatus(base::Bind(&DebugDaemonLogSource::OnGetModemStatus,
61 weak_ptr_factory_.GetWeakPtr())); 63 weak_ptr_factory_.GetWeakPtr()));
62 ++num_pending_requests_; 64 ++num_pending_requests_;
63 client->GetAllLogs(base::Bind(&DebugDaemonLogSource::OnGetLogs, 65 client->GetAllLogs(base::Bind(&DebugDaemonLogSource::OnGetLogs,
64 weak_ptr_factory_.GetWeakPtr())); 66 weak_ptr_factory_.GetWeakPtr()));
65 ++num_pending_requests_; 67 ++num_pending_requests_;
68 client->GetUserLogFiles(base::Bind(&DebugDaemonLogSource::OnGetUserLogFiles,
69 weak_ptr_factory_.GetWeakPtr()));
70 ++num_pending_requests_;
66 } 71 }
67 72
68 void DebugDaemonLogSource::OnGetRoutes(bool succeeded, 73 void DebugDaemonLogSource::OnGetRoutes(bool succeeded,
69 const std::vector<std::string>& routes) { 74 const std::vector<std::string>& routes) {
70 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
71 76
72 if (succeeded) 77 if (succeeded)
73 (*response_)[kRoutesKeyName] = JoinString(routes, '\n'); 78 (*response_)[kRoutesKeyName] = JoinString(routes, '\n');
74 else 79 else
75 (*response_)[kRoutesKeyName] = kNotAvailable; 80 (*response_)[kRoutesKeyName] = kNotAvailable;
(...skipping 16 matching lines...) Expand all
92 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 97 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
93 98
94 if (succeeded) 99 if (succeeded)
95 (*response_)[kModemStatusKeyName] = status; 100 (*response_)[kModemStatusKeyName] = status;
96 else 101 else
97 (*response_)[kModemStatusKeyName] = kNotAvailable; 102 (*response_)[kModemStatusKeyName] = kNotAvailable;
98 RequestCompleted(); 103 RequestCompleted();
99 } 104 }
100 105
101 void DebugDaemonLogSource::OnGetLogs(bool /* succeeded */, 106 void DebugDaemonLogSource::OnGetLogs(bool /* succeeded */,
102 const std::map<std::string, 107 const KeyValueMap& logs) {
103 std::string>& logs) {
104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
105 109
106 // We ignore 'succeeded' for this callback - we want to display as much of the 110 // 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 111 // 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. 112 // couldn't fetch any of it, none of the fields will even appear.
109 response_->insert(logs.begin(), logs.end()); 113 response_->insert(logs.begin(), logs.end());
110 RequestCompleted(); 114 RequestCompleted();
111 } 115 }
112 116
117 void DebugDaemonLogSource::OnGetUserLogFiles(
118 bool succeeded,
119 const KeyValueMap& user_log_files) {
120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
121 if (succeeded) {
122 content::BrowserThread::PostBlockingPoolTaskAndReply(
123 FROM_HERE,
124 base::Bind(
125 &DebugDaemonLogSource::ReadUserLogFiles,
126 weak_ptr_factory_.GetWeakPtr(),
127 user_log_files),
128 base::Bind(&DebugDaemonLogSource::RequestCompleted,
129 weak_ptr_factory_.GetWeakPtr()));
130 } else {
131 (*response_)[kUserLogFileKeyName] = kNotAvailable;
132 RequestCompleted();
133 }
134 }
135
136 void DebugDaemonLogSource::ReadUserLogFiles(const KeyValueMap& user_log_files) {
137 for (KeyValueMap::const_iterator it = user_log_files.begin();
138 it != user_log_files.end();
139 ++it) {
140 std::string value;
141 bool read_success = file_util::ReadFileToString(
142 FilePath(it->second), &value);
143 if (read_success && !value.empty())
144 (*response_)[it->first] = value;
145 else
146 (*response_)[it->second] = kNotAvailable;
147 }
148 }
149
113 void DebugDaemonLogSource::RequestCompleted() { 150 void DebugDaemonLogSource::RequestCompleted() {
114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 151 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
115 DCHECK(!callback_.is_null()); 152 DCHECK(!callback_.is_null());
116 153
117 --num_pending_requests_; 154 --num_pending_requests_;
118 if (num_pending_requests_ > 0) 155 if (num_pending_requests_ > 0)
119 return; 156 return;
120 callback_.Run(response_.get()); 157 callback_.Run(response_.get());
121 } 158 }
122 159
123 } // namespace chromeos 160 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698