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 namespace debugd { | |
39 | |
40 const char kEnableDebuggingFeatures[] = "EnableChromeDevFeatures"; | |
41 const char kRemoveRootfsVerification[] = "RemoveRootfsVerification"; | |
42 | |
43 } | |
xiyuan
2014/10/30 03:52:09
nit: } // namespace debugd
zel
2014/10/31 01:22:26
Done.
| |
44 | |
38 namespace chromeos { | 45 namespace chromeos { |
39 | 46 |
40 // The DebugDaemonClient implementation used in production. | 47 // The DebugDaemonClient implementation used in production. |
41 class DebugDaemonClientImpl : public DebugDaemonClient { | 48 class DebugDaemonClientImpl : public DebugDaemonClient { |
42 public: | 49 public: |
43 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {} | 50 DebugDaemonClientImpl() : debugdaemon_proxy_(NULL), weak_ptr_factory_(this) {} |
44 | 51 |
45 virtual ~DebugDaemonClientImpl() {} | 52 virtual ~DebugDaemonClientImpl() {} |
46 | 53 |
47 // DebugDaemonClient override. | 54 // DebugDaemonClient override. |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 virtual void UploadCrashes() override { | 302 virtual void UploadCrashes() override { |
296 dbus::MethodCall method_call(debugd::kDebugdInterface, | 303 dbus::MethodCall method_call(debugd::kDebugdInterface, |
297 debugd::kUploadCrashes); | 304 debugd::kUploadCrashes); |
298 debugdaemon_proxy_->CallMethod( | 305 debugdaemon_proxy_->CallMethod( |
299 &method_call, | 306 &method_call, |
300 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 307 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
301 base::Bind(&DebugDaemonClientImpl::OnStartMethod, | 308 base::Bind(&DebugDaemonClientImpl::OnStartMethod, |
302 weak_ptr_factory_.GetWeakPtr())); | 309 weak_ptr_factory_.GetWeakPtr())); |
303 } | 310 } |
304 | 311 |
312 virtual void EnableDebuggingFeatures( | |
313 const std::string& password, | |
314 const EnableDebuggingCallback& callback) override { | |
315 dbus::MethodCall method_call(debugd::kDebugdInterface, | |
316 debugd::kEnableDebuggingFeatures); | |
317 dbus::MessageWriter writer(&method_call); | |
318 writer.AppendString(password); | |
319 debugdaemon_proxy_->CallMethod( | |
320 &method_call, | |
321 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
322 base::Bind(&DebugDaemonClientImpl::OnEnableDebuggingFeatures, | |
323 weak_ptr_factory_.GetWeakPtr(), | |
324 callback)); | |
325 } | |
326 | |
327 | |
328 virtual void RemoveRootfsVerification( | |
xiyuan
2014/10/30 03:52:09
nit: move this before EnableDebuggingFeatures to m
zel
2014/10/31 01:22:26
Done.
| |
329 const EnableDebuggingCallback& callback) override { | |
330 dbus::MethodCall method_call(debugd::kDebugdInterface, | |
331 debugd::kRemoveRootfsVerification); | |
332 dbus::MessageWriter writer(&method_call); | |
333 debugdaemon_proxy_->CallMethod( | |
334 &method_call, | |
335 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
336 base::Bind(&DebugDaemonClientImpl::OnRemoveRootfsVerification, | |
337 weak_ptr_factory_.GetWeakPtr(), | |
338 callback)); | |
339 } | |
340 | |
305 protected: | 341 protected: |
306 virtual void Init(dbus::Bus* bus) override { | 342 virtual void Init(dbus::Bus* bus) override { |
307 debugdaemon_proxy_ = | 343 debugdaemon_proxy_ = |
308 bus->GetObjectProxy(debugd::kDebugdServiceName, | 344 bus->GetObjectProxy(debugd::kDebugdServiceName, |
309 dbus::ObjectPath(debugd::kDebugdServicePath)); | 345 dbus::ObjectPath(debugd::kDebugdServicePath)); |
310 } | 346 } |
311 | 347 |
312 private: | 348 private: |
313 // Called when a CheckValidity response is received. | 349 // Called when a CheckValidity response is received. |
314 void OnCheckValidityGetDebugLogs(bool is_compressed, | 350 void OnCheckValidityGetDebugLogs(bool is_compressed, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 } | 488 } |
453 | 489 |
454 // Called when a response for a simple start is received. | 490 // Called when a response for a simple start is received. |
455 void OnStartMethod(dbus::Response* response) { | 491 void OnStartMethod(dbus::Response* response) { |
456 if (!response) { | 492 if (!response) { |
457 LOG(ERROR) << "Failed to request start"; | 493 LOG(ERROR) << "Failed to request start"; |
458 return; | 494 return; |
459 } | 495 } |
460 } | 496 } |
461 | 497 |
498 void OnEnableDebuggingFeatures( | |
499 const EnableDebuggingCallback& callback, | |
500 dbus::Response* response) { | |
501 if (callback.is_null()) | |
502 return; | |
503 | |
504 callback.Run(response != NULL); | |
505 } | |
506 | |
507 void OnRemoveRootfsVerification( | |
508 const EnableDebuggingCallback& callback, | |
509 dbus::Response* response) { | |
510 if (callback.is_null()) | |
511 return; | |
512 | |
513 bool success = false; | |
514 if (!response || !dbus::MessageReader(response).PopBool(&success)) { | |
515 callback.Run(false); | |
516 return; | |
517 } | |
518 | |
519 callback.Run(success); | |
520 } | |
521 | |
462 // Creates dbus::FileDescriptor from base::File. | 522 // Creates dbus::FileDescriptor from base::File. |
463 static scoped_ptr<dbus::FileDescriptor> | 523 static scoped_ptr<dbus::FileDescriptor> |
464 CreateFileDescriptorToStopSystemTracing(base::File pipe_write_end) { | 524 CreateFileDescriptorToStopSystemTracing(base::File pipe_write_end) { |
465 if (!pipe_write_end.IsValid()) { | 525 if (!pipe_write_end.IsValid()) { |
466 LOG(ERROR) << "Cannot create pipe reader"; | 526 LOG(ERROR) << "Cannot create pipe reader"; |
467 // NB: continue anyway to shutdown tracing; toss trace data | 527 // NB: continue anyway to shutdown tracing; toss trace data |
468 pipe_write_end.Initialize(base::FilePath(FILE_PATH_LITERAL("/dev/null")), | 528 pipe_write_end.Initialize(base::FilePath(FILE_PATH_LITERAL("/dev/null")), |
469 base::File::FLAG_OPEN | base::File::FLAG_WRITE); | 529 base::File::FLAG_OPEN | base::File::FLAG_WRITE); |
470 // TODO(sleffler) if this fails AppendFileDescriptor will abort | 530 // TODO(sleffler) if this fails AppendFileDescriptor will abort |
471 } | 531 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
545 DebugDaemonClient::EmptyStopSystemTracingCallback() { | 605 DebugDaemonClient::EmptyStopSystemTracingCallback() { |
546 return base::Bind(&EmptyStopSystemTracingCallbackBody); | 606 return base::Bind(&EmptyStopSystemTracingCallbackBody); |
547 } | 607 } |
548 | 608 |
549 // static | 609 // static |
550 DebugDaemonClient* DebugDaemonClient::Create() { | 610 DebugDaemonClient* DebugDaemonClient::Create() { |
551 return new DebugDaemonClientImpl(); | 611 return new DebugDaemonClientImpl(); |
552 } | 612 } |
553 | 613 |
554 } // namespace chromeos | 614 } // namespace chromeos |
OLD | NEW |