1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "chromeos/ash/components/dbus/debug_daemon/debug_daemon_client.h"
#include <fcntl.h>
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/trace_event/trace_config.h"
#include "chromeos/ash/components/dbus/cryptohome/rpc.pb.h"
#include "chromeos/ash/components/dbus/debug_daemon/fake_debug_daemon_client.h"
#include "chromeos/ash/components/dbus/debug_daemon/metrics.h"
#include "chromeos/dbus/common/dbus_library_error.h"
#include "chromeos/dbus/common/pipe_reader.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "third_party/cros_system_api/dbus/debugd/dbus-constants.h"
namespace ash {
namespace {
const char kCrOSTracingAgentName[] = "cros";
const char kCrOSTraceLabel[] = "systemTraceEvents";
// Because the cheets logs are very huge, we set the D-Bus timeout to 2 minutes.
const int kBigLogsDBusTimeoutMS = 120 * 1000;
// crash_sender could take a while to run if the network connection is slow, so
// wait up to 20 seconds for it.
const int kCrashSenderTimeoutMS = 20 * 1000;
// NOTE: This does not use the typical pattern of a single `g_instance` variable
// due to browser_tests that need to temporarily override the existing instance
// with a specialized subclass.
DebugDaemonClient* g_instance = nullptr;
DebugDaemonClient* g_instance_for_test = nullptr;
// A self-deleting object that wraps the pipe reader operations for reading the
// big feedback logs. It will delete itself once the pipe stream has been
// terminated. Once the data has been completely read from the pipe, it invokes
// the GetLogsCallback |callback| passing the deserialized logs data back to
// the requester.
class PipeReaderWrapper final {
public:
explicit PipeReaderWrapper(DebugDaemonClient::GetLogsCallback callback)
: pipe_reader_(base::ThreadPool::CreateTaskRunner(
{base::MayBlock(),
base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN})),
callback_(std::move(callback)) {}
PipeReaderWrapper(const PipeReaderWrapper&) = delete;
PipeReaderWrapper& operator=(const PipeReaderWrapper&) = delete;
base::ScopedFD Initialize() {
return pipe_reader_.StartIO(base::BindOnce(&PipeReaderWrapper::OnIOComplete,
weak_ptr_factory_.GetWeakPtr()));
}
void OnIOComplete(std::optional<std::string> result) {
if (!result.has_value()) {
VLOG(1) << "Failed to read data.";
RecordGetFeedbackLogsV2DbusResult(
GetFeedbackLogsV2DbusResult::kErrorReadingData);
RunCallbackAndDestroy(std::nullopt);
return;
}
std::optional<base::Value::Dict> logs = base::JSONReader::ReadDict(*result);
if (!logs.has_value()) {
VLOG(1) << "Failed to deserialize the JSON logs.";
RecordGetFeedbackLogsV2DbusResult(
GetFeedbackLogsV2DbusResult::kErrorDeserializingJSonLogs);
RunCallbackAndDestroy(std::nullopt);
return;
}
std::map<std::string, std::string> data;
for (const auto [dict_key, dict_value] : *logs) {
data[dict_key] = dict_value.GetString();
}
RunCallbackAndDestroy(std::move(data));
}
void TerminateStream() {
VLOG(1) << "Terminated";
RunCallbackAndDestroy(std::nullopt);
}
base::WeakPtr<PipeReaderWrapper> AsWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
private:
void RunCallbackAndDestroy(
std::optional<std::map<std::string, std::string>> result) {
if (result.has_value()) {
std::move(callback_).Run(true, std::move(result.value()));
} else {
std::move(callback_).Run(false, std::map<std::string, std::string>());
}
delete this;
}
chromeos::PipeReader pipe_reader_;
DebugDaemonClient::GetLogsCallback callback_;
base::WeakPtrFactory<PipeReaderWrapper> weak_ptr_factory_{this};
};
// The DebugDaemonClient implementation used in production.
class DebugDaemonClientImpl : public DebugDaemonClient {
public:
DebugDaemonClientImpl() : debugdaemon_proxy_(nullptr) {}
DebugDaemonClientImpl(const DebugDaemonClientImpl&) = delete;
DebugDaemonClientImpl& operator=(const DebugDaemonClientImpl&) = delete;
~DebugDaemonClientImpl() override = default;
// DebugDaemonClient override.
void DumpDebugLogs(bool is_compressed,
int file_descriptor,
chromeos::VoidDBusMethodCallback callback) override {
// Issue the dbus request to get debug logs.
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kDumpDebugLogs);
dbus::MessageWriter writer(&method_call);
writer.AppendBool(is_compressed);
writer.AppendFileDescriptor(file_descriptor);
debugdaemon_proxy_->CallMethod(
&method_call, kBigLogsDBusTimeoutMS,
base::BindOnce(&DebugDaemonClientImpl::OnVoidMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetDebugMode(const std::string& subsystem,
chromeos::VoidDBusMethodCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSetDebugMode);
dbus::MessageWriter writer(&method_call);
writer.AppendString(subsystem);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnVoidMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetRoutes(bool numeric,
bool ipv6,
bool all_tables,
chromeos::DBusMethodCallback<std::vector<std::string>>
callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, debugd::kGetRoutes);
dbus::MessageWriter writer(&method_call);
dbus::MessageWriter sub_writer(NULL);
writer.OpenArray("{sv}", &sub_writer);
dbus::MessageWriter elem_writer(NULL);
sub_writer.OpenDictEntry(&elem_writer);
elem_writer.AppendString("numeric");
elem_writer.AppendVariantOfBool(numeric);
sub_writer.CloseContainer(&elem_writer);
sub_writer.OpenDictEntry(&elem_writer);
elem_writer.AppendString("v6");
elem_writer.AppendVariantOfBool(ipv6);
sub_writer.CloseContainer(&elem_writer);
sub_writer.OpenDictEntry(&elem_writer);
elem_writer.AppendString("all");
elem_writer.AppendVariantOfBool(all_tables);
sub_writer.CloseContainer(&elem_writer);
writer.CloseContainer(&sub_writer);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnGetRoutes,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNetworkStatus(
chromeos::DBusMethodCallback<std::string> callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetNetworkStatus);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStringMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetNetworkInterfaces(
chromeos::DBusMethodCallback<std::string> callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetInterfaces);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStringMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetPerfOutput(const std::vector<std::string>& quipper_args,
bool disable_cpu_idle,
int file_descriptor,
chromeos::DBusMethodCallback<uint64_t> callback) override {
DCHECK(file_descriptor);
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetPerfOutputV2);
dbus::MessageWriter writer(&method_call);
writer.AppendArrayOfStrings(quipper_args);
writer.AppendBool(disable_cpu_idle);
writer.AppendFileDescriptor(file_descriptor);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnUint64Method,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void StopPerf(uint64_t session_id,
chromeos::VoidDBusMethodCallback callback) override {
DCHECK(session_id);
dbus::MethodCall method_call(debugd::kDebugdInterface, debugd::kStopPerf);
dbus::MessageWriter writer(&method_call);
writer.AppendUint64(session_id);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnVoidMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetFeedbackLogs(
const cryptohome::AccountIdentifier& id,
const std::vector<debugd::FeedbackLogType>& requested_logs,
GetLogsCallback callback) override {
// The PipeReaderWrapper is a self-deleting object; we don't have to worry
// about ownership or lifetime. We need to create a new one for each Big
// Logs requests in order to queue these requests. One request can take a
// long time to be processed and a new request should never be ignored nor
// cancels the on-going one.
PipeReaderWrapper* pipe_reader = new PipeReaderWrapper(std::move(callback));
base::ScopedFD pipe_write_end = pipe_reader->Initialize();
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetFeedbackLogsV3);
dbus::MessageWriter writer(&method_call);
writer.AppendFileDescriptor(pipe_write_end.get());
writer.AppendString(id.account_id());
// Write |requested_logs|.
dbus::MessageWriter sub_writer(nullptr);
writer.OpenArray("i", &sub_writer);
for (auto log_type : requested_logs) {
sub_writer.AppendInt32(log_type);
}
writer.CloseContainer(&sub_writer);
DVLOG(1) << "Requesting feedback logs";
debugdaemon_proxy_->CallMethodWithErrorResponse(
&method_call, kBigLogsDBusTimeoutMS,
base::BindOnce(&DebugDaemonClientImpl::OnFeedbackLogsResponse,
weak_ptr_factory_.GetWeakPtr(),
pipe_reader->AsWeakPtr()));
}
void GetFeedbackBinaryLogs(
const cryptohome::AccountIdentifier& id,
const std::map<debugd::FeedbackBinaryLogType, base::ScopedFD>&
log_type_fds,
chromeos::VoidDBusMethodCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetFeedbackBinaryLogs);
dbus::MessageWriter writer(&method_call);
writer.AppendString(id.account_id());
dbus::MessageWriter array_writer(nullptr);
// Write map of log_type and fd.
writer.OpenArray("{ih}", &array_writer);
for (const auto& log_type : log_type_fds) {
dbus::MessageWriter dict_entry_writer(nullptr);
array_writer.OpenDictEntry(&dict_entry_writer);
dict_entry_writer.AppendInt32(log_type.first);
dict_entry_writer.AppendFileDescriptor(log_type.second.get());
array_writer.CloseContainer(&dict_entry_writer);
}
writer.CloseContainer(&array_writer);
DVLOG(1) << "Requesting feedback binary logs";
debugdaemon_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnFeedbackBinaryLogsResponse,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void BackupArcBugReport(const cryptohome::AccountIdentifier& id,
chromeos::VoidDBusMethodCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kBackupArcBugReport);
dbus::MessageWriter writer(&method_call);
writer.AppendString(id.account_id());
DVLOG(1) << "Backing up ARC bug report";
debugdaemon_proxy_->CallMethod(
&method_call, kBigLogsDBusTimeoutMS,
base::BindOnce(&DebugDaemonClientImpl::OnVoidMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetAllLogs(GetLogsCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, debugd::kGetAllLogs);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnGetAllLogs,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetLog(const std::string& log_name,
chromeos::DBusMethodCallback<std::string> callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, debugd::kGetLog);
dbus::MessageWriter(&method_call).AppendString(log_name);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStringMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
// base::trace_event::TracingAgent implementation.
std::string GetTracingAgentName() override { return kCrOSTracingAgentName; }
std::string GetTraceEventLabel() override { return kCrOSTraceLabel; }
void StartAgentTracing(const base::trace_event::TraceConfig& trace_config,
StartAgentTracingCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSystraceStart);
dbus::MessageWriter writer(&method_call);
if (trace_config.systrace_events().empty()) {
writer.AppendString("all"); // TODO(sleffler) parameterize category list
} else {
std::string events;
for (const std::string& event : trace_config.systrace_events()) {
if (!events.empty())
events += " ";
events += event;
}
writer.AppendString(events);
}
DVLOG(1) << "Requesting a systrace start";
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStartMethod,
weak_ptr_factory_.GetWeakPtr()));
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), GetTracingAgentName(),
true /* success */));
}
void StopAgentTracing(StopAgentTracingCallback callback) override {
DCHECK(stop_agent_tracing_task_runner_);
if (pipe_reader_ != NULL) {
LOG(ERROR) << "Busy doing StopSystemTracing";
return;
}
pipe_reader_ =
std::make_unique<chromeos::PipeReader>(stop_agent_tracing_task_runner_);
callback_ = std::move(callback);
base::ScopedFD pipe_write_end = pipe_reader_->StartIO(base::BindOnce(
&DebugDaemonClientImpl::OnIOComplete, weak_ptr_factory_.GetWeakPtr()));
DCHECK(pipe_write_end.is_valid());
// Issue the dbus request to stop system tracing
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSystraceStop);
dbus::MessageWriter writer(&method_call);
writer.AppendFileDescriptor(pipe_write_end.get());
DVLOG(1) << "Requesting a systrace stop";
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStopAgentTracing,
weak_ptr_factory_.GetWeakPtr()));
}
void SetStopAgentTracingTaskRunner(
scoped_refptr<base::TaskRunner> task_runner) override {
stop_agent_tracing_task_runner_ = task_runner;
}
void TestICMP(const std::string& ip_address,
TestICMPCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface, debugd::kTestICMP);
dbus::MessageWriter writer(&method_call);
writer.AppendString(ip_address);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnTestICMP,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void TestICMPWithOptions(const std::string& ip_address,
const std::map<std::string, std::string>& options,
TestICMPCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kTestICMPWithOptions);
dbus::MessageWriter writer(&method_call);
dbus::MessageWriter sub_writer(NULL);
dbus::MessageWriter elem_writer(NULL);
// Write the host.
writer.AppendString(ip_address);
// Write the options.
writer.OpenArray("{ss}", &sub_writer);
std::map<std::string, std::string>::const_iterator it;
for (it = options.begin(); it != options.end(); ++it) {
sub_writer.OpenDictEntry(&elem_writer);
elem_writer.AppendString(it->first);
elem_writer.AppendString(it->second);
sub_writer.CloseContainer(&elem_writer);
}
writer.CloseContainer(&sub_writer);
// Call the function.
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnTestICMP,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void UploadCrashes(UploadCrashesCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kUploadCrashes);
debugdaemon_proxy_->CallMethod(
&method_call, kCrashSenderTimeoutMS,
base::BindOnce(&DebugDaemonClientImpl::OnUploadCrashes,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void OnUploadCrashes(UploadCrashesCallback callback,
dbus::Response* response) {
if (callback.is_null()) {
return;
}
std::move(callback).Run(response != nullptr);
}
void EnableDebuggingFeatures(const std::string& password,
EnableDebuggingCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kEnableChromeDevFeatures);
dbus::MessageWriter writer(&method_call);
writer.AppendString(password);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnEnableDebuggingFeatures,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void QueryDebuggingFeatures(QueryDevFeaturesCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kQueryDevFeatures);
dbus::MessageWriter writer(&method_call);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnQueryDebuggingFeatures,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void RemoveRootfsVerification(EnableDebuggingCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kRemoveRootfsVerification);
dbus::MessageWriter writer(&method_call);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnRemoveRootfsVerification,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void WaitForServiceToBeAvailable(
chromeos::WaitForServiceToBeAvailableCallback callback) override {
debugdaemon_proxy_->WaitForServiceToBeAvailable(std::move(callback));
}
void SetOomScoreAdj(const std::map<pid_t, int32_t>& pid_to_oom_score_adj,
SetOomScoreAdjCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSetOomScoreAdj);
dbus::MessageWriter writer(&method_call);
dbus::MessageWriter sub_writer(nullptr);
writer.OpenArray("{ii}", &sub_writer);
dbus::MessageWriter elem_writer(nullptr);
for (const auto& entry : pid_to_oom_score_adj) {
sub_writer.OpenDictEntry(&elem_writer);
elem_writer.AppendInt32(entry.first);
elem_writer.AppendInt32(entry.second);
sub_writer.CloseContainer(&elem_writer);
}
writer.CloseContainer(&sub_writer);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnSetOomScoreAdj,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void CupsAddManuallyConfiguredPrinter(
const std::string& name,
const std::string& uri,
const std::string& language,
const std::string& ppd_contents,
DebugDaemonClient::CupsAddPrinterCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kCupsAddManuallyConfiguredPrinterV2);
dbus::MessageWriter writer(&method_call);
writer.AppendString(name);
writer.AppendString(uri);
writer.AppendString(language);
writer.AppendArrayOfBytes(base::as_byte_span(ppd_contents));
debugdaemon_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnPrinterAdded,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void CupsAddAutoConfiguredPrinter(
const std::string& name,
const std::string& uri,
const std::string& language,
DebugDaemonClient::CupsAddPrinterCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kCupsAddAutoConfiguredPrinterV2);
dbus::MessageWriter writer(&method_call);
writer.AppendString(name);
writer.AppendString(uri);
writer.AppendString(language);
debugdaemon_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnPrinterAdded,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void CupsRemovePrinter(const std::string& name,
DebugDaemonClient::CupsRemovePrinterCallback callback,
base::OnceClosure error_callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kCupsRemovePrinter);
dbus::MessageWriter writer(&method_call);
writer.AppendString(name);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnPrinterRemoved,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback)));
}
void CupsRetrievePrinterPpd(
const std::string& name,
DebugDaemonClient::CupsRetrievePrinterPpdCallback callback,
base::OnceClosure error_callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kCupsRetrievePpd);
dbus::MessageWriter writer(&method_call);
writer.AppendString(name);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnRetrievedPrinterPpd,
weak_ptr_factory_.GetWeakPtr(), std::move(callback),
std::move(error_callback)));
}
void StartPluginVmDispatcher(const std::string& owner_id,
const std::string& lang,
PluginVmDispatcherCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kStartVmPluginDispatcher);
dbus::MessageWriter writer(&method_call);
writer.AppendString(owner_id);
writer.AppendString(lang);
debugdaemon_proxy_->CallMethodWithErrorResponse(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStartPluginVmDispatcher,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void StopPluginVmDispatcher(PluginVmDispatcherCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kStopVmPluginDispatcher);
dbus::MessageWriter writer(&method_call);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStopPluginVmDispatcher,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetRlzPingSent(SetRlzPingSentCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSetRlzPingSent);
dbus::MessageWriter writer(&method_call);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnSetRlzPingSent,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetKstaledRatio(uint8_t val, KstaledRatioCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kKstaledSetRatio);
dbus::MessageWriter writer(&method_call);
writer.AppendByte(val);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnSetKstaledRatio,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetSchedulerConfigurationV2(
const std::string& config_name,
bool lock_policy,
SetSchedulerConfigurationV2Callback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSetSchedulerConfigurationV2);
dbus::MessageWriter writer(&method_call);
writer.AppendString(config_name);
writer.AppendBool(lock_policy);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnSetSchedulerConfigurationV2,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void SetU2fFlags(const std::set<std::string>& flags,
chromeos::VoidDBusMethodCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kSetU2fFlags);
dbus::MessageWriter writer(&method_call);
writer.AppendString(base::JoinString(
std::vector<std::string>(flags.begin(), flags.end()), ","));
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnVoidMethod,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void GetU2fFlags(
chromeos::DBusMethodCallback<std::set<std::string>> callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kGetU2fFlags);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnGetU2fFlags,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void BluetoothStartBtsnoop(BluetoothBtsnoopCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kBluetoothStartBtsnoop);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnBluetoothStartBtsnoop,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void BluetoothStopBtsnoop(int fd,
BluetoothBtsnoopCallback callback) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kBluetoothStopBtsnoop);
dbus::MessageWriter writer(&method_call);
writer.AppendFileDescriptor(fd);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnBluetoothStopBtsnoop,
weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
}
void StopPacketCapture(const std::string& handle) override {
dbus::MethodCall method_call(debugd::kDebugdInterface,
debugd::kPacketCaptureStop);
dbus::MessageWriter writer(&method_call);
writer.AppendString(handle);
debugdaemon_proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&DebugDaemonClientImpl::OnStopMethod,
weak_ptr_factory_.GetWeakPtr()));
}
// DebugDaemonClient Observer overrides.
void AddObserver(Observer* observer) override {
DCHECK(observer);
observers_.AddObserver(observer);
}
void RemoveObserver(Observer* observer) override {
DCHECK(observer);
observers_.RemoveObserver(observer);
}
void Init(dbus::Bus* bus) override {
debugdaemon_proxy_ =
bus->GetObjectProxy(debugd::kDebugdServiceName,
dbus::ObjectPath(debugd::kDebugdServicePath));
// Listen to D-Bus signals emitted by debugd.
auto on_connected_callback =
base::BindRepeating(&DebugDaemonClientImpl::SignalConnected,
weak_ptr_factory_.GetWeakPtr());
debugdaemon_proxy_->ConnectToSignal(
debugd::kDebugdInterface, debugd::kPacketCaptureStartSignal,
base::BindRepeating(
&DebugDaemonClientImpl::PacketCaptureStartSignalReceived,
weak_ptr_factory_.GetWeakPtr()),
on_connected_callback);
debugdaemon_proxy_->ConnectToSignal(
debugd::kDebugdInterface, debugd::kPacketCaptureStopSignal,
base::BindRepeating(
&DebugDaemonClientImpl::PacketCaptureStopSignalReceived,
weak_ptr_factory_.GetWeakPtr()),
on_connected_callback);
}
private:
void OnGetRoutes(
chromeos::DBusMethodCallback<std::vector<std::string>> callback,
dbus::Response* response) {
if (!response) {
std::move(callback).Run(std::nullopt);
return;
}
std::vector<std::string> routes;
dbus::MessageReader reader(response);
if (!reader.PopArrayOfStrings(&routes)) {
LOG(ERROR) << "Got non-array response from GetRoutes";
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(std::move(routes));
}
void OnGetAllLogs(GetLogsCallback callback, dbus::Response* response) {
std::map<std::string, std::string> logs;
bool broken = false; // did we see a broken (k,v) pair?
dbus::MessageReader sub_reader(NULL);
if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) {
std::move(callback).Run(false, logs);
return;
}
while (sub_reader.HasMoreData()) {
dbus::MessageReader sub_sub_reader(NULL);
std::string key, value;
if (!sub_reader.PopDictEntry(&sub_sub_reader) ||
!sub_sub_reader.PopString(&key) ||
!sub_sub_reader.PopString(&value)) {
broken = true;
break;
}
logs[key] = value;
}
std::move(callback).Run(!sub_reader.HasMoreData() && !broken, logs);
}
void OnFeedbackLogsResponse(base::WeakPtr<PipeReaderWrapper> pipe_reader,
dbus::Response* response,
dbus::ErrorResponse* err_response) {
RecordGetFeedbackLogsV2DbusError(err_response);
if (!response && pipe_reader.get()) {
// We need to terminate the data stream if an error occurred while the
// pipe reader is still waiting on read.
pipe_reader->TerminateStream();
}
}
void OnFeedbackBinaryLogsResponse(chromeos::VoidDBusMethodCallback callback,
dbus::Response* response,
dbus::ErrorResponse* err_response) {
bool succeeded = !err_response;
if (!succeeded) {
LOG(ERROR) << "Failed to GetFeedbackBinaryLogs. Error: "
<< err_response->GetErrorName();
}
std::move(callback).Run(succeeded);
}
// Called when a response for a simple start is received.
void OnStartMethod(dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to request start";
return;
}
}
// Called when a response for a simple stop is received.
void OnStopMethod(dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to request stop method through D-Bus";
return;
}
}
// Called when D-Bus method call which does not return the result is
// completed or on its error.
void OnVoidMethod(chromeos::VoidDBusMethodCallback callback,
dbus::Response* response) {
std::move(callback).Run(response);
}
void OnUint64Method(chromeos::DBusMethodCallback<uint64_t> callback,
dbus::Response* response) {
if (!response) {
std::move(callback).Run(std::nullopt);
return;
}
dbus::MessageReader reader(response);
uint64_t result;
if (!reader.PopUint64(&result)) {
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(std::move(result));
}
// Called when D-Bus method call which returns a string is completed or on
// its error.
void OnStringMethod(chromeos::DBusMethodCallback<std::string> callback,
dbus::Response* response) {
if (!response) {
std::move(callback).Run(std::nullopt);
return;
}
dbus::MessageReader reader(response);
std::string result;
if (!reader.PopString(&result)) {
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(std::move(result));
}
void OnEnableDebuggingFeatures(EnableDebuggingCallback callback,
dbus::Response* response) {
if (callback.is_null())
return;
std::move(callback).Run(response != nullptr);
}
void OnQueryDebuggingFeatures(QueryDevFeaturesCallback callback,
dbus::Response* response) {
if (callback.is_null())
return;
int32_t feature_mask = DEV_FEATURE_NONE;
if (!response || !dbus::MessageReader(response).PopInt32(&feature_mask)) {
std::move(callback).Run(false,
debugd::DevFeatureFlag::DEV_FEATURES_DISABLED);
return;
}
std::move(callback).Run(true, feature_mask);
}
void OnRemoveRootfsVerification(EnableDebuggingCallback callback,
dbus::Response* response) {
if (callback.is_null())
return;
std::move(callback).Run(response != nullptr);
}
// Called when a response for StopAgentTracing() is received.
void OnStopAgentTracing(dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to request systrace stop";
// If debugd crashes or completes I/O before this message is processed
// then pipe_reader_ can be NULL, see OnIOComplete().
if (pipe_reader_.get()) {
pipe_reader_.reset();
std::move(callback_).Run(GetTracingAgentName(), GetTraceEventLabel(),
scoped_refptr<base::RefCountedString>(
new base::RefCountedString()));
}
}
// NB: requester is signaled when i/o completes
}
void OnTestICMP(TestICMPCallback callback, dbus::Response* response) {
std::string status;
if (!response || !dbus::MessageReader(response).PopString(&status)) {
std::move(callback).Run(std::nullopt);
return;
}
std::move(callback).Run(status);
}
// Called when pipe i/o completes; pass data on and delete the instance.
void OnIOComplete(std::optional<std::string> result) {
pipe_reader_.reset();
std::string pipe_data =
result.has_value() ? std::move(result).value() : std::string();
std::move(callback_).Run(
GetTracingAgentName(), GetTraceEventLabel(),
base::MakeRefCounted<base::RefCountedString>(std::move(pipe_data)));
}
void OnSetOomScoreAdj(SetOomScoreAdjCallback callback,
dbus::Response* response) {
std::string output;
if (response && dbus::MessageReader(response).PopString(&output))
std::move(callback).Run(true, output);
else
std::move(callback).Run(false, "");
}
void OnPrinterAdded(CupsAddPrinterCallback callback,
dbus::Response* response,
dbus::ErrorResponse* err_response) {
int32_t result;
// If we get a normal response, we need not examine the error response.
if (response && dbus::MessageReader(response).PopInt32(&result)) {
DCHECK_GE(result, 0);
std::move(callback).Run(result);
return;
}
// Without a normal response, we communicate the D-Bus error response
// to the callback.
std::string err_str;
if (err_response) {
dbus::MessageReader err_reader(err_response);
err_str = err_response->GetErrorName();
}
chromeos::DBusLibraryError dbus_error =
chromeos::DBusLibraryErrorFromString(err_str);
std::move(callback).Run(dbus_error);
}
void OnPrinterRemoved(CupsRemovePrinterCallback callback,
base::OnceClosure error_callback,
dbus::Response* response) {
bool result = false;
if (response && dbus::MessageReader(response).PopBool(&result))
std::move(callback).Run(result);
else
std::move(error_callback).Run();
}
void OnRetrievedPrinterPpd(CupsRetrievePrinterPpdCallback callback,
base::OnceClosure error_callback,
dbus::Response* response) {
size_t length = 0;
const uint8_t* bytes = nullptr;
if (!(response &&
dbus::MessageReader(response).PopArrayOfBytes(&bytes, &length)) ||
length == 0 || bytes == nullptr) {
LOG(ERROR) << "Failed to retrieve printer PPD";
std::move(error_callback).Run();
return;
}
std::vector<uint8_t> data(bytes, bytes + length);
std::move(callback).Run(data);
}
void OnStartPluginVmDispatcher(PluginVmDispatcherCallback callback,
dbus::Response* response,
dbus::ErrorResponse* error) {
if (error) {
LOG(ERROR) << "Failed to start dispatcher, DBus error "
<< error->GetErrorName();
std::move(callback).Run(false);
return;
}
bool result = false;
if (response) {
dbus::MessageReader reader(response);
reader.PopBool(&result);
}
std::move(callback).Run(result);
}
void OnStopPluginVmDispatcher(PluginVmDispatcherCallback callback,
dbus::Response* response) {
// Debugd just sends back an empty response, so we just check if
// the response exists
std::move(callback).Run(response != nullptr);
}
void OnSetRlzPingSent(SetRlzPingSentCallback callback,
dbus::Response* response) {
bool result = false;
if (response) {
dbus::MessageReader reader(response);
reader.PopBool(&result);
}
std::move(callback).Run(result);
}
void OnSetKstaledRatio(KstaledRatioCallback callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to read debugd response";
std::move(callback).Run(false);
return;
}
bool result = false;
dbus::MessageReader reader(response);
if (!reader.PopBool(&result)) {
LOG(ERROR) << "Debugd response did not contain a bool";
std::move(callback).Run(false);
return;
}
std::move(callback).Run(result);
}
void OnSetSchedulerConfigurationV2(
SetSchedulerConfigurationV2Callback callback,
dbus::Response* response) {
if (!response) {
std::move(callback).Run(false, 0);
return;
}
bool result = false;
uint32_t num_cores_disabled = 0;
dbus::MessageReader reader(response);
if (!reader.PopBool(&result) || !reader.PopUint32(&num_cores_disabled)) {
LOG(ERROR) << "Failed to read SetSchedulerConfigurationV2 response";
std::move(callback).Run(false, 0);
return;
}
std::move(callback).Run(result, num_cores_disabled);
}
void OnGetU2fFlags(
chromeos::DBusMethodCallback<std::set<std::string>> callback,
dbus::Response* response) {
if (!response) {
std::move(callback).Run(std::nullopt);
return;
}
std::string flags_string;
dbus::MessageReader reader(response);
if (!reader.PopString(&flags_string)) {
LOG(ERROR) << "Failed to read GetU2fFlags response";
std::move(callback).Run(std::nullopt);
return;
}
std::set<std::string> flags;
for (const auto& flag :
base::SplitString(flags_string, ",", base::TRIM_WHITESPACE,
base::SPLIT_WANT_NONEMPTY)) {
flags.insert(flag);
}
std::move(callback).Run(std::move(flags));
}
void OnBluetoothStartBtsnoop(BluetoothBtsnoopCallback callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to read debugd response";
}
std::move(callback).Run(response != nullptr);
}
void OnBluetoothStopBtsnoop(BluetoothBtsnoopCallback callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "Failed to read debugd response";
}
std::move(callback).Run(response != nullptr);
}
// Called when a D-Bus signal is initially connected.
void SignalConnected(const std::string& interface_name,
const std::string& signal_name,
bool success) {
if (!success)
LOG(ERROR) << "Failed to connect to signal " << signal_name << ".";
}
void PacketCaptureStartSignalReceived(dbus::Signal* signal) override {
for (auto& observer : observers_)
observer.OnPacketCaptureStarted();
}
void PacketCaptureStopSignalReceived(dbus::Signal* signal) override {
for (auto& observer : observers_)
observer.OnPacketCaptureStopped();
}
raw_ptr<dbus::ObjectProxy> debugdaemon_proxy_;
std::unique_ptr<chromeos::PipeReader> pipe_reader_;
StopAgentTracingCallback callback_;
scoped_refptr<base::TaskRunner> stop_agent_tracing_task_runner_;
base::ObserverList<Observer> observers_;
base::WeakPtrFactory<DebugDaemonClientImpl> weak_ptr_factory_{this};
};
} // namespace
// static
DebugDaemonClient* DebugDaemonClient::Get() {
if (g_instance_for_test)
return g_instance_for_test;
return g_instance;
}
// static
void DebugDaemonClient::Initialize(dbus::Bus* bus) {
CHECK(bus);
CHECK(!g_instance);
g_instance = new DebugDaemonClientImpl();
g_instance->Init(bus);
}
// static
void DebugDaemonClient::InitializeFake() {
CHECK(!g_instance);
g_instance = new FakeDebugDaemonClient();
g_instance->Init(nullptr);
}
// static
void DebugDaemonClient::SetInstanceForTest(DebugDaemonClient* client) {
g_instance_for_test = client;
}
// static
void DebugDaemonClient::Shutdown() {
CHECK(g_instance);
delete g_instance;
g_instance = nullptr;
}
DebugDaemonClient::DebugDaemonClient() = default;
DebugDaemonClient::~DebugDaemonClient() = default;
// static
std::unique_ptr<DebugDaemonClient> DebugDaemonClient::CreateInstance() {
return std::make_unique<DebugDaemonClientImpl>();
}
} // namespace ash
|