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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 file_descriptor), | 299 file_descriptor), |
300 base::Bind(&DebugDaemonClientImpl::OnCheckValidityRequestStopSystem, | 300 base::Bind(&DebugDaemonClientImpl::OnCheckValidityRequestStopSystem, |
301 weak_ptr_factory_.GetWeakPtr(), | 301 weak_ptr_factory_.GetWeakPtr(), |
302 base::Owned(file_descriptor), | 302 base::Owned(file_descriptor), |
303 callback), | 303 callback), |
304 false); | 304 false); |
305 | 305 |
306 return true; | 306 return true; |
307 } | 307 } |
308 | 308 |
| 309 virtual void TestICMP(const std::string& ip_address, |
| 310 const TestICMPCallback& callback) OVERRIDE { |
| 311 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 312 debugd::kTestICMP); |
| 313 dbus::MessageWriter writer(&method_call); |
| 314 writer.AppendString(ip_address); |
| 315 debugdaemon_proxy_->CallMethod( |
| 316 &method_call, |
| 317 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 318 base::Bind(&DebugDaemonClientImpl::OnTestICMP, |
| 319 weak_ptr_factory_.GetWeakPtr(), |
| 320 callback)); |
| 321 } |
| 322 |
309 private: | 323 private: |
310 // Called to check descriptor validity on a thread where i/o is permitted. | 324 // Called to check descriptor validity on a thread where i/o is permitted. |
311 static void CheckValidity(dbus::FileDescriptor* file_descriptor) { | 325 static void CheckValidity(dbus::FileDescriptor* file_descriptor) { |
312 file_descriptor->CheckValidity(); | 326 file_descriptor->CheckValidity(); |
313 } | 327 } |
314 | 328 |
315 // Called when a CheckValidity response is received. | 329 // Called when a CheckValidity response is received. |
316 void OnCheckValidityGetDebugLogs(dbus::FileDescriptor* file_descriptor, | 330 void OnCheckValidityGetDebugLogs(dbus::FileDescriptor* file_descriptor, |
317 const GetDebugLogsCallback& callback) { | 331 const GetDebugLogsCallback& callback) { |
318 // Issue the dbus request to get debug logs. | 332 // Issue the dbus request to get debug logs. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 | 465 |
452 // Called when a response for RequestStopSystemTracing() is received. | 466 // Called when a response for RequestStopSystemTracing() is received. |
453 void OnRequestStopSystemTracing(dbus::Response* response) { | 467 void OnRequestStopSystemTracing(dbus::Response* response) { |
454 if (!response) { | 468 if (!response) { |
455 LOG(ERROR) << "Failed to request systrace stop"; | 469 LOG(ERROR) << "Failed to request systrace stop"; |
456 pipe_reader_->OnDataReady(-1); // terminate data stream | 470 pipe_reader_->OnDataReady(-1); // terminate data stream |
457 } | 471 } |
458 // NB: requester is signaled when i/o completes | 472 // NB: requester is signaled when i/o completes |
459 } | 473 } |
460 | 474 |
| 475 void OnTestICMP(const TestICMPCallback& callback, dbus::Response* response) { |
| 476 std::string status; |
| 477 if (response && dbus::MessageReader(response).PopString(&status)) |
| 478 callback.Run(true, status); |
| 479 else |
| 480 callback.Run(false, ""); |
| 481 } |
| 482 |
461 // Called when pipe i/o completes; pass data on and delete the instance. | 483 // Called when pipe i/o completes; pass data on and delete the instance. |
462 void OnIOComplete() { | 484 void OnIOComplete() { |
463 callback_.Run(base::RefCountedString::TakeString(pipe_reader_->data())); | 485 callback_.Run(base::RefCountedString::TakeString(pipe_reader_->data())); |
464 pipe_reader_.reset(); | 486 pipe_reader_.reset(); |
465 } | 487 } |
466 | 488 |
467 dbus::ObjectProxy* debugdaemon_proxy_; | 489 dbus::ObjectProxy* debugdaemon_proxy_; |
468 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; | 490 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; |
469 scoped_ptr<PipeReader> pipe_reader_; | 491 scoped_ptr<PipeReader> pipe_reader_; |
470 StopSystemTracingCallback callback_; | 492 StopSystemTracingCallback callback_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 callback.Run(false, ""); | 527 callback.Run(false, ""); |
506 } | 528 } |
507 virtual void GetNetworkInterfaces( | 529 virtual void GetNetworkInterfaces( |
508 const GetNetworkInterfacesCallback& callback) OVERRIDE { | 530 const GetNetworkInterfacesCallback& callback) OVERRIDE { |
509 callback.Run(false, ""); | 531 callback.Run(false, ""); |
510 } | 532 } |
511 virtual void GetAllLogs(const GetAllLogsCallback& callback) OVERRIDE { | 533 virtual void GetAllLogs(const GetAllLogsCallback& callback) OVERRIDE { |
512 std::map<std::string, std::string> empty; | 534 std::map<std::string, std::string> empty; |
513 callback.Run(false, empty); | 535 callback.Run(false, empty); |
514 } | 536 } |
| 537 |
| 538 virtual void TestICMP(const std::string& ip_address, |
| 539 const TestICMPCallback& callback) OVERRIDE { |
| 540 callback.Run(false, ""); |
| 541 } |
515 }; | 542 }; |
516 | 543 |
517 DebugDaemonClient::DebugDaemonClient() { | 544 DebugDaemonClient::DebugDaemonClient() { |
518 } | 545 } |
519 | 546 |
520 DebugDaemonClient::~DebugDaemonClient() { | 547 DebugDaemonClient::~DebugDaemonClient() { |
521 } | 548 } |
522 | 549 |
523 // static | 550 // static |
524 DebugDaemonClient::StopSystemTracingCallback | 551 DebugDaemonClient::StopSystemTracingCallback |
525 DebugDaemonClient::EmptyStopSystemTracingCallback() { | 552 DebugDaemonClient::EmptyStopSystemTracingCallback() { |
526 return base::Bind(&EmptyStopSystemTracingCallbackBody); | 553 return base::Bind(&EmptyStopSystemTracingCallbackBody); |
527 } | 554 } |
528 | 555 |
529 // static | 556 // static |
530 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, | 557 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, |
531 dbus::Bus* bus) { | 558 dbus::Bus* bus) { |
532 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 559 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
533 return new DebugDaemonClientImpl(bus); | 560 return new DebugDaemonClientImpl(bus); |
534 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 561 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
535 return new DebugDaemonClientStubImpl(); | 562 return new DebugDaemonClientStubImpl(); |
536 } | 563 } |
537 | 564 |
538 } // namespace chromeos | 565 } // namespace chromeos |
OLD | NEW |