| 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 <unistd.h> | 8 #include <unistd.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Used in DebugDaemonClient::EmptySystemStopTracingCallback(). | 31 // Used in DebugDaemonClient::EmptySystemStopTracingCallback(). |
| 32 void EmptyStopSystemTracingCallbackBody( | 32 void EmptyStopSystemTracingCallbackBody( |
| 33 const scoped_refptr<base::RefCountedString>& unused_result) { | 33 const scoped_refptr<base::RefCountedString>& unused_result) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 // TODO(zelidrag): Move this to ChromeOS wherever place... |
| 39 namespace debugd { |
| 40 |
| 41 const char kEnableDebuggingFeatures[] = "EnableChromeDevFeatures"; |
| 42 const char kQueryDevFeatures[] = "QueryDevFeatures"; |
| 43 const char kRemoveRootfsVerification[] = "RemoveRootfsVerification"; |
| 44 |
| 45 } // namespace debugd |
| 46 |
| 38 namespace chromeos { | 47 namespace chromeos { |
| 39 | 48 |
| 40 // The DebugDaemonClient implementation used in production. | 49 // The DebugDaemonClient implementation used in production. |
| 41 class DebugDaemonClientImpl : public DebugDaemonClient { | 50 class DebugDaemonClientImpl : public DebugDaemonClient { |
| 42 public: | 51 public: |
| 43 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {} | 52 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {} |
| 44 | 53 |
| 45 virtual ~DebugDaemonClientImpl() {} | 54 virtual ~DebugDaemonClientImpl() {} |
| 46 | 55 |
| 47 // DebugDaemonClient override. | 56 // DebugDaemonClient override. |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 virtual void UploadCrashes() override { | 304 virtual void UploadCrashes() override { |
| 296 dbus::MethodCall method_call(debugd::kDebugdInterface, | 305 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 297 debugd::kUploadCrashes); | 306 debugd::kUploadCrashes); |
| 298 debugdaemon_proxy_->CallMethod( | 307 debugdaemon_proxy_->CallMethod( |
| 299 &method_call, | 308 &method_call, |
| 300 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 309 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 301 base::Bind(&DebugDaemonClientImpl::OnStartMethod, | 310 base::Bind(&DebugDaemonClientImpl::OnStartMethod, |
| 302 weak_ptr_factory_.GetWeakPtr())); | 311 weak_ptr_factory_.GetWeakPtr())); |
| 303 } | 312 } |
| 304 | 313 |
| 314 virtual void EnableDebuggingFeatures( |
| 315 const std::string& password, |
| 316 const EnableDebuggingCallback& callback) override { |
| 317 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 318 debugd::kEnableDebuggingFeatures); |
| 319 dbus::MessageWriter writer(&method_call); |
| 320 writer.AppendString(password); |
| 321 debugdaemon_proxy_->CallMethod( |
| 322 &method_call, |
| 323 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 324 base::Bind(&DebugDaemonClientImpl::OnEnableDebuggingFeatures, |
| 325 weak_ptr_factory_.GetWeakPtr(), |
| 326 callback)); |
| 327 } |
| 328 |
| 329 virtual void QueryDebuggingFeatures( |
| 330 const QueryDevFeaturesCallback& callback) override { |
| 331 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 332 debugd::kQueryDevFeatures); |
| 333 dbus::MessageWriter writer(&method_call); |
| 334 debugdaemon_proxy_->CallMethod( |
| 335 &method_call, |
| 336 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 337 base::Bind(&DebugDaemonClientImpl::OnQueryDebuggingFeatures, |
| 338 weak_ptr_factory_.GetWeakPtr(), |
| 339 callback)); |
| 340 } |
| 341 |
| 342 virtual void RemoveRootfsVerification( |
| 343 const EnableDebuggingCallback& callback) override { |
| 344 dbus::MethodCall method_call(debugd::kDebugdInterface, |
| 345 debugd::kRemoveRootfsVerification); |
| 346 dbus::MessageWriter writer(&method_call); |
| 347 debugdaemon_proxy_->CallMethod( |
| 348 &method_call, |
| 349 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 350 base::Bind(&DebugDaemonClientImpl::OnRemoveRootfsVerification, |
| 351 weak_ptr_factory_.GetWeakPtr(), |
| 352 callback)); |
| 353 } |
| 354 |
| 305 protected: | 355 protected: |
| 306 virtual void Init(dbus::Bus* bus) override { | 356 virtual void Init(dbus::Bus* bus) override { |
| 307 debugdaemon_proxy_ = | 357 debugdaemon_proxy_ = |
| 308 bus->GetObjectProxy(debugd::kDebugdServiceName, | 358 bus->GetObjectProxy(debugd::kDebugdServiceName, |
| 309 dbus::ObjectPath(debugd::kDebugdServicePath)); | 359 dbus::ObjectPath(debugd::kDebugdServicePath)); |
| 310 } | 360 } |
| 311 | 361 |
| 312 private: | 362 private: |
| 313 // Called when a CheckValidity response is received. | 363 // Called when a CheckValidity response is received. |
| 314 void OnCheckValidityGetDebugLogs(bool is_compressed, | 364 void OnCheckValidityGetDebugLogs(bool is_compressed, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 } | 502 } |
| 453 | 503 |
| 454 // Called when a response for a simple start is received. | 504 // Called when a response for a simple start is received. |
| 455 void OnStartMethod(dbus::Response* response) { | 505 void OnStartMethod(dbus::Response* response) { |
| 456 if (!response) { | 506 if (!response) { |
| 457 LOG(ERROR) << "Failed to request start"; | 507 LOG(ERROR) << "Failed to request start"; |
| 458 return; | 508 return; |
| 459 } | 509 } |
| 460 } | 510 } |
| 461 | 511 |
| 512 void OnEnableDebuggingFeatures( |
| 513 const EnableDebuggingCallback& callback, |
| 514 dbus::Response* response) { |
| 515 if (callback.is_null()) |
| 516 return; |
| 517 |
| 518 callback.Run(response != NULL); |
| 519 } |
| 520 |
| 521 void OnQueryDebuggingFeatures( |
| 522 const QueryDevFeaturesCallback& callback, |
| 523 dbus::Response* response) { |
| 524 if (callback.is_null()) |
| 525 return; |
| 526 |
| 527 int32 feature_mask = DEV_FEATURE_NONE; |
| 528 if (!response || !dbus::MessageReader(response).PopInt32(&feature_mask)) { |
| 529 callback.Run(false, DEV_FEATURES_DISABLED); |
| 530 return; |
| 531 } |
| 532 |
| 533 callback.Run(true, feature_mask); |
| 534 } |
| 535 |
| 536 void OnRemoveRootfsVerification( |
| 537 const EnableDebuggingCallback& callback, |
| 538 dbus::Response* response) { |
| 539 if (callback.is_null()) |
| 540 return; |
| 541 |
| 542 callback.Run(response != NULL); |
| 543 } |
| 544 |
| 462 // Creates dbus::FileDescriptor from base::File. | 545 // Creates dbus::FileDescriptor from base::File. |
| 463 static scoped_ptr<dbus::FileDescriptor> | 546 static scoped_ptr<dbus::FileDescriptor> |
| 464 CreateFileDescriptorToStopSystemTracing(base::File pipe_write_end) { | 547 CreateFileDescriptorToStopSystemTracing(base::File pipe_write_end) { |
| 465 if (!pipe_write_end.IsValid()) { | 548 if (!pipe_write_end.IsValid()) { |
| 466 LOG(ERROR) << "Cannot create pipe reader"; | 549 LOG(ERROR) << "Cannot create pipe reader"; |
| 467 // NB: continue anyway to shutdown tracing; toss trace data | 550 // NB: continue anyway to shutdown tracing; toss trace data |
| 468 pipe_write_end.Initialize(base::FilePath(FILE_PATH_LITERAL("/dev/null")), | 551 pipe_write_end.Initialize(base::FilePath(FILE_PATH_LITERAL("/dev/null")), |
| 469 base::File::FLAG_OPEN | base::File::FLAG_WRITE); | 552 base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
| 470 // TODO(sleffler) if this fails AppendFileDescriptor will abort | 553 // TODO(sleffler) if this fails AppendFileDescriptor will abort |
| 471 } | 554 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 DebugDaemonClient::EmptyStopSystemTracingCallback() { | 628 DebugDaemonClient::EmptyStopSystemTracingCallback() { |
| 546 return base::Bind(&EmptyStopSystemTracingCallbackBody); | 629 return base::Bind(&EmptyStopSystemTracingCallbackBody); |
| 547 } | 630 } |
| 548 | 631 |
| 549 // static | 632 // static |
| 550 DebugDaemonClient* DebugDaemonClient::Create() { | 633 DebugDaemonClient* DebugDaemonClient::Create() { |
| 551 return new DebugDaemonClientImpl(); | 634 return new DebugDaemonClientImpl(); |
| 552 } | 635 } |
| 553 | 636 |
| 554 } // namespace chromeos | 637 } // namespace chromeos |
| OLD | NEW |