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 "chromeos/dbus/debug_daemon_client.h" | 5 #include "chromeos/dbus/debug_daemon_client.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 sub_writer.CloseContainer(&elem_writer); | 461 sub_writer.CloseContainer(&elem_writer); |
462 } | 462 } |
463 writer.CloseContainer(&sub_writer); | 463 writer.CloseContainer(&sub_writer); |
464 | 464 |
465 debugdaemon_proxy_->CallMethod( | 465 debugdaemon_proxy_->CallMethod( |
466 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 466 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
467 base::Bind(&DebugDaemonClientImpl::OnSetOomScoreAdj, | 467 base::Bind(&DebugDaemonClientImpl::OnSetOomScoreAdj, |
468 weak_ptr_factory_.GetWeakPtr(), callback)); | 468 weak_ptr_factory_.GetWeakPtr(), callback)); |
469 } | 469 } |
470 | 470 |
471 void CupsAddPrinter(const std::string& name, | |
472 const std::string& uri, | |
473 const std::string& ppd_path, | |
474 bool ipp_everywhere, | |
475 const DebugDaemonClient::AddPrinterCallback& callback, | |
476 const base::Closure& error_callback) override { | |
477 dbus::MethodCall method_call(debugd::kDebugdInterface, | |
478 debugd::kCupsAddPrinter); | |
479 dbus::MessageWriter writer(&method_call); | |
480 writer.AppendString(name); | |
481 writer.AppendString(uri); | |
482 writer.AppendString(ppd_path); | |
483 writer.AppendBool(ipp_everywhere); | |
484 | |
485 debugdaemon_proxy_->CallMethod( | |
486 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
487 base::Bind(&DebugDaemonClientImpl::OnPrinterAdded, | |
488 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | |
489 } | |
490 | |
491 void CupsRemovePrinter( | |
492 const std::string& name, | |
493 const DebugDaemonClient::RemovePrinterCallback& callback, | |
494 const base::Closure& error_callback) override { | |
495 dbus::MethodCall method_call(debugd::kDebugdInterface, | |
496 debugd::kCupsRemovePrinter); | |
497 dbus::MessageWriter writer(&method_call); | |
498 writer.AppendString(name); | |
499 | |
500 debugdaemon_proxy_->CallMethod( | |
501 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
502 base::Bind(&DebugDaemonClientImpl::OnPrinterRemoved, | |
503 weak_ptr_factory_.GetWeakPtr(), callback, error_callback)); | |
504 } | |
505 | |
471 protected: | 506 protected: |
472 void Init(dbus::Bus* bus) override { | 507 void Init(dbus::Bus* bus) override { |
473 debugdaemon_proxy_ = | 508 debugdaemon_proxy_ = |
474 bus->GetObjectProxy(debugd::kDebugdServiceName, | 509 bus->GetObjectProxy(debugd::kDebugdServiceName, |
475 dbus::ObjectPath(debugd::kDebugdServicePath)); | 510 dbus::ObjectPath(debugd::kDebugdServicePath)); |
476 } | 511 } |
477 | 512 |
478 private: | 513 private: |
479 // Called when a response for GetDebugLogs() is received. | 514 // Called when a response for GetDebugLogs() is received. |
480 void OnGetDebugLogs(const GetDebugLogsCallback& callback, | 515 void OnGetDebugLogs(const GetDebugLogsCallback& callback, |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 | 708 |
674 void OnSetOomScoreAdj(const SetOomScoreAdjCallback& callback, | 709 void OnSetOomScoreAdj(const SetOomScoreAdjCallback& callback, |
675 dbus::Response* response) { | 710 dbus::Response* response) { |
676 std::string output; | 711 std::string output; |
677 if (response && dbus::MessageReader(response).PopString(&output)) | 712 if (response && dbus::MessageReader(response).PopString(&output)) |
678 callback.Run(true, output); | 713 callback.Run(true, output); |
679 else | 714 else |
680 callback.Run(false, ""); | 715 callback.Run(false, ""); |
681 } | 716 } |
682 | 717 |
718 void OnPrinterAdded(const AddPrinterCallback& callback, | |
719 const base::Closure& error_callback, | |
720 dbus::Response* response) { | |
721 bool result; | |
hashimoto
2016/09/12 05:20:36
nit: bool result = false;
Please don't leave this
skau
2016/09/12 17:53:56
Done.
| |
722 dbus::MessageReader reader(response); | |
723 if (response && reader.PopBool(&result)) { | |
724 callback.Run(result); | |
725 } else { | |
726 error_callback.Run(); | |
727 } | |
728 } | |
729 | |
730 void OnPrinterRemoved(const RemovePrinterCallback& callback, | |
731 const base::Closure& error_callback, | |
732 dbus::Response* response) { | |
733 bool result; | |
hashimoto
2016/09/12 05:20:36
ditto.
skau
2016/09/12 17:53:56
Done.
| |
734 dbus::MessageReader reader(response); | |
735 if (response && reader.PopBool(&result)) { | |
736 callback.Run(result); | |
737 } else { | |
738 error_callback.Run(); | |
739 } | |
740 } | |
741 | |
683 dbus::ObjectProxy* debugdaemon_proxy_; | 742 dbus::ObjectProxy* debugdaemon_proxy_; |
684 std::unique_ptr<PipeReaderForString> pipe_reader_; | 743 std::unique_ptr<PipeReaderForString> pipe_reader_; |
685 StopAgentTracingCallback callback_; | 744 StopAgentTracingCallback callback_; |
686 scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_; | 745 scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_; |
687 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; | 746 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; |
688 | 747 |
689 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); | 748 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); |
690 }; | 749 }; |
691 | 750 |
692 DebugDaemonClient::DebugDaemonClient() { | 751 DebugDaemonClient::DebugDaemonClient() { |
693 } | 752 } |
694 | 753 |
695 DebugDaemonClient::~DebugDaemonClient() { | 754 DebugDaemonClient::~DebugDaemonClient() { |
696 } | 755 } |
697 | 756 |
698 // static | 757 // static |
699 DebugDaemonClient::StopAgentTracingCallback | 758 DebugDaemonClient::StopAgentTracingCallback |
700 DebugDaemonClient::EmptyStopAgentTracingCallback() { | 759 DebugDaemonClient::EmptyStopAgentTracingCallback() { |
701 return base::Bind(&EmptyStopAgentTracingCallbackBody); | 760 return base::Bind(&EmptyStopAgentTracingCallbackBody); |
702 } | 761 } |
703 | 762 |
704 // static | 763 // static |
705 DebugDaemonClient* DebugDaemonClient::Create() { | 764 DebugDaemonClient* DebugDaemonClient::Create() { |
706 return new DebugDaemonClientImpl(); | 765 return new DebugDaemonClientImpl(); |
707 } | 766 } |
708 | 767 |
709 } // namespace chromeos | 768 } // namespace chromeos |
OLD | NEW |