Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: dbus/test_service.cc

Issue 9668018: dbus: remove service name from ExportedObject (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pay more attention when fixing mock Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dbus/test_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 dbus::MessageWriter writer(&signal); 88 dbus::MessageWriter writer(&signal);
89 writer.AppendString(message); 89 writer.AppendString(message);
90 exported_object_->SendSignal(&signal); 90 exported_object_->SendSignal(&signal);
91 } 91 }
92 92
93 void TestService::SendTestSignalFromRootInternal(const std::string& message) { 93 void TestService::SendTestSignalFromRootInternal(const std::string& message) {
94 dbus::Signal signal("org.chromium.TestInterface", "Test"); 94 dbus::Signal signal("org.chromium.TestInterface", "Test");
95 dbus::MessageWriter writer(&signal); 95 dbus::MessageWriter writer(&signal);
96 writer.AppendString(message); 96 writer.AppendString(message);
97 97
98 bus_->RequestOwnership("org.chromium.TestService",
99 base::Bind(&TestService::OnOwnership,
100 base::Unretained(this)));
101
98 // Use "/" just like dbus-send does. 102 // Use "/" just like dbus-send does.
99 ExportedObject* root_object = 103 ExportedObject* root_object =
100 bus_->GetExportedObject("org.chromium.TestService", 104 bus_->GetExportedObject(dbus::ObjectPath("/"));
101 dbus::ObjectPath("/"));
102 root_object->SendSignal(&signal); 105 root_object->SendSignal(&signal);
103 } 106 }
104 107
108 void TestService::OnOwnership(const std::string& service_name,
109 bool success) {
110 LOG_IF(ERROR, !success) << "Failed to own: " << service_name;
111 }
112
105 void TestService::OnExported(const std::string& interface_name, 113 void TestService::OnExported(const std::string& interface_name,
106 const std::string& method_name, 114 const std::string& method_name,
107 bool success) { 115 bool success) {
108 if (!success) { 116 if (!success) {
109 LOG(ERROR) << "Failed to export: " << interface_name << "." 117 LOG(ERROR) << "Failed to export: " << interface_name << "."
110 << method_name; 118 << method_name;
111 // Returning here will make WaitUntilServiceIsStarted() to time out 119 // Returning here will make WaitUntilServiceIsStarted() to time out
112 // and return false. 120 // and return false.
113 return; 121 return;
114 } 122 }
115 123
116 ++num_exported_methods_; 124 ++num_exported_methods_;
117 if (num_exported_methods_ == kNumMethodsToExport) 125 if (num_exported_methods_ == kNumMethodsToExport)
118 on_all_methods_exported_.Signal(); 126 on_all_methods_exported_.Signal();
119 } 127 }
120 128
121 void TestService::Run(MessageLoop* message_loop) { 129 void TestService::Run(MessageLoop* message_loop) {
122 Bus::Options bus_options; 130 Bus::Options bus_options;
123 bus_options.bus_type = Bus::SESSION; 131 bus_options.bus_type = Bus::SESSION;
124 bus_options.connection_type = Bus::PRIVATE; 132 bus_options.connection_type = Bus::PRIVATE;
125 bus_options.dbus_thread_message_loop_proxy = dbus_thread_message_loop_proxy_; 133 bus_options.dbus_thread_message_loop_proxy = dbus_thread_message_loop_proxy_;
126 bus_ = new Bus(bus_options); 134 bus_ = new Bus(bus_options);
127 135
136 bus_->RequestOwnership("org.chromium.TestService",
137 base::Bind(&TestService::OnOwnership,
138 base::Unretained(this)));
139
128 exported_object_ = bus_->GetExportedObject( 140 exported_object_ = bus_->GetExportedObject(
129 "org.chromium.TestService",
130 dbus::ObjectPath("/org/chromium/TestObject")); 141 dbus::ObjectPath("/org/chromium/TestObject"));
131 142
132 int num_methods = 0; 143 int num_methods = 0;
133 exported_object_->ExportMethod( 144 exported_object_->ExportMethod(
134 "org.chromium.TestInterface", 145 "org.chromium.TestInterface",
135 "Echo", 146 "Echo",
136 base::Bind(&TestService::Echo, 147 base::Bind(&TestService::Echo,
137 base::Unretained(this)), 148 base::Unretained(this)),
138 base::Bind(&TestService::OnExported, 149 base::Bind(&TestService::OnExported,
139 base::Unretained(this))); 150 base::Unretained(this)));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 array_writer.OpenDictEntry(&dict_entry_writer); 402 array_writer.OpenDictEntry(&dict_entry_writer);
392 dict_entry_writer.AppendString("Name"); 403 dict_entry_writer.AppendString("Name");
393 dict_entry_writer.AppendVariantOfString(name); 404 dict_entry_writer.AppendVariantOfString(name);
394 array_writer.CloseContainer(&dict_entry_writer); 405 array_writer.CloseContainer(&dict_entry_writer);
395 writer.CloseContainer(&array_writer); 406 writer.CloseContainer(&array_writer);
396 407
397 exported_object_->SendSignal(&signal); 408 exported_object_->SendSignal(&signal);
398 } 409 }
399 410
400 } // namespace dbus 411 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/test_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698