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/bus.h" | 5 #include "dbus/bus.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 void ObjectProxy::Detach() { | 128 void ObjectProxy::Detach() { |
129 bus_->AssertOnDBusThread(); | 129 bus_->AssertOnDBusThread(); |
130 | 130 |
131 if (filter_added_) { | 131 if (filter_added_) { |
132 if (!bus_->RemoveFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { | 132 if (!bus_->RemoveFilterFunction(&ObjectProxy::HandleMessageThunk, this)) { |
133 LOG(ERROR) << "Failed to remove filter function"; | 133 LOG(ERROR) << "Failed to remove filter function"; |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 for (size_t i = 0; i < match_rules_.size(); ++i) { | 137 for (std::set<std::string>::iterator iter = match_rules_.begin(); |
| 138 iter != match_rules_.end(); ++iter) { |
138 ScopedDBusError error; | 139 ScopedDBusError error; |
139 bus_->RemoveMatch(match_rules_[i], error.get()); | 140 bus_->RemoveMatch(*iter, error.get()); |
140 if (error.is_set()) { | 141 if (error.is_set()) { |
141 // There is nothing we can do to recover, so just print the error. | 142 // There is nothing we can do to recover, so just print the error. |
142 LOG(ERROR) << "Failed to remove match rule: " << match_rules_[i]; | 143 LOG(ERROR) << "Failed to remove match rule: " << *iter; |
143 } | 144 } |
144 } | 145 } |
| 146 match_rules_.clear(); |
145 } | 147 } |
146 | 148 |
147 // static | 149 // static |
148 ObjectProxy::ResponseCallback ObjectProxy::EmptyResponseCallback() { | 150 ObjectProxy::ResponseCallback ObjectProxy::EmptyResponseCallback() { |
149 return base::Bind(&EmptyResponseCallbackBody); | 151 return base::Bind(&EmptyResponseCallbackBody); |
150 } | 152 } |
151 | 153 |
152 ObjectProxy::OnPendingCallIsCompleteData::OnPendingCallIsCompleteData( | 154 ObjectProxy::OnPendingCallIsCompleteData::OnPendingCallIsCompleteData( |
153 ObjectProxy* in_object_proxy, | 155 ObjectProxy* in_object_proxy, |
154 ResponseCallback in_response_callback, | 156 ResponseCallback in_response_callback, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 299 } |
298 // Add a match rule so the signal goes through HandleMessage(). | 300 // Add a match rule so the signal goes through HandleMessage(). |
299 // | 301 // |
300 // We don't restrict the sender object path to be |object_path_| here, | 302 // We don't restrict the sender object path to be |object_path_| here, |
301 // to make it easy to test D-Bus signal handling with dbus-send, that | 303 // to make it easy to test D-Bus signal handling with dbus-send, that |
302 // uses "/" as the sender object path. We can make the object path | 304 // uses "/" as the sender object path. We can make the object path |
303 // restriction customizable when it becomes necessary. | 305 // restriction customizable when it becomes necessary. |
304 const std::string match_rule = | 306 const std::string match_rule = |
305 base::StringPrintf("type='signal', interface='%s'", | 307 base::StringPrintf("type='signal', interface='%s'", |
306 interface_name.c_str()); | 308 interface_name.c_str()); |
307 ScopedDBusError error; | 309 |
308 bus_->AddMatch(match_rule, error.get());; | 310 // Add the match rule if we don't have it. |
309 if (error.is_set()) { | 311 if (match_rules_.find(match_rule) == match_rules_.end()) { |
310 LOG(ERROR) << "Failed to add match rule: " << match_rule; | 312 ScopedDBusError error; |
| 313 bus_->AddMatch(match_rule, error.get());; |
| 314 if (error.is_set()) { |
| 315 LOG(ERROR) << "Failed to add match rule: " << match_rule; |
| 316 } else { |
| 317 // Store the match rule, so that we can remove this in Detach(). |
| 318 match_rules_.insert(match_rule); |
| 319 // Add the signal callback to the method table. |
| 320 method_table_[absolute_signal_name] = signal_callback; |
| 321 success = true; |
| 322 } |
311 } else { | 323 } else { |
312 // Store the match rule, so that we can remove this in Detach(). | 324 // We already have the match rule. |
313 match_rules_.push_back(match_rule); | |
314 // Add the signal callback to the method table. | |
315 method_table_[absolute_signal_name] = signal_callback; | 325 method_table_[absolute_signal_name] = signal_callback; |
316 success = true; | 326 success = true; |
317 } | 327 } |
318 } | 328 } |
319 | 329 |
320 // Run on_connected_callback in the origin thread. | 330 // Run on_connected_callback in the origin thread. |
321 bus_->PostTaskToOriginThread( | 331 bus_->PostTaskToOriginThread( |
322 FROM_HERE, | 332 FROM_HERE, |
323 base::Bind(&ObjectProxy::OnConnected, | 333 base::Bind(&ObjectProxy::OnConnected, |
324 this, | 334 this, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 | 410 |
401 DBusHandlerResult ObjectProxy::HandleMessageThunk( | 411 DBusHandlerResult ObjectProxy::HandleMessageThunk( |
402 DBusConnection* connection, | 412 DBusConnection* connection, |
403 DBusMessage* raw_message, | 413 DBusMessage* raw_message, |
404 void* user_data) { | 414 void* user_data) { |
405 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); | 415 ObjectProxy* self = reinterpret_cast<ObjectProxy*>(user_data); |
406 return self->HandleMessage(connection, raw_message); | 416 return self->HandleMessage(connection, raw_message); |
407 } | 417 } |
408 | 418 |
409 } // namespace dbus | 419 } // namespace dbus |
OLD | NEW |