OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/object_manager.h" | 5 #include "dbus/object_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 void* user_data) { | 245 void* user_data) { |
246 ObjectManager* self = reinterpret_cast<ObjectManager*>(user_data); | 246 ObjectManager* self = reinterpret_cast<ObjectManager*>(user_data); |
247 return self->HandleMessage(connection, raw_message); | 247 return self->HandleMessage(connection, raw_message); |
248 } | 248 } |
249 | 249 |
250 DBusHandlerResult ObjectManager::HandleMessage(DBusConnection* connection, | 250 DBusHandlerResult ObjectManager::HandleMessage(DBusConnection* connection, |
251 DBusMessage* raw_message) { | 251 DBusMessage* raw_message) { |
252 DCHECK(bus_); | 252 DCHECK(bus_); |
253 bus_->AssertOnDBusThread(); | 253 bus_->AssertOnDBusThread(); |
254 | 254 |
| 255 // Handle the message only if it is a signal. |
| 256 // Note that the match rule in SetupMatchRuleAndFilter() is configured to |
| 257 // only accept signals, but we check here just in case. |
255 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) | 258 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) |
256 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 259 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
257 | 260 |
258 // raw_message will be unrefed on exit of the function. Increment the | 261 // raw_message will be unrefed on exit of the function. Increment the |
259 // reference so we can use it in Signal. | 262 // reference so we can use it in Signal. |
260 dbus_message_ref(raw_message); | 263 dbus_message_ref(raw_message); |
261 scoped_ptr<Signal> signal( | 264 scoped_ptr<Signal> signal( |
262 Signal::FromRawMessage(raw_message)); | 265 Signal::FromRawMessage(raw_message)); |
263 | 266 |
264 const std::string interface = signal->GetInterface(); | 267 const std::string interface = signal->GetInterface(); |
265 const std::string member = signal->GetMember(); | 268 const std::string member = signal->GetMember(); |
266 | 269 |
267 statistics::AddReceivedSignal(service_name_, interface, member); | 270 statistics::AddReceivedSignal(service_name_, interface, member); |
268 | 271 |
269 // Only handle the PropertiesChanged signal. | 272 // Handle the signal only if it is PropertiesChanged. |
| 273 // Note that the match rule in SetupMatchRuleAndFilter() is configured to |
| 274 // only accept PropertiesChanged signals, but we check here just in case. |
270 const std::string absolute_signal_name = | 275 const std::string absolute_signal_name = |
271 GetAbsoluteMemberName(interface, member); | 276 GetAbsoluteMemberName(interface, member); |
272 const std::string properties_changed_signal_name = | 277 const std::string properties_changed_signal_name = |
273 GetAbsoluteMemberName(kPropertiesInterface, kPropertiesChanged); | 278 GetAbsoluteMemberName(kPropertiesInterface, kPropertiesChanged); |
274 if (absolute_signal_name != properties_changed_signal_name) | 279 if (absolute_signal_name != properties_changed_signal_name) |
275 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 280 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
276 | 281 |
277 VLOG(1) << "Signal received: " << signal->ToString(); | 282 VLOG(1) << "Signal received: " << signal->ToString(); |
278 | 283 |
279 // Make sure that the signal originated from the correct sender. | 284 // Handle the signal only if it is from the service that the ObjectManager |
| 285 // instance is interested in. |
| 286 // Note that the match rule in SetupMatchRuleAndFilter() is configured to |
| 287 // only accept messages from the service name of our interest. However, the |
| 288 // service='...' filter does not work as intended. See crbug.com/507206#14 |
| 289 // and #15 for details, hence it's necessary to check the sender here. |
280 std::string sender = signal->GetSender(); | 290 std::string sender = signal->GetSender(); |
281 if (service_name_owner_ != sender) { | 291 if (service_name_owner_ != sender) |
282 LOG(ERROR) << "Rejecting a message from a wrong sender."; | |
283 UMA_HISTOGRAM_COUNTS("DBus.RejectedSignalCount", 1); | |
284 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 292 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
285 } | |
286 | 293 |
287 const ObjectPath path = signal->GetPath(); | 294 const ObjectPath path = signal->GetPath(); |
288 | 295 |
289 if (bus_->HasDBusThread()) { | 296 if (bus_->HasDBusThread()) { |
290 // Post a task to run the method in the origin thread. Transfer ownership of | 297 // Post a task to run the method in the origin thread. Transfer ownership of |
291 // |signal| to NotifyPropertiesChanged, which will handle the clean up. | 298 // |signal| to NotifyPropertiesChanged, which will handle the clean up. |
292 Signal* released_signal = signal.release(); | 299 Signal* released_signal = signal.release(); |
293 bus_->GetOriginTaskRunner()->PostTask( | 300 bus_->GetOriginTaskRunner()->PostTask( |
294 FROM_HERE, | 301 FROM_HERE, |
295 base::Bind(&ObjectManager::NotifyPropertiesChanged, | 302 base::Bind(&ObjectManager::NotifyPropertiesChanged, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 RemoveInterface(object_path, *iiter); | 525 RemoveInterface(object_path, *iiter); |
519 } | 526 } |
520 | 527 |
521 } | 528 } |
522 | 529 |
523 if (!new_owner.empty()) | 530 if (!new_owner.empty()) |
524 GetManagedObjects(); | 531 GetManagedObjects(); |
525 } | 532 } |
526 | 533 |
527 } // namespace dbus | 534 } // namespace dbus |
OLD | NEW |