summaryrefslogtreecommitdiffstats
path: root/chromium/dbus/test_service.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/dbus/test_service.cc')
-rw-r--r--chromium/dbus/test_service.cc101
1 files changed, 90 insertions, 11 deletions
diff --git a/chromium/dbus/test_service.cc b/chromium/dbus/test_service.cc
index 5f5950162ec..96fa8bced98 100644
--- a/chromium/dbus/test_service.cc
+++ b/chromium/dbus/test_service.cc
@@ -38,7 +38,7 @@ TestService::TestService(const Options& options)
: base::Thread("TestService"),
request_ownership_options_(options.request_ownership_options),
dbus_task_runner_(options.dbus_task_runner),
- on_all_methods_exported_(false, false),
+ on_name_obtained_(false, false),
num_exported_methods_(0) {
}
@@ -54,8 +54,8 @@ bool TestService::StartService() {
bool TestService::WaitUntilServiceIsStarted() {
const base::TimeDelta timeout(TestTimeouts::action_max_timeout());
- // Wait until all methods are exported.
- return on_all_methods_exported_.TimedWait(timeout);
+ // Wait until the ownership of the service name is obtained.
+ return on_name_obtained_.TimedWait(timeout);
}
void TestService::ShutdownAndBlock() {
@@ -138,6 +138,26 @@ void TestService::OnOwnership(base::Callback<void(bool)> callback,
has_ownership_ = success;
LOG_IF(ERROR, !success) << "Failed to own: " << service_name;
callback.Run(success);
+
+ on_name_obtained_.Signal();
+}
+
+void TestService::ReleaseOwnership(base::Closure callback) {
+ bus_->GetDBusTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&TestService::ReleaseOwnershipInternal,
+ base::Unretained(this),
+ callback));
+}
+
+void TestService::ReleaseOwnershipInternal(
+ base::Closure callback) {
+ bus_->ReleaseOwnership("org.chromium.TestService");
+ has_ownership_ = false;
+
+ bus_->GetOriginTaskRunner()->PostTask(
+ FROM_HERE,
+ callback);
}
void TestService::OnExported(const std::string& interface_name,
@@ -152,8 +172,15 @@ void TestService::OnExported(const std::string& interface_name,
}
++num_exported_methods_;
- if (num_exported_methods_ == kNumMethodsToExport)
- on_all_methods_exported_.Signal();
+ if (num_exported_methods_ == kNumMethodsToExport) {
+ // As documented in exported_object.h, the service name should be
+ // requested after all methods are exposed.
+ bus_->RequestOwnership("org.chromium.TestService",
+ request_ownership_options_,
+ base::Bind(&TestService::OnOwnership,
+ base::Unretained(this),
+ base::Bind(&EmptyCallback)));
+ }
}
void TestService::Run(base::MessageLoop* message_loop) {
@@ -163,12 +190,6 @@ void TestService::Run(base::MessageLoop* message_loop) {
bus_options.dbus_task_runner = dbus_task_runner_;
bus_ = new Bus(bus_options);
- bus_->RequestOwnership("org.chromium.TestService",
- request_ownership_options_,
- base::Bind(&TestService::OnOwnership,
- base::Unretained(this),
- base::Bind(&EmptyCallback)));
-
exported_object_ = bus_->GetExportedObject(
ObjectPath("/org/chromium/TestObject"));
@@ -387,6 +408,20 @@ void TestService::GetProperty(MethodCall* method_call,
writer.CloseContainer(&variant_writer);
response_sender.Run(response.Pass());
+ } else if (name == "Bytes") {
+ // Return the previous value for the "Bytes" property:
+ // Variant<[0x54, 0x65, 0x73, 0x74]>
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response.get());
+ MessageWriter variant_writer(NULL);
+ MessageWriter variant_array_writer(NULL);
+
+ writer.OpenVariant("ay", &variant_writer);
+ const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 };
+ variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes));
+ writer.CloseContainer(&variant_writer);
+
+ response_sender.Run(response.Pass());
} else {
// Return error.
response_sender.Run(scoped_ptr<Response>());
@@ -440,11 +475,46 @@ void TestService::PerformAction(
AddObject(object_path);
else if (action == "RemoveObject")
RemoveObject(object_path);
+ else if (action == "ReleaseOwnership") {
+ ReleaseOwnership(base::Bind(&TestService::PerformActionResponse,
+ base::Unretained(this),
+ method_call, response_sender));
+ return;
+ } else if (action == "Ownership") {
+ ReleaseOwnership(base::Bind(&TestService::OwnershipReleased,
+ base::Unretained(this),
+ method_call, response_sender));
+ return;
+ }
+
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ response_sender.Run(response.Pass());
+}
+void TestService::PerformActionResponse(
+ MethodCall* method_call,
+ ExportedObject::ResponseSender response_sender) {
scoped_ptr<Response> response = Response::FromMethodCall(method_call);
response_sender.Run(response.Pass());
}
+void TestService::OwnershipReleased(
+ MethodCall* method_call,
+ ExportedObject::ResponseSender response_sender) {
+ RequestOwnership(base::Bind(&TestService::OwnershipRegained,
+ base::Unretained(this),
+ method_call, response_sender));
+}
+
+
+void TestService::OwnershipRegained(
+ MethodCall* method_call,
+ ExportedObject::ResponseSender response_sender,
+ bool success) {
+ PerformActionResponse(method_call, response_sender);
+}
+
+
void TestService::GetManagedObjects(
MethodCall* method_call,
ExportedObject::ResponseSender response_sender) {
@@ -498,6 +568,7 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) {
// "Version": Variant<10>,
// "Methods": Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>,
// "Objects": Variant<[objectpath:"/TestObjectPath"]>
+ // "Bytes": Variant<[0x54, 0x65, 0x73, 0x74]>
// }
MessageWriter array_writer(NULL);
@@ -538,6 +609,14 @@ void TestService::AddPropertiesToWriter(MessageWriter* writer) {
dict_entry_writer.CloseContainer(&variant_writer);
array_writer.CloseContainer(&dict_entry_writer);
+ array_writer.OpenDictEntry(&dict_entry_writer);
+ dict_entry_writer.AppendString("Bytes");
+ dict_entry_writer.OpenVariant("ay", &variant_writer);
+ const uint8 bytes[] = { 0x54, 0x65, 0x73, 0x74 };
+ variant_writer.AppendArrayOfBytes(bytes, sizeof(bytes));
+ dict_entry_writer.CloseContainer(&variant_writer);
+ array_writer.CloseContainer(&dict_entry_writer);
+
writer->CloseContainer(&array_writer);
}