| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 dbus::MethodCall method_call(debugd::kDebugdInterface, | 239 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 240 debugd::kGetInterfaces); | 240 debugd::kGetInterfaces); |
| 241 debugdaemon_proxy_->CallMethod( | 241 debugdaemon_proxy_->CallMethod( |
| 242 &method_call, | 242 &method_call, |
| 243 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 243 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 244 base::Bind(&DebugDaemonClientImpl::OnGetNetworkInterfaces, | 244 base::Bind(&DebugDaemonClientImpl::OnGetNetworkInterfaces, |
| 245 weak_ptr_factory_.GetWeakPtr(), | 245 weak_ptr_factory_.GetWeakPtr(), |
| 246 callback)); | 246 callback)); |
| 247 } | 247 } |
| 248 | 248 |
| 249 virtual void GetAllLogs(const GetAllLogsCallback& callback) | 249 virtual void GetAllLogs(const GetLogsCallback& callback) |
| 250 OVERRIDE { | 250 OVERRIDE { |
| 251 dbus::MethodCall method_call(debugd::kDebugdInterface, | 251 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 252 "GetAllLogs"); | 252 debugd::kGetAllLogs); |
| 253 debugdaemon_proxy_->CallMethod( | 253 debugdaemon_proxy_->CallMethod( |
| 254 &method_call, | 254 &method_call, |
| 255 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 255 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 256 base::Bind(&DebugDaemonClientImpl::OnGetAllLogs, | 256 base::Bind(&DebugDaemonClientImpl::OnGetAllLogs, |
| 257 weak_ptr_factory_.GetWeakPtr(), | 257 weak_ptr_factory_.GetWeakPtr(), |
| 258 callback)); | 258 callback)); |
| 259 } | 259 } |
| 260 | 260 |
| 261 virtual void GetUserLogFiles( |
| 262 const GetLogsCallback& callback) OVERRIDE { |
| 263 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 264 debugd::kGetUserLogFiles); |
| 265 debugdaemon_proxy_->CallMethod( |
| 266 &method_call, |
| 267 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 268 base::Bind(&DebugDaemonClientImpl::OnGetUserLogFiles, |
| 269 weak_ptr_factory_.GetWeakPtr(), |
| 270 callback)); |
| 271 } |
| 272 |
| 261 virtual void StartSystemTracing() OVERRIDE { | 273 virtual void StartSystemTracing() OVERRIDE { |
| 262 dbus::MethodCall method_call( | 274 dbus::MethodCall method_call( |
| 263 debugd::kDebugdInterface, | 275 debugd::kDebugdInterface, |
| 264 debugd::kSystraceStart); | 276 debugd::kSystraceStart); |
| 265 dbus::MessageWriter writer(&method_call); | 277 dbus::MessageWriter writer(&method_call); |
| 266 writer.AppendString("all"); // TODO(sleffler) parameterize category list | 278 writer.AppendString("all"); // TODO(sleffler) parameterize category list |
| 267 | 279 |
| 268 DVLOG(1) << "Requesting a systrace start"; | 280 DVLOG(1) << "Requesting a systrace start"; |
| 269 debugdaemon_proxy_->CallMethod( | 281 debugdaemon_proxy_->CallMethod( |
| 270 &method_call, | 282 &method_call, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 void OnGetNetworkStatus(const GetNetworkStatusCallback& callback, | 400 void OnGetNetworkStatus(const GetNetworkStatusCallback& callback, |
| 389 dbus::Response* response) { | 401 dbus::Response* response) { |
| 390 std::string status; | 402 std::string status; |
| 391 if (response && dbus::MessageReader(response).PopString(&status)) | 403 if (response && dbus::MessageReader(response).PopString(&status)) |
| 392 callback.Run(true, status); | 404 callback.Run(true, status); |
| 393 else | 405 else |
| 394 callback.Run(false, ""); | 406 callback.Run(false, ""); |
| 395 } | 407 } |
| 396 | 408 |
| 397 void OnGetModemStatus(const GetModemStatusCallback& callback, | 409 void OnGetModemStatus(const GetModemStatusCallback& callback, |
| 398 dbus::Response* response) { | 410 dbus::Response* response) { |
| 399 std::string status; | 411 std::string status; |
| 400 if (response && dbus::MessageReader(response).PopString(&status)) | 412 if (response && dbus::MessageReader(response).PopString(&status)) |
| 401 callback.Run(true, status); | 413 callback.Run(true, status); |
| 402 else | 414 else |
| 403 callback.Run(false, ""); | 415 callback.Run(false, ""); |
| 404 } | 416 } |
| 405 | 417 |
| 406 void OnGetNetworkInterfaces(const GetNetworkInterfacesCallback& callback, | 418 void OnGetNetworkInterfaces(const GetNetworkInterfacesCallback& callback, |
| 407 dbus::Response* response) { | 419 dbus::Response* response) { |
| 408 std::string status; | 420 std::string status; |
| 409 if (response && dbus::MessageReader(response).PopString(&status)) | 421 if (response && dbus::MessageReader(response).PopString(&status)) |
| 410 callback.Run(true, status); | 422 callback.Run(true, status); |
| 411 else | 423 else |
| 412 callback.Run(false, ""); | 424 callback.Run(false, ""); |
| 413 } | 425 } |
| 414 | 426 |
| 415 void OnGetAllLogs(const GetAllLogsCallback& callback, | 427 void OnGetAllLogs(const GetLogsCallback& callback, |
| 416 dbus::Response* response) { | 428 dbus::Response* response) { |
| 417 std::map<std::string, std::string> logs; | 429 std::map<std::string, std::string> logs; |
| 418 bool broken = false; // did we see a broken (k,v) pair? | 430 bool broken = false; // did we see a broken (k,v) pair? |
| 419 dbus::MessageReader sub_reader(NULL); | 431 dbus::MessageReader sub_reader(NULL); |
| 420 if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) { | 432 if (!response || !dbus::MessageReader(response).PopArray(&sub_reader)) { |
| 421 callback.Run(false, logs); | 433 callback.Run(false, logs); |
| 422 return; | 434 return; |
| 423 } | 435 } |
| 424 while (sub_reader.HasMoreData()) { | 436 while (sub_reader.HasMoreData()) { |
| 425 dbus::MessageReader sub_sub_reader(NULL); | 437 dbus::MessageReader sub_sub_reader(NULL); |
| 426 std::string key, value; | 438 std::string key, value; |
| 427 if (!sub_reader.PopDictEntry(&sub_sub_reader) | 439 if (!sub_reader.PopDictEntry(&sub_sub_reader) |
| 428 || !sub_sub_reader.PopString(&key) | 440 || !sub_sub_reader.PopString(&key) |
| 429 || !sub_sub_reader.PopString(&value)) { | 441 || !sub_sub_reader.PopString(&value)) { |
| 430 broken = true; | 442 broken = true; |
| 431 break; | 443 break; |
| 432 } | 444 } |
| 433 logs[key] = value; | 445 logs[key] = value; |
| 434 } | 446 } |
| 435 callback.Run(!sub_reader.HasMoreData() && !broken, logs); | 447 callback.Run(!sub_reader.HasMoreData() && !broken, logs); |
| 436 } | 448 } |
| 437 | 449 |
| 450 void OnGetUserLogFiles(const GetLogsCallback& callback, |
| 451 dbus::Response* response) { |
| 452 return OnGetAllLogs(callback, response); |
| 453 } |
| 454 |
| 438 // Called when a response for StartSystemTracing() is received. | 455 // Called when a response for StartSystemTracing() is received. |
| 439 void OnStartSystemTracing(dbus::Response* response) { | 456 void OnStartSystemTracing(dbus::Response* response) { |
| 440 if (!response) { | 457 if (!response) { |
| 441 LOG(ERROR) << "Failed to request systrace start"; | 458 LOG(ERROR) << "Failed to request systrace start"; |
| 442 return; | 459 return; |
| 443 } | 460 } |
| 444 } | 461 } |
| 445 | 462 |
| 446 // Called when a CheckValidity response is received. | 463 // Called when a CheckValidity response is received. |
| 447 void OnCheckValidityRequestStopSystem( | 464 void OnCheckValidityRequestStopSystem( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 callback.Run(false, ""); | 546 callback.Run(false, ""); |
| 530 } | 547 } |
| 531 virtual void GetModemStatus(const GetModemStatusCallback& callback) | 548 virtual void GetModemStatus(const GetModemStatusCallback& callback) |
| 532 OVERRIDE { | 549 OVERRIDE { |
| 533 callback.Run(false, ""); | 550 callback.Run(false, ""); |
| 534 } | 551 } |
| 535 virtual void GetNetworkInterfaces( | 552 virtual void GetNetworkInterfaces( |
| 536 const GetNetworkInterfacesCallback& callback) OVERRIDE { | 553 const GetNetworkInterfacesCallback& callback) OVERRIDE { |
| 537 callback.Run(false, ""); | 554 callback.Run(false, ""); |
| 538 } | 555 } |
| 539 virtual void GetAllLogs(const GetAllLogsCallback& callback) OVERRIDE { | 556 virtual void GetAllLogs(const GetLogsCallback& callback) OVERRIDE { |
| 540 std::map<std::string, std::string> empty; | 557 std::map<std::string, std::string> empty; |
| 541 callback.Run(false, empty); | 558 callback.Run(false, empty); |
| 542 } | 559 } |
| 560 virtual void GetUserLogFiles(const GetLogsCallback& callback) OVERRIDE { |
| 561 std::map<std::string, std::string> empty; |
| 562 callback.Run(false, empty); |
| 563 } |
| 543 | 564 |
| 544 virtual void TestICMP(const std::string& ip_address, | 565 virtual void TestICMP(const std::string& ip_address, |
| 545 const TestICMPCallback& callback) OVERRIDE { | 566 const TestICMPCallback& callback) OVERRIDE { |
| 546 callback.Run(false, ""); | 567 callback.Run(false, ""); |
| 547 } | 568 } |
| 548 }; | 569 }; |
| 549 | 570 |
| 550 DebugDaemonClient::DebugDaemonClient() { | 571 DebugDaemonClient::DebugDaemonClient() { |
| 551 } | 572 } |
| 552 | 573 |
| 553 DebugDaemonClient::~DebugDaemonClient() { | 574 DebugDaemonClient::~DebugDaemonClient() { |
| 554 } | 575 } |
| 555 | 576 |
| 556 // static | 577 // static |
| 557 DebugDaemonClient::StopSystemTracingCallback | 578 DebugDaemonClient::StopSystemTracingCallback |
| 558 DebugDaemonClient::EmptyStopSystemTracingCallback() { | 579 DebugDaemonClient::EmptyStopSystemTracingCallback() { |
| 559 return base::Bind(&EmptyStopSystemTracingCallbackBody); | 580 return base::Bind(&EmptyStopSystemTracingCallbackBody); |
| 560 } | 581 } |
| 561 | 582 |
| 562 // static | 583 // static |
| 563 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, | 584 DebugDaemonClient* DebugDaemonClient::Create(DBusClientImplementationType type, |
| 564 dbus::Bus* bus) { | 585 dbus::Bus* bus) { |
| 565 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 586 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 566 return new DebugDaemonClientImpl(bus); | 587 return new DebugDaemonClientImpl(bus); |
| 567 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 588 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 568 return new DebugDaemonClientStubImpl(); | 589 return new DebugDaemonClientStubImpl(); |
| 569 } | 590 } |
| 570 | 591 |
| 571 } // namespace chromeos | 592 } // namespace chromeos |
| OLD | NEW |