| 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" |
| 11 #include "dbus/exported_object.h" | 11 #include "dbus/exported_object.h" |
| 12 #include "dbus/message.h" | 12 #include "dbus/message.h" |
| 13 #include "dbus/object_manager.h" | 13 #include "dbus/object_manager.h" |
| 14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
| 15 #include "dbus/property.h" | 15 #include "dbus/property.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 void EmptyCallback(bool /* success */) { | 19 void EmptyCallback(bool /* success */) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 namespace dbus { | 24 namespace dbus { |
| 25 | 25 |
| 26 // Echo, SlowEcho, AsyncEcho, BrokenMethod, GetAll, Get, Set, PerformAction, | 26 // Echo, SlowEcho, AsyncEcho, BrokenMethod, GetAll, Get, Set, PerformAction, |
| 27 // GetManagedObjects. | 27 // GetManagedObjects |
| 28 const int TestService::kNumMethodsToExport = 9; | 28 const int TestService::kNumMethodsToExport = 9; |
| 29 | 29 |
| 30 TestService::Options::Options() | 30 TestService::Options::Options() |
| 31 : request_ownership_options(Bus::REQUIRE_PRIMARY) { | 31 : request_ownership_options(Bus::REQUIRE_PRIMARY) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 TestService::Options::~Options() { | 34 TestService::Options::~Options() { |
| 35 } | 35 } |
| 36 | 36 |
| 37 TestService::TestService(const Options& options) | 37 TestService::TestService(const Options& options) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void TestService::ReleaseOwnershipInternal( | 153 void TestService::ReleaseOwnershipInternal( |
| 154 base::Closure callback) { | 154 base::Closure callback) { |
| 155 bus_->ReleaseOwnership("org.chromium.TestService"); | 155 bus_->ReleaseOwnership("org.chromium.TestService"); |
| 156 has_ownership_ = false; | 156 has_ownership_ = false; |
| 157 | 157 |
| 158 bus_->GetOriginTaskRunner()->PostTask( | 158 bus_->GetOriginTaskRunner()->PostTask( |
| 159 FROM_HERE, | 159 FROM_HERE, |
| 160 callback); | 160 callback); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void TestService::SetSendImmediatePropertiesChanged() { |
| 164 send_immediate_properties_changed_ = true; |
| 165 } |
| 166 |
| 163 void TestService::OnExported(const std::string& interface_name, | 167 void TestService::OnExported(const std::string& interface_name, |
| 164 const std::string& method_name, | 168 const std::string& method_name, |
| 165 bool success) { | 169 bool success) { |
| 166 if (!success) { | 170 if (!success) { |
| 167 LOG(ERROR) << "Failed to export: " << interface_name << "." | 171 LOG(ERROR) << "Failed to export: " << interface_name << "." |
| 168 << method_name; | 172 << method_name; |
| 169 // Returning here will make WaitUntilServiceIsStarted() to time out | 173 // Returning here will make WaitUntilServiceIsStarted() to time out |
| 170 // and return false. | 174 // and return false. |
| 171 return; | 175 return; |
| 172 } | 176 } |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 MethodCall* method_call, | 468 MethodCall* method_call, |
| 465 ExportedObject::ResponseSender response_sender) { | 469 ExportedObject::ResponseSender response_sender) { |
| 466 MessageReader reader(method_call); | 470 MessageReader reader(method_call); |
| 467 std::string action; | 471 std::string action; |
| 468 ObjectPath object_path; | 472 ObjectPath object_path; |
| 469 if (!reader.PopString(&action) || !reader.PopObjectPath(&object_path)) { | 473 if (!reader.PopString(&action) || !reader.PopObjectPath(&object_path)) { |
| 470 response_sender.Run(scoped_ptr<Response>()); | 474 response_sender.Run(scoped_ptr<Response>()); |
| 471 return; | 475 return; |
| 472 } | 476 } |
| 473 | 477 |
| 474 if (action == "AddObject") | 478 if (action == "AddObject") { |
| 475 AddObject(object_path); | 479 AddObject(object_path); |
| 476 else if (action == "RemoveObject") | 480 } else if (action == "RemoveObject") { |
| 477 RemoveObject(object_path); | 481 RemoveObject(object_path); |
| 478 else if (action == "ReleaseOwnership") { | 482 } else if (action == "SetSendImmediatePropertiesChanged") { |
| 483 SetSendImmediatePropertiesChanged(); |
| 484 } if (action == "ReleaseOwnership") { |
| 479 ReleaseOwnership(base::Bind(&TestService::PerformActionResponse, | 485 ReleaseOwnership(base::Bind(&TestService::PerformActionResponse, |
| 480 base::Unretained(this), | 486 base::Unretained(this), |
| 481 method_call, response_sender)); | 487 method_call, response_sender)); |
| 482 return; | 488 return; |
| 483 } else if (action == "Ownership") { | 489 } else if (action == "Ownership") { |
| 484 ReleaseOwnership(base::Bind(&TestService::OwnershipReleased, | 490 ReleaseOwnership(base::Bind(&TestService::OwnershipReleased, |
| 485 base::Unretained(this), | 491 base::Unretained(this), |
| 486 method_call, response_sender)); | 492 method_call, response_sender)); |
| 487 return; | 493 return; |
| 488 } | 494 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 object_dict_entry_writer.AppendString("org.chromium.TestInterface"); | 555 object_dict_entry_writer.AppendString("org.chromium.TestInterface"); |
| 550 AddPropertiesToWriter(&object_dict_entry_writer); | 556 AddPropertiesToWriter(&object_dict_entry_writer); |
| 551 object_array_writer.CloseContainer(&object_dict_entry_writer); | 557 object_array_writer.CloseContainer(&object_dict_entry_writer); |
| 552 | 558 |
| 553 dict_entry_writer.CloseContainer(&object_array_writer); | 559 dict_entry_writer.CloseContainer(&object_array_writer); |
| 554 | 560 |
| 555 array_writer.CloseContainer(&dict_entry_writer); | 561 array_writer.CloseContainer(&dict_entry_writer); |
| 556 writer.CloseContainer(&array_writer); | 562 writer.CloseContainer(&array_writer); |
| 557 | 563 |
| 558 response_sender.Run(response.Pass()); | 564 response_sender.Run(response.Pass()); |
| 565 |
| 566 if (send_immediate_properties_changed_) |
| 567 SendPropertyChangedSignal("ChangedTestServiceName"); |
| 559 } | 568 } |
| 560 | 569 |
| 561 void TestService::AddPropertiesToWriter(MessageWriter* writer) { | 570 void TestService::AddPropertiesToWriter(MessageWriter* writer) { |
| 562 // The properties response is a dictionary of strings identifying the | 571 // The properties response is a dictionary of strings identifying the |
| 563 // property and a variant containing the property value. We return all | 572 // property and a variant containing the property value. We return all |
| 564 // of the properties, thus the response is: | 573 // of the properties, thus the response is: |
| 565 // | 574 // |
| 566 // { | 575 // { |
| 567 // "Name": Variant<"TestService">, | 576 // "Name": Variant<"TestService">, |
| 568 // "Version": Variant<10>, | 577 // "Version": Variant<10>, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 array_writer.OpenDictEntry(&dict_entry_writer); | 695 array_writer.OpenDictEntry(&dict_entry_writer); |
| 687 dict_entry_writer.AppendString("Name"); | 696 dict_entry_writer.AppendString("Name"); |
| 688 dict_entry_writer.AppendVariantOfString(name); | 697 dict_entry_writer.AppendVariantOfString(name); |
| 689 array_writer.CloseContainer(&dict_entry_writer); | 698 array_writer.CloseContainer(&dict_entry_writer); |
| 690 writer.CloseContainer(&array_writer); | 699 writer.CloseContainer(&array_writer); |
| 691 | 700 |
| 692 exported_object_->SendSignal(&signal); | 701 exported_object_->SendSignal(&signal); |
| 693 } | 702 } |
| 694 | 703 |
| 695 } // namespace dbus | 704 } // namespace dbus |
| OLD | NEW |