| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 void TestService::SendTestSignal(const std::string& message) { | 67 void TestService::SendTestSignal(const std::string& message) { |
| 68 message_loop()->PostTask( | 68 message_loop()->PostTask( |
| 69 FROM_HERE, | 69 FROM_HERE, |
| 70 base::Bind(&TestService::SendTestSignalInternal, | 70 base::Bind(&TestService::SendTestSignalInternal, |
| 71 base::Unretained(this), | 71 base::Unretained(this), |
| 72 message)); | 72 message)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void TestService::SendTestSignalFromRoot(const std::string& message) { |
| 76 message_loop()->PostTask( |
| 77 FROM_HERE, |
| 78 base::Bind(&TestService::SendTestSignalFromRootInternal, |
| 79 base::Unretained(this), |
| 80 message)); |
| 81 } |
| 82 |
| 75 void TestService::SendTestSignalInternal(const std::string& message) { | 83 void TestService::SendTestSignalInternal(const std::string& message) { |
| 76 dbus::Signal signal("org.chromium.TestInterface", "Test"); | 84 dbus::Signal signal("org.chromium.TestInterface", "Test"); |
| 77 dbus::MessageWriter writer(&signal); | 85 dbus::MessageWriter writer(&signal); |
| 78 writer.AppendString(message); | 86 writer.AppendString(message); |
| 79 exported_object_->SendSignal(&signal); | 87 exported_object_->SendSignal(&signal); |
| 80 } | 88 } |
| 81 | 89 |
| 90 void TestService::SendTestSignalFromRootInternal(const std::string& message) { |
| 91 dbus::Signal signal("org.chromium.TestInterface", "Test"); |
| 92 dbus::MessageWriter writer(&signal); |
| 93 writer.AppendString(message); |
| 94 |
| 95 // Use "/" just like dbus-send does. |
| 96 ExportedObject* root_object = |
| 97 bus_->GetExportedObject("org.chromium.TestService", |
| 98 "/"); |
| 99 root_object->SendSignal(&signal); |
| 100 } |
| 101 |
| 82 void TestService::OnExported(const std::string& interface_name, | 102 void TestService::OnExported(const std::string& interface_name, |
| 83 const std::string& method_name, | 103 const std::string& method_name, |
| 84 bool success) { | 104 bool success) { |
| 85 if (!success) { | 105 if (!success) { |
| 86 LOG(ERROR) << "Failed to export: " << interface_name << "." | 106 LOG(ERROR) << "Failed to export: " << interface_name << "." |
| 87 << method_name; | 107 << method_name; |
| 88 // Returning here will make WaitUntilServiceIsStarted() to time out | 108 // Returning here will make WaitUntilServiceIsStarted() to time out |
| 89 // and return false. | 109 // and return false. |
| 90 return; | 110 return; |
| 91 } | 111 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 Response* TestService::SlowEcho(MethodCall* method_call) { | 177 Response* TestService::SlowEcho(MethodCall* method_call) { |
| 158 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); | 178 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); |
| 159 return Echo(method_call); | 179 return Echo(method_call); |
| 160 } | 180 } |
| 161 | 181 |
| 162 Response* TestService::BrokenMethod(MethodCall* method_call) { | 182 Response* TestService::BrokenMethod(MethodCall* method_call) { |
| 163 return NULL; | 183 return NULL; |
| 164 } | 184 } |
| 165 | 185 |
| 166 } // namespace dbus | 186 } // namespace dbus |
| OLD | NEW |