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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 dbus::MessageWriter writer(&method_call); | 339 dbus::MessageWriter writer(&method_call); |
340 writer.AppendString(ip_address); | 340 writer.AppendString(ip_address); |
341 debugdaemon_proxy_->CallMethod( | 341 debugdaemon_proxy_->CallMethod( |
342 &method_call, | 342 &method_call, |
343 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 343 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
344 base::Bind(&DebugDaemonClientImpl::OnTestICMP, | 344 base::Bind(&DebugDaemonClientImpl::OnTestICMP, |
345 weak_ptr_factory_.GetWeakPtr(), | 345 weak_ptr_factory_.GetWeakPtr(), |
346 callback)); | 346 callback)); |
347 } | 347 } |
348 | 348 |
| 349 virtual void TestICMPWithOptions( |
| 350 const std::string& ip_address, |
| 351 const std::map<std::string, std::string>& options, |
| 352 const TestICMPCallback& callback) OVERRIDE { |
| 353 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 354 debugd::kTestICMPWithOptions); |
| 355 dbus::MessageWriter writer(&method_call); |
| 356 dbus::MessageWriter sub_writer(NULL); |
| 357 dbus::MessageWriter elem_writer(NULL); |
| 358 |
| 359 // Write the host. |
| 360 writer.AppendString(ip_address); |
| 361 |
| 362 // Write the options. |
| 363 writer.OpenArray("{ss}", &sub_writer); |
| 364 std::map<std::string, std::string>::const_iterator it; |
| 365 for (it = options.begin(); it != options.end(); ++it) { |
| 366 sub_writer.OpenDictEntry(&elem_writer); |
| 367 elem_writer.AppendString(it->first); |
| 368 elem_writer.AppendString(it->second); |
| 369 sub_writer.CloseContainer(&elem_writer); |
| 370 } |
| 371 writer.CloseContainer(&sub_writer); |
| 372 |
| 373 // Call the function. |
| 374 debugdaemon_proxy_->CallMethod( |
| 375 &method_call, |
| 376 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 377 base::Bind(&DebugDaemonClientImpl::OnTestICMP, |
| 378 weak_ptr_factory_.GetWeakPtr(), |
| 379 callback)); |
| 380 } |
| 381 |
349 private: | 382 private: |
350 // Called to check descriptor validity on a thread where i/o is permitted. | 383 // Called to check descriptor validity on a thread where i/o is permitted. |
351 static void CheckValidity(dbus::FileDescriptor* file_descriptor) { | 384 static void CheckValidity(dbus::FileDescriptor* file_descriptor) { |
352 file_descriptor->CheckValidity(); | 385 file_descriptor->CheckValidity(); |
353 } | 386 } |
354 | 387 |
355 // Called when a CheckValidity response is received. | 388 // Called when a CheckValidity response is received. |
356 void OnCheckValidityGetDebugLogs(dbus::FileDescriptor* file_descriptor, | 389 void OnCheckValidityGetDebugLogs(dbus::FileDescriptor* file_descriptor, |
357 const GetDebugLogsCallback& callback) { | 390 const GetDebugLogsCallback& callback) { |
358 // Issue the dbus request to get debug logs. | 391 // Issue the dbus request to get debug logs. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 virtual bool RequestStopSystemTracing(const StopSystemTracingCallback& | 599 virtual bool RequestStopSystemTracing(const StopSystemTracingCallback& |
567 callback) OVERRIDE { | 600 callback) OVERRIDE { |
568 std::string no_data; | 601 std::string no_data; |
569 callback.Run(base::RefCountedString::TakeString(&no_data)); | 602 callback.Run(base::RefCountedString::TakeString(&no_data)); |
570 return true; | 603 return true; |
571 } | 604 } |
572 virtual void GetRoutes(bool numeric, bool ipv6, | 605 virtual void GetRoutes(bool numeric, bool ipv6, |
573 const GetRoutesCallback& callback) OVERRIDE { | 606 const GetRoutesCallback& callback) OVERRIDE { |
574 std::vector<std::string> empty; | 607 std::vector<std::string> empty; |
575 base::MessageLoop::current()->PostTask(FROM_HERE, | 608 base::MessageLoop::current()->PostTask(FROM_HERE, |
576 base::Bind(callback, false, empty)); | 609 base::Bind(callback, false, empty)); |
577 } | 610 } |
578 virtual void GetNetworkStatus(const GetNetworkStatusCallback& callback) | 611 virtual void GetNetworkStatus(const GetNetworkStatusCallback& callback) |
579 OVERRIDE { | 612 OVERRIDE { |
580 base::MessageLoop::current()->PostTask(FROM_HERE, | 613 base::MessageLoop::current()->PostTask(FROM_HERE, |
581 base::Bind(callback, false, "")); | 614 base::Bind(callback, false, "")); |
582 } | 615 } |
583 virtual void GetModemStatus(const GetModemStatusCallback& callback) | 616 virtual void GetModemStatus(const GetModemStatusCallback& callback) |
584 OVERRIDE { | 617 OVERRIDE { |
585 base::MessageLoop::current()->PostTask(FROM_HERE, | 618 base::MessageLoop::current()->PostTask(FROM_HERE, |
586 base::Bind(callback, false, "")); | 619 base::Bind(callback, false, "")); |
587 } | 620 } |
588 virtual void GetNetworkInterfaces( | 621 virtual void GetNetworkInterfaces( |
589 const GetNetworkInterfacesCallback& callback) OVERRIDE { | 622 const GetNetworkInterfacesCallback& callback) OVERRIDE { |
590 base::MessageLoop::current()->PostTask(FROM_HERE, | 623 base::MessageLoop::current()->PostTask(FROM_HERE, |
591 base::Bind(callback, false, "")); | 624 base::Bind(callback, false, "")); |
592 } | 625 } |
593 virtual void GetPerfData(uint32_t duration, | 626 virtual void GetPerfData(uint32_t duration, |
594 const GetPerfDataCallback& callback) OVERRIDE { | 627 const GetPerfDataCallback& callback) OVERRIDE { |
595 std::vector<uint8> data; | 628 std::vector<uint8> data; |
596 base::MessageLoop::current()->PostTask(FROM_HERE, | 629 base::MessageLoop::current()->PostTask(FROM_HERE, |
597 base::Bind(callback, data)); | 630 base::Bind(callback, data)); |
598 } | 631 } |
599 virtual void GetAllLogs(const GetLogsCallback& callback) OVERRIDE { | 632 virtual void GetAllLogs(const GetLogsCallback& callback) OVERRIDE { |
600 std::map<std::string, std::string> empty; | 633 std::map<std::string, std::string> empty; |
601 base::MessageLoop::current()->PostTask(FROM_HERE, | 634 base::MessageLoop::current()->PostTask(FROM_HERE, |
602 base::Bind(callback, false, empty)); | 635 base::Bind(callback, false, empty)); |
603 } | 636 } |
604 virtual void GetUserLogFiles(const GetLogsCallback& callback) OVERRIDE { | 637 virtual void GetUserLogFiles(const GetLogsCallback& callback) OVERRIDE { |
605 std::map<std::string, std::string> user_logs; | 638 std::map<std::string, std::string> user_logs; |
606 user_logs["preferences"] = "Preferences"; | 639 user_logs["preferences"] = "Preferences"; |
607 user_logs["invalid_file"] = "Invalid File"; | 640 user_logs["invalid_file"] = "Invalid File"; |
608 base::MessageLoop::current()->PostTask(FROM_HERE, | 641 base::MessageLoop::current()->PostTask( |
609 base::Bind(callback, true, user_logs)); | 642 FROM_HERE, |
| 643 base::Bind(callback, true, user_logs)); |
610 } | 644 } |
611 | 645 |
612 virtual void TestICMP(const std::string& ip_address, | 646 virtual void TestICMP(const std::string& ip_address, |
613 const TestICMPCallback& callback) OVERRIDE { | 647 const TestICMPCallback& callback) OVERRIDE { |
614 base::MessageLoop::current()->PostTask(FROM_HERE, | 648 base::MessageLoop::current()->PostTask(FROM_HERE, |
615 base::Bind(callback, false, "")); | 649 base::Bind(callback, false, "")); |
| 650 } |
| 651 |
| 652 virtual void TestICMPWithOptions( |
| 653 const std::string& ip_address, |
| 654 const std::map<std::string, std::string>& options, |
| 655 const TestICMPCallback& callback) OVERRIDE { |
| 656 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 657 base::Bind(callback, false, "")); |
616 } | 658 } |
617 }; | 659 }; |
618 | 660 |
619 DebugDaemonClient::DebugDaemonClient() { | 661 DebugDaemonClient::DebugDaemonClient() { |
620 } | 662 } |
621 | 663 |
622 DebugDaemonClient::~DebugDaemonClient() { | 664 DebugDaemonClient::~DebugDaemonClient() { |
623 } | 665 } |
624 | 666 |
625 // static | 667 // static |
626 DebugDaemonClient::StopSystemTracingCallback | 668 DebugDaemonClient::StopSystemTracingCallback |
627 DebugDaemonClient::EmptyStopSystemTracingCallback() { | 669 DebugDaemonClient::EmptyStopSystemTracingCallback() { |
628 return base::Bind(&EmptyStopSystemTracingCallbackBody); | 670 return base::Bind(&EmptyStopSystemTracingCallbackBody); |
629 } | 671 } |
630 | 672 |
631 // static | 673 // static |
632 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, | 674 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, |
633 dbus::Bus* bus) { | 675 dbus::Bus* bus) { |
634 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 676 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
635 return new DebugDaemonClientImpl(bus); | 677 return new DebugDaemonClientImpl(bus); |
636 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 678 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
637 return new DebugDaemonClientStubImpl(); | 679 return new DebugDaemonClientStubImpl(); |
638 } | 680 } |
639 | 681 |
640 } // namespace chromeos | 682 } // namespace chromeos |
OLD | NEW |