OLD | NEW |
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/exported_object.h" | 5 #include "dbus/exported_object.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 188 |
189 DBusHandlerResult ExportedObject::HandleMessage( | 189 DBusHandlerResult ExportedObject::HandleMessage( |
190 DBusConnection* connection, | 190 DBusConnection* connection, |
191 DBusMessage* raw_message) { | 191 DBusMessage* raw_message) { |
192 bus_->AssertOnDBusThread(); | 192 bus_->AssertOnDBusThread(); |
193 DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_CALL, dbus_message_get_type(raw_message)); | 193 DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_CALL, dbus_message_get_type(raw_message)); |
194 | 194 |
195 // raw_message will be unrefed on exit of the function. Increment the | 195 // raw_message will be unrefed on exit of the function. Increment the |
196 // reference so we can use it in MethodCall. | 196 // reference so we can use it in MethodCall. |
197 dbus_message_ref(raw_message); | 197 dbus_message_ref(raw_message); |
198 scoped_ptr<MethodCall> method_call( | 198 std::unique_ptr<MethodCall> method_call( |
199 MethodCall::FromRawMessage(raw_message)); | 199 MethodCall::FromRawMessage(raw_message)); |
200 const std::string interface = method_call->GetInterface(); | 200 const std::string interface = method_call->GetInterface(); |
201 const std::string member = method_call->GetMember(); | 201 const std::string member = method_call->GetMember(); |
202 | 202 |
203 if (interface.empty()) { | 203 if (interface.empty()) { |
204 // We don't support method calls without interface. | 204 // We don't support method calls without interface. |
205 LOG(WARNING) << "Interface is missing: " << method_call->ToString(); | 205 LOG(WARNING) << "Interface is missing: " << method_call->ToString(); |
206 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; | 206 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
207 } | 207 } |
208 | 208 |
(...skipping 25 matching lines...) Expand all Loading... |
234 start_time, | 234 start_time, |
235 base::Passed(&method_call))); | 235 base::Passed(&method_call))); |
236 } | 236 } |
237 | 237 |
238 // It's valid to say HANDLED here, and send a method response at a later | 238 // It's valid to say HANDLED here, and send a method response at a later |
239 // time from OnMethodCompleted() asynchronously. | 239 // time from OnMethodCompleted() asynchronously. |
240 return DBUS_HANDLER_RESULT_HANDLED; | 240 return DBUS_HANDLER_RESULT_HANDLED; |
241 } | 241 } |
242 | 242 |
243 void ExportedObject::RunMethod(MethodCallCallback method_call_callback, | 243 void ExportedObject::RunMethod(MethodCallCallback method_call_callback, |
244 scoped_ptr<MethodCall> method_call, | 244 std::unique_ptr<MethodCall> method_call, |
245 base::TimeTicks start_time) { | 245 base::TimeTicks start_time) { |
246 bus_->AssertOnOriginThread(); | 246 bus_->AssertOnOriginThread(); |
247 MethodCall* method = method_call.get(); | 247 MethodCall* method = method_call.get(); |
248 method_call_callback.Run(method, | 248 method_call_callback.Run(method, |
249 base::Bind(&ExportedObject::SendResponse, | 249 base::Bind(&ExportedObject::SendResponse, |
250 this, | 250 this, |
251 start_time, | 251 start_time, |
252 base::Passed(&method_call))); | 252 base::Passed(&method_call))); |
253 } | 253 } |
254 | 254 |
255 void ExportedObject::SendResponse(base::TimeTicks start_time, | 255 void ExportedObject::SendResponse(base::TimeTicks start_time, |
256 scoped_ptr<MethodCall> method_call, | 256 std::unique_ptr<MethodCall> method_call, |
257 scoped_ptr<Response> response) { | 257 std::unique_ptr<Response> response) { |
258 DCHECK(method_call); | 258 DCHECK(method_call); |
259 if (bus_->HasDBusThread()) { | 259 if (bus_->HasDBusThread()) { |
260 bus_->GetDBusTaskRunner()->PostTask( | 260 bus_->GetDBusTaskRunner()->PostTask( |
261 FROM_HERE, | 261 FROM_HERE, |
262 base::Bind(&ExportedObject::OnMethodCompleted, | 262 base::Bind(&ExportedObject::OnMethodCompleted, |
263 this, | 263 this, |
264 base::Passed(&method_call), | 264 base::Passed(&method_call), |
265 base::Passed(&response), | 265 base::Passed(&response), |
266 start_time)); | 266 start_time)); |
267 } else { | 267 } else { |
268 OnMethodCompleted(std::move(method_call), std::move(response), start_time); | 268 OnMethodCompleted(std::move(method_call), std::move(response), start_time); |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
272 void ExportedObject::OnMethodCompleted(scoped_ptr<MethodCall> method_call, | 272 void ExportedObject::OnMethodCompleted(std::unique_ptr<MethodCall> method_call, |
273 scoped_ptr<Response> response, | 273 std::unique_ptr<Response> response, |
274 base::TimeTicks start_time) { | 274 base::TimeTicks start_time) { |
275 bus_->AssertOnDBusThread(); | 275 bus_->AssertOnDBusThread(); |
276 | 276 |
277 // Record if the method call is successful, or not. 1 if successful. | 277 // Record if the method call is successful, or not. 1 if successful. |
278 UMA_HISTOGRAM_ENUMERATION("DBus.ExportedMethodHandleSuccess", | 278 UMA_HISTOGRAM_ENUMERATION("DBus.ExportedMethodHandleSuccess", |
279 response ? 1 : 0, | 279 response ? 1 : 0, |
280 kSuccessRatioHistogramMaxValue); | 280 kSuccessRatioHistogramMaxValue); |
281 | 281 |
282 // Check if the bus is still connected. If the method takes long to | 282 // Check if the bus is still connected. If the method takes long to |
283 // complete, the bus may be shut down meanwhile. | 283 // complete, the bus may be shut down meanwhile. |
284 if (!bus_->is_connected()) | 284 if (!bus_->is_connected()) |
285 return; | 285 return; |
286 | 286 |
287 if (!response) { | 287 if (!response) { |
288 // Something bad happened in the method call. | 288 // Something bad happened in the method call. |
289 scoped_ptr<ErrorResponse> error_response( | 289 std::unique_ptr<ErrorResponse> error_response(ErrorResponse::FromMethodCall( |
290 ErrorResponse::FromMethodCall( | 290 method_call.get(), DBUS_ERROR_FAILED, |
291 method_call.get(), | 291 "error occurred in " + method_call->GetMember())); |
292 DBUS_ERROR_FAILED, | |
293 "error occurred in " + method_call->GetMember())); | |
294 bus_->Send(error_response->raw_message(), NULL); | 292 bus_->Send(error_response->raw_message(), NULL); |
295 return; | 293 return; |
296 } | 294 } |
297 | 295 |
298 // The method call was successful. | 296 // The method call was successful. |
299 bus_->Send(response->raw_message(), NULL); | 297 bus_->Send(response->raw_message(), NULL); |
300 | 298 |
301 // Record time spent to handle the the method call. Don't include failures. | 299 // Record time spent to handle the the method call. Don't include failures. |
302 UMA_HISTOGRAM_TIMES("DBus.ExportedMethodHandleTime", | 300 UMA_HISTOGRAM_TIMES("DBus.ExportedMethodHandleTime", |
303 base::TimeTicks::Now() - start_time); | 301 base::TimeTicks::Now() - start_time); |
(...skipping 10 matching lines...) Expand all Loading... |
314 return self->HandleMessage(connection, raw_message); | 312 return self->HandleMessage(connection, raw_message); |
315 } | 313 } |
316 | 314 |
317 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, | 315 void ExportedObject::OnUnregisteredThunk(DBusConnection *connection, |
318 void* user_data) { | 316 void* user_data) { |
319 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); | 317 ExportedObject* self = reinterpret_cast<ExportedObject*>(user_data); |
320 return self->OnUnregistered(connection); | 318 return self->OnUnregistered(connection); |
321 } | 319 } |
322 | 320 |
323 } // namespace dbus | 321 } // namespace dbus |
OLD | NEW |