| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/run_loop.h" |
| 14 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
| 15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 16 #include "dbus/bus.h" | 17 #include "dbus/bus.h" |
| 17 #include "dbus/exported_object.h" | 18 #include "dbus/exported_object.h" |
| 18 #include "dbus/message.h" | 19 #include "dbus/message.h" |
| 19 #include "dbus/object_manager.h" | 20 #include "dbus/object_manager.h" |
| 20 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 21 #include "dbus/property.h" | 22 #include "dbus/property.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // As documented in exported_object.h, the service name should be | 196 // As documented in exported_object.h, the service name should be |
| 196 // requested after all methods are exposed. | 197 // requested after all methods are exposed. |
| 197 bus_->RequestOwnership(service_name_, | 198 bus_->RequestOwnership(service_name_, |
| 198 request_ownership_options_, | 199 request_ownership_options_, |
| 199 base::Bind(&TestService::OnOwnership, | 200 base::Bind(&TestService::OnOwnership, |
| 200 base::Unretained(this), | 201 base::Unretained(this), |
| 201 base::Bind(&EmptyCallback))); | 202 base::Bind(&EmptyCallback))); |
| 202 } | 203 } |
| 203 } | 204 } |
| 204 | 205 |
| 205 void TestService::Run(base::MessageLoop* message_loop) { | 206 void TestService::Run(base::RunLoop* run_loop) { |
| 206 Bus::Options bus_options; | 207 Bus::Options bus_options; |
| 207 bus_options.bus_type = Bus::SESSION; | 208 bus_options.bus_type = Bus::SESSION; |
| 208 bus_options.connection_type = Bus::PRIVATE; | 209 bus_options.connection_type = Bus::PRIVATE; |
| 209 bus_options.dbus_task_runner = dbus_task_runner_; | 210 bus_options.dbus_task_runner = dbus_task_runner_; |
| 210 bus_ = new Bus(bus_options); | 211 bus_ = new Bus(bus_options); |
| 211 | 212 |
| 212 exported_object_ = bus_->GetExportedObject( | 213 exported_object_ = bus_->GetExportedObject( |
| 213 ObjectPath("/org/chromium/TestObject")); | 214 ObjectPath("/org/chromium/TestObject")); |
| 214 | 215 |
| 215 int num_methods = 0; | 216 int num_methods = 0; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 base::Unretained(this)), | 296 base::Unretained(this)), |
| 296 base::Bind(&TestService::OnExported, | 297 base::Bind(&TestService::OnExported, |
| 297 base::Unretained(this))); | 298 base::Unretained(this))); |
| 298 ++num_methods; | 299 ++num_methods; |
| 299 | 300 |
| 300 // Just print an error message as we don't want to crash tests. | 301 // Just print an error message as we don't want to crash tests. |
| 301 // Tests will fail at a call to WaitUntilServiceIsStarted(). | 302 // Tests will fail at a call to WaitUntilServiceIsStarted(). |
| 302 if (num_methods != kNumMethodsToExport) { | 303 if (num_methods != kNumMethodsToExport) { |
| 303 LOG(ERROR) << "The number of methods does not match"; | 304 LOG(ERROR) << "The number of methods does not match"; |
| 304 } | 305 } |
| 305 message_loop->Run(); | 306 run_loop->Run(); |
| 306 } | 307 } |
| 307 | 308 |
| 308 void TestService::Echo(MethodCall* method_call, | 309 void TestService::Echo(MethodCall* method_call, |
| 309 ExportedObject::ResponseSender response_sender) { | 310 ExportedObject::ResponseSender response_sender) { |
| 310 MessageReader reader(method_call); | 311 MessageReader reader(method_call); |
| 311 std::string text_message; | 312 std::string text_message; |
| 312 if (!reader.PopString(&text_message)) { | 313 if (!reader.PopString(&text_message)) { |
| 313 response_sender.Run(std::unique_ptr<Response>()); | 314 response_sender.Run(std::unique_ptr<Response>()); |
| 314 return; | 315 return; |
| 315 } | 316 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 MessageWriter invalidated_array_writer(NULL); | 744 MessageWriter invalidated_array_writer(NULL); |
| 744 | 745 |
| 745 writer.OpenArray("s", &invalidated_array_writer); | 746 writer.OpenArray("s", &invalidated_array_writer); |
| 746 invalidated_array_writer.AppendString("Name"); | 747 invalidated_array_writer.AppendString("Name"); |
| 747 writer.CloseContainer(&invalidated_array_writer); | 748 writer.CloseContainer(&invalidated_array_writer); |
| 748 | 749 |
| 749 exported_object_->SendSignal(&signal); | 750 exported_object_->SendSignal(&signal); |
| 750 } | 751 } |
| 751 | 752 |
| 752 } // namespace dbus | 753 } // namespace dbus |
| OLD | NEW |