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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 return false; | 203 return false; |
204 | 204 |
205 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) | 205 if (!bus_->Connect() || !bus_->SetUpAsyncOperations()) |
206 return false; | 206 return false; |
207 | 207 |
208 service_name_owner_ = | 208 service_name_owner_ = |
209 bus_->GetServiceOwnerAndBlock(service_name_, Bus::SUPPRESS_ERRORS); | 209 bus_->GetServiceOwnerAndBlock(service_name_, Bus::SUPPRESS_ERRORS); |
210 | 210 |
211 const std::string match_rule = | 211 const std::string match_rule = |
212 base::StringPrintf( | 212 base::StringPrintf( |
213 "type='signal', sender='%s', interface='%s', member='%s'", | 213 "type='signal', sender='%s', interface='%s', member='%s'", |
hashimoto
2015/08/17 07:07:49
ObjectManager::HandleMessage looks like a dead cop
satorux1
2015/08/17 07:35:07
Good points, but I'd rather not to do non-trivial
| |
214 service_name_.c_str(), | 214 service_name_.c_str(), |
215 kPropertiesInterface, | 215 kPropertiesInterface, |
216 kPropertiesChanged); | 216 kPropertiesChanged); |
217 | 217 |
218 bus_->AddFilterFunction(&ObjectManager::HandleMessageThunk, this); | 218 bus_->AddFilterFunction(&ObjectManager::HandleMessageThunk, this); |
219 | 219 |
220 ScopedDBusError error; | 220 ScopedDBusError error; |
221 bus_->AddMatch(match_rule, error.get()); | 221 bus_->AddMatch(match_rule, error.get()); |
222 if (error.is_set()) { | 222 if (error.is_set()) { |
223 LOG(ERROR) << "ObjectManager failed to add match rule \"" << match_rule | 223 LOG(ERROR) << "ObjectManager failed to add match rule \"" << match_rule |
(...skipping 21 matching lines...) Expand all 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. | |
255 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) | 256 if (dbus_message_get_type(raw_message) != DBUS_MESSAGE_TYPE_SIGNAL) |
256 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 257 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
257 | 258 |
258 // raw_message will be unrefed on exit of the function. Increment the | 259 // raw_message will be unrefed on exit of the function. Increment the |
259 // reference so we can use it in Signal. | 260 // reference so we can use it in Signal. |
260 dbus_message_ref(raw_message); | 261 dbus_message_ref(raw_message); |
261 scoped_ptr<Signal> signal( | 262 scoped_ptr<Signal> signal( |
262 Signal::FromRawMessage(raw_message)); | 263 Signal::FromRawMessage(raw_message)); |
263 | 264 |
264 const std::string interface = signal->GetInterface(); | 265 const std::string interface = signal->GetInterface(); |
265 const std::string member = signal->GetMember(); | 266 const std::string member = signal->GetMember(); |
266 | 267 |
267 statistics::AddReceivedSignal(service_name_, interface, member); | 268 statistics::AddReceivedSignal(service_name_, interface, member); |
268 | 269 |
269 // Only handle the PropertiesChanged signal. | 270 // Handle the signal only if it is PropertiesChanged. |
270 const std::string absolute_signal_name = | 271 const std::string absolute_signal_name = |
271 GetAbsoluteMemberName(interface, member); | 272 GetAbsoluteMemberName(interface, member); |
272 const std::string properties_changed_signal_name = | 273 const std::string properties_changed_signal_name = |
273 GetAbsoluteMemberName(kPropertiesInterface, kPropertiesChanged); | 274 GetAbsoluteMemberName(kPropertiesInterface, kPropertiesChanged); |
274 if (absolute_signal_name != properties_changed_signal_name) | 275 if (absolute_signal_name != properties_changed_signal_name) |
275 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 276 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
276 | 277 |
277 VLOG(1) << "Signal received: " << signal->ToString(); | 278 VLOG(1) << "Signal received: " << signal->ToString(); |
278 | 279 |
279 // Make sure that the signal originated from the correct sender. | 280 // Handle the signal only if it is from the service that the ObjectManager |
281 // instance is interested in. | |
280 std::string sender = signal->GetSender(); | 282 std::string sender = signal->GetSender(); |
281 if (service_name_owner_ != sender) { | 283 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; | 284 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
285 } | |
286 | 285 |
287 const ObjectPath path = signal->GetPath(); | 286 const ObjectPath path = signal->GetPath(); |
288 | 287 |
289 if (bus_->HasDBusThread()) { | 288 if (bus_->HasDBusThread()) { |
290 // Post a task to run the method in the origin thread. Transfer ownership of | 289 // Post a task to run the method in the origin thread. Transfer ownership of |
291 // |signal| to NotifyPropertiesChanged, which will handle the clean up. | 290 // |signal| to NotifyPropertiesChanged, which will handle the clean up. |
292 Signal* released_signal = signal.release(); | 291 Signal* released_signal = signal.release(); |
293 bus_->GetOriginTaskRunner()->PostTask( | 292 bus_->GetOriginTaskRunner()->PostTask( |
294 FROM_HERE, | 293 FROM_HERE, |
295 base::Bind(&ObjectManager::NotifyPropertiesChanged, | 294 base::Bind(&ObjectManager::NotifyPropertiesChanged, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 RemoveInterface(object_path, *iiter); | 517 RemoveInterface(object_path, *iiter); |
519 } | 518 } |
520 | 519 |
521 } | 520 } |
522 | 521 |
523 if (!new_owner.empty()) | 522 if (!new_owner.empty()) |
524 GetManagedObjects(); | 523 GetManagedObjects(); |
525 } | 524 } |
526 | 525 |
527 } // namespace dbus | 526 } // namespace dbus |
OLD | NEW |