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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 base::Bind(&DebugDaemonClientImpl::OnRemoveRootfsVerification, | 453 base::Bind(&DebugDaemonClientImpl::OnRemoveRootfsVerification, |
454 weak_ptr_factory_.GetWeakPtr(), | 454 weak_ptr_factory_.GetWeakPtr(), |
455 callback)); | 455 callback)); |
456 } | 456 } |
457 | 457 |
458 void WaitForServiceToBeAvailable( | 458 void WaitForServiceToBeAvailable( |
459 const WaitForServiceToBeAvailableCallback& callback) override { | 459 const WaitForServiceToBeAvailableCallback& callback) override { |
460 debugdaemon_proxy_->WaitForServiceToBeAvailable(callback); | 460 debugdaemon_proxy_->WaitForServiceToBeAvailable(callback); |
461 } | 461 } |
462 | 462 |
463 void SetOomScoreAdj(const std::map<int, int>& scores, | |
464 const SetOomScoreAdjCallback& callback) override { | |
465 dbus::MethodCall method_call(debugd::kDebugdInterface, | |
466 debugd::kSetOomScoreAdj); | |
467 dbus::MessageWriter writer(&method_call); | |
468 dbus::MessageWriter sub_writer(NULL); | |
hashimoto
2016/08/15 03:54:23
Please declare this variable in as local a scope a
cylee1
2016/08/16 19:47:10
Done.
| |
469 dbus::MessageWriter elem_writer(NULL); | |
hashimoto
2016/08/15 03:54:23
ditto.
cylee1
2016/08/16 19:47:10
Done.
| |
470 | |
471 writer.OpenArray("{ii}", &sub_writer); | |
472 for (const auto& entry : scores) { | |
473 sub_writer.OpenDictEntry(&elem_writer); | |
474 elem_writer.AppendInt32(entry.first); | |
475 elem_writer.AppendInt32(entry.second); | |
476 sub_writer.CloseContainer(&elem_writer); | |
477 } | |
478 writer.CloseContainer(&sub_writer); | |
479 | |
480 debugdaemon_proxy_->CallMethod( | |
481 &method_call, | |
482 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
483 base::Bind(&DebugDaemonClientImpl::OnSetOomScoreAdj, | |
484 weak_ptr_factory_.GetWeakPtr(), | |
485 callback)); | |
486 } | |
487 | |
463 protected: | 488 protected: |
464 void Init(dbus::Bus* bus) override { | 489 void Init(dbus::Bus* bus) override { |
465 debugdaemon_proxy_ = | 490 debugdaemon_proxy_ = |
466 bus->GetObjectProxy(debugd::kDebugdServiceName, | 491 bus->GetObjectProxy(debugd::kDebugdServiceName, |
467 dbus::ObjectPath(debugd::kDebugdServicePath)); | 492 dbus::ObjectPath(debugd::kDebugdServicePath)); |
468 } | 493 } |
469 | 494 |
470 private: | 495 private: |
471 // Called when a CheckValidity response is received. | 496 // Called when a CheckValidity response is received. |
472 void OnCheckValidityGetDebugLogs(bool is_compressed, | 497 void OnCheckValidityGetDebugLogs(bool is_compressed, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 738 |
714 // Called when pipe i/o completes; pass data on and delete the instance. | 739 // Called when pipe i/o completes; pass data on and delete the instance. |
715 void OnIOComplete() { | 740 void OnIOComplete() { |
716 std::string pipe_data; | 741 std::string pipe_data; |
717 pipe_reader_->GetData(&pipe_data); | 742 pipe_reader_->GetData(&pipe_data); |
718 callback_.Run(GetTracingAgentName(), GetTraceEventLabel(), | 743 callback_.Run(GetTracingAgentName(), GetTraceEventLabel(), |
719 base::RefCountedString::TakeString(&pipe_data)); | 744 base::RefCountedString::TakeString(&pipe_data)); |
720 pipe_reader_.reset(); | 745 pipe_reader_.reset(); |
721 } | 746 } |
722 | 747 |
748 void OnSetOomScoreAdj(const SetOomScoreAdjCallback& callback, | |
749 dbus::Response* response) { | |
750 if (callback.is_null()) | |
hashimoto
2016/08/15 03:54:23
Is there any strong reason to allow null callbacks
cylee1
2016/08/16 19:47:10
Done.
| |
751 return; | |
752 | |
753 std::string output; | |
754 if (response && dbus::MessageReader(response).PopString(&output)) | |
755 callback.Run(true, output); | |
756 else | |
757 callback.Run(false, ""); | |
758 } | |
759 | |
723 dbus::ObjectProxy* debugdaemon_proxy_; | 760 dbus::ObjectProxy* debugdaemon_proxy_; |
724 std::unique_ptr<PipeReaderForString> pipe_reader_; | 761 std::unique_ptr<PipeReaderForString> pipe_reader_; |
725 StopAgentTracingCallback callback_; | 762 StopAgentTracingCallback callback_; |
726 scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_; | 763 scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_; |
727 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; | 764 base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_; |
728 | 765 |
729 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); | 766 DISALLOW_COPY_AND_ASSIGN(DebugDaemonClientImpl); |
730 }; | 767 }; |
731 | 768 |
732 DebugDaemonClient::DebugDaemonClient() { | 769 DebugDaemonClient::DebugDaemonClient() { |
733 } | 770 } |
734 | 771 |
735 DebugDaemonClient::~DebugDaemonClient() { | 772 DebugDaemonClient::~DebugDaemonClient() { |
736 } | 773 } |
737 | 774 |
738 // static | 775 // static |
739 DebugDaemonClient::StopAgentTracingCallback | 776 DebugDaemonClient::StopAgentTracingCallback |
740 DebugDaemonClient::EmptyStopAgentTracingCallback() { | 777 DebugDaemonClient::EmptyStopAgentTracingCallback() { |
741 return base::Bind(&EmptyStopAgentTracingCallbackBody); | 778 return base::Bind(&EmptyStopAgentTracingCallbackBody); |
742 } | 779 } |
743 | 780 |
744 // static | 781 // static |
745 DebugDaemonClient* DebugDaemonClient::Create() { | 782 DebugDaemonClient* DebugDaemonClient::Create() { |
746 return new DebugDaemonClientImpl(); | 783 return new DebugDaemonClientImpl(); |
747 } | 784 } |
748 | 785 |
749 } // namespace chromeos | 786 } // namespace chromeos |
OLD | NEW |