| 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 "dbus/test_service.h" | 5 #include "dbus/test_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
| 10 #include "dbus/bus.h" | 10 #include "dbus/bus.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 void TestService::OnOwnership(base::Callback<void(bool)> callback, | 135 void TestService::OnOwnership(base::Callback<void(bool)> callback, |
| 136 const std::string& service_name, | 136 const std::string& service_name, |
| 137 bool success) { | 137 bool success) { |
| 138 has_ownership_ = success; | 138 has_ownership_ = success; |
| 139 LOG_IF(ERROR, !success) << "Failed to own: " << service_name; | 139 LOG_IF(ERROR, !success) << "Failed to own: " << service_name; |
| 140 callback.Run(success); | 140 callback.Run(success); |
| 141 | 141 |
| 142 on_name_obtained_.Signal(); | 142 on_name_obtained_.Signal(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void TestService::ReleaseOwnership(base::Closure callback) { |
| 146 bus_->GetDBusTaskRunner()->PostTask( |
| 147 FROM_HERE, |
| 148 base::Bind(&TestService::ReleaseOwnershipInternal, |
| 149 base::Unretained(this), |
| 150 callback)); |
| 151 } |
| 152 |
| 153 void TestService::ReleaseOwnershipInternal( |
| 154 base::Closure callback) { |
| 155 bus_->ReleaseOwnership("org.chromium.TestService"); |
| 156 has_ownership_ = false; |
| 157 |
| 158 bus_->GetOriginTaskRunner()->PostTask( |
| 159 FROM_HERE, |
| 160 callback); |
| 161 } |
| 162 |
| 145 void TestService::OnExported(const std::string& interface_name, | 163 void TestService::OnExported(const std::string& interface_name, |
| 146 const std::string& method_name, | 164 const std::string& method_name, |
| 147 bool success) { | 165 bool success) { |
| 148 if (!success) { | 166 if (!success) { |
| 149 LOG(ERROR) << "Failed to export: " << interface_name << "." | 167 LOG(ERROR) << "Failed to export: " << interface_name << "." |
| 150 << method_name; | 168 << method_name; |
| 151 // Returning here will make WaitUntilServiceIsStarted() to time out | 169 // Returning here will make WaitUntilServiceIsStarted() to time out |
| 152 // and return false. | 170 // and return false. |
| 153 return; | 171 return; |
| 154 } | 172 } |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 ObjectPath object_path; | 454 ObjectPath object_path; |
| 437 if (!reader.PopString(&action) || !reader.PopObjectPath(&object_path)) { | 455 if (!reader.PopString(&action) || !reader.PopObjectPath(&object_path)) { |
| 438 response_sender.Run(scoped_ptr<Response>()); | 456 response_sender.Run(scoped_ptr<Response>()); |
| 439 return; | 457 return; |
| 440 } | 458 } |
| 441 | 459 |
| 442 if (action == "AddObject") | 460 if (action == "AddObject") |
| 443 AddObject(object_path); | 461 AddObject(object_path); |
| 444 else if (action == "RemoveObject") | 462 else if (action == "RemoveObject") |
| 445 RemoveObject(object_path); | 463 RemoveObject(object_path); |
| 464 else if (action == "ReleaseOwnership") { |
| 465 ReleaseOwnership(base::Bind(&TestService::PerformActionResponse, |
| 466 base::Unretained(this), |
| 467 method_call, response_sender)); |
| 468 return; |
| 469 } else if (action == "Ownership") { |
| 470 ReleaseOwnership(base::Bind(&TestService::OwnershipReleased, |
| 471 base::Unretained(this), |
| 472 method_call, response_sender)); |
| 473 return; |
| 474 } |
| 446 | 475 |
| 447 scoped_ptr<Response> response = Response::FromMethodCall(method_call); | 476 scoped_ptr<Response> response = Response::FromMethodCall(method_call); |
| 448 response_sender.Run(response.Pass()); | 477 response_sender.Run(response.Pass()); |
| 449 } | 478 } |
| 450 | 479 |
| 480 void TestService::PerformActionResponse( |
| 481 MethodCall* method_call, |
| 482 ExportedObject::ResponseSender response_sender) { |
| 483 scoped_ptr<Response> response = Response::FromMethodCall(method_call); |
| 484 response_sender.Run(response.Pass()); |
| 485 } |
| 486 |
| 487 void TestService::OwnershipReleased( |
| 488 MethodCall* method_call, |
| 489 ExportedObject::ResponseSender response_sender) { |
| 490 RequestOwnership(base::Bind(&TestService::OwnershipRegained, |
| 491 base::Unretained(this), |
| 492 method_call, response_sender)); |
| 493 } |
| 494 |
| 495 |
| 496 void TestService::OwnershipRegained( |
| 497 MethodCall* method_call, |
| 498 ExportedObject::ResponseSender response_sender, |
| 499 bool success) { |
| 500 PerformActionResponse(method_call, response_sender); |
| 501 } |
| 502 |
| 503 |
| 451 void TestService::GetManagedObjects( | 504 void TestService::GetManagedObjects( |
| 452 MethodCall* method_call, | 505 MethodCall* method_call, |
| 453 ExportedObject::ResponseSender response_sender) { | 506 ExportedObject::ResponseSender response_sender) { |
| 454 scoped_ptr<Response> response = Response::FromMethodCall(method_call); | 507 scoped_ptr<Response> response = Response::FromMethodCall(method_call); |
| 455 MessageWriter writer(response.get()); | 508 MessageWriter writer(response.get()); |
| 456 | 509 |
| 457 // The managed objects response is a dictionary of object paths identifying | 510 // The managed objects response is a dictionary of object paths identifying |
| 458 // the object(s) with a dictionary of strings identifying the interface(s) | 511 // the object(s) with a dictionary of strings identifying the interface(s) |
| 459 // they implement and then a dictionary of property values. | 512 // they implement and then a dictionary of property values. |
| 460 // | 513 // |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 array_writer.OpenDictEntry(&dict_entry_writer); | 663 array_writer.OpenDictEntry(&dict_entry_writer); |
| 611 dict_entry_writer.AppendString("Name"); | 664 dict_entry_writer.AppendString("Name"); |
| 612 dict_entry_writer.AppendVariantOfString(name); | 665 dict_entry_writer.AppendVariantOfString(name); |
| 613 array_writer.CloseContainer(&dict_entry_writer); | 666 array_writer.CloseContainer(&dict_entry_writer); |
| 614 writer.CloseContainer(&array_writer); | 667 writer.CloseContainer(&array_writer); |
| 615 | 668 |
| 616 exported_object_->SendSignal(&signal); | 669 exported_object_->SendSignal(&signal); |
| 617 } | 670 } |
| 618 | 671 |
| 619 } // namespace dbus | 672 } // namespace dbus |
| OLD | NEW |