OLD | NEW |
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 <fcntl.h> | 5 #include <fcntl.h> |
6 #include <unistd.h> | 6 #include <unistd.h> |
7 | 7 |
8 #include "chromeos/dbus/debug_daemon_client.h" | 8 #include "chromeos/dbus/debug_daemon_client.h" |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 writer.AppendFileDescriptor(fd); | 160 writer.AppendFileDescriptor(fd); |
161 | 161 |
162 debugdaemon_proxy_->CallMethod( | 162 debugdaemon_proxy_->CallMethod( |
163 &method_call, | 163 &method_call, |
164 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 164 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
165 base::Bind(&DebugDaemonClientImpl::OnGetDebugLogs, | 165 base::Bind(&DebugDaemonClientImpl::OnGetDebugLogs, |
166 weak_ptr_factory_.GetWeakPtr(), | 166 weak_ptr_factory_.GetWeakPtr(), |
167 callback)); | 167 callback)); |
168 } | 168 } |
169 | 169 |
| 170 virtual void SetDebugMode(const std::string& subsystem, |
| 171 const SetDebugModeCallback& callback) OVERRIDE { |
| 172 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 173 debugd::kSetDebugMode); |
| 174 dbus::MessageWriter writer(&method_call); |
| 175 writer.AppendString(subsystem); |
| 176 debugdaemon_proxy_->CallMethod( |
| 177 &method_call, |
| 178 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 179 base::Bind(&DebugDaemonClientImpl::OnSetDebugMode, |
| 180 weak_ptr_factory_.GetWeakPtr(), |
| 181 callback)); |
| 182 } |
| 183 |
170 virtual void StartSystemTracing() OVERRIDE { | 184 virtual void StartSystemTracing() OVERRIDE { |
171 dbus::MethodCall method_call( | 185 dbus::MethodCall method_call( |
172 debugd::kDebugdInterface, | 186 debugd::kDebugdInterface, |
173 debugd::kSystraceStart); | 187 debugd::kSystraceStart); |
174 dbus::MessageWriter writer(&method_call); | 188 dbus::MessageWriter writer(&method_call); |
175 writer.AppendString("all"); // TODO(sleffler) parameterize category list | 189 writer.AppendString("all"); // TODO(sleffler) parameterize category list |
176 | 190 |
177 DVLOG(1) << "Requesting a systrace start"; | 191 DVLOG(1) << "Requesting a systrace start"; |
178 debugdaemon_proxy_->CallMethod( | 192 debugdaemon_proxy_->CallMethod( |
179 &method_call, | 193 &method_call, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 233 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
220 base::Bind(&DebugDaemonClientImpl::OnRequestStopSystemTracing, | 234 base::Bind(&DebugDaemonClientImpl::OnRequestStopSystemTracing, |
221 weak_ptr_factory_.GetWeakPtr())); | 235 weak_ptr_factory_.GetWeakPtr())); |
222 | 236 |
223 pipe_reader_->CloseWriteFD(); // close our copy of fd after send | 237 pipe_reader_->CloseWriteFD(); // close our copy of fd after send |
224 | 238 |
225 return true; | 239 return true; |
226 } | 240 } |
227 | 241 |
228 private: | 242 private: |
| 243 // Called when a response for GetDebugLogs() is received. |
229 void OnGetDebugLogs(const GetDebugLogsCallback& callback, | 244 void OnGetDebugLogs(const GetDebugLogsCallback& callback, |
230 dbus::Response* response) { | 245 dbus::Response* response) { |
231 if (!response) { | 246 if (!response) { |
232 LOG(ERROR) << "Failed to get debug logs"; | 247 LOG(ERROR) << "Failed to get debug logs"; |
233 callback.Run(false); | 248 callback.Run(false); |
234 return; | 249 return; |
235 } | 250 } |
236 callback.Run(true); | 251 callback.Run(true); |
237 } | 252 } |
238 | 253 |
| 254 // Called when a response for SetDebugMode() is received. |
| 255 void OnSetDebugMode(const SetDebugModeCallback& callback, |
| 256 dbus::Response* response) { |
| 257 if (!response) { |
| 258 LOG(ERROR) << "Failed to change debug mode"; |
| 259 callback.Run(false); |
| 260 } else { |
| 261 callback.Run(true); |
| 262 } |
| 263 } |
| 264 |
239 // Called when a response for StartSystemTracing() is received. | 265 // Called when a response for StartSystemTracing() is received. |
240 void OnStartSystemTracing(dbus::Response* response) { | 266 void OnStartSystemTracing(dbus::Response* response) { |
241 if (!response) { | 267 if (!response) { |
242 LOG(ERROR) << "Failed to request systrace start"; | 268 LOG(ERROR) << "Failed to request systrace start"; |
243 return; | 269 return; |
244 } | 270 } |
245 } | 271 } |
246 | 272 |
247 // Called when a response for RequestStopSystemTracing() is received. | 273 // Called when a response for RequestStopSystemTracing() is received. |
248 void OnRequestStopSystemTracing(dbus::Response* response) { | 274 void OnRequestStopSystemTracing(dbus::Response* response) { |
(...skipping 19 matching lines...) Expand all Loading... |
268 }; | 294 }; |
269 | 295 |
270 // The DebugDaemonClient implementation used on Linux desktop, | 296 // The DebugDaemonClient implementation used on Linux desktop, |
271 // which does nothing. | 297 // which does nothing. |
272 class DebugDaemonClientStubImpl : public DebugDaemonClient { | 298 class DebugDaemonClientStubImpl : public DebugDaemonClient { |
273 // DebugDaemonClient overrides. | 299 // DebugDaemonClient overrides. |
274 virtual void GetDebugLogs(base::PlatformFile file, | 300 virtual void GetDebugLogs(base::PlatformFile file, |
275 const GetDebugLogsCallback& callback) OVERRIDE { | 301 const GetDebugLogsCallback& callback) OVERRIDE { |
276 callback.Run(false); | 302 callback.Run(false); |
277 } | 303 } |
| 304 virtual void SetDebugMode(const std::string& subsystem, |
| 305 const SetDebugModeCallback& callback) OVERRIDE { |
| 306 callback.Run(false); |
| 307 } |
278 virtual void StartSystemTracing() OVERRIDE {} | 308 virtual void StartSystemTracing() OVERRIDE {} |
279 virtual bool RequestStopSystemTracing(const StopSystemTracingCallback& | 309 virtual bool RequestStopSystemTracing(const StopSystemTracingCallback& |
280 callback) OVERRIDE { | 310 callback) OVERRIDE { |
281 std::string no_data; | 311 std::string no_data; |
282 callback.Run(base::RefCountedString::TakeString(&no_data)); | 312 callback.Run(base::RefCountedString::TakeString(&no_data)); |
283 return true; | 313 return true; |
284 } | 314 } |
285 }; | 315 }; |
286 | 316 |
287 DebugDaemonClient::DebugDaemonClient() { | 317 DebugDaemonClient::DebugDaemonClient() { |
(...skipping 11 matching lines...) Expand all Loading... |
299 // static | 329 // static |
300 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, | 330 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, |
301 dbus::Bus* bus) { | 331 dbus::Bus* bus) { |
302 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 332 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
303 return new DebugDaemonClientImpl(bus); | 333 return new DebugDaemonClientImpl(bus); |
304 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 334 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
305 return new DebugDaemonClientStubImpl(); | 335 return new DebugDaemonClientStubImpl(); |
306 } | 336 } |
307 | 337 |
308 } // namespace chromeos | 338 } // namespace chromeos |
OLD | NEW |