Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: dbus/object_proxy.cc

Issue 1074963003: Clean up potentially leaky use of base::DeletePointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed another probleb Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « dbus/object_proxy.h ('k') | device/core/device_monitor_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } else if (dbus_message_get_type(response_message) == 322 } else if (dbus_message_get_type(response_message) ==
323 DBUS_MESSAGE_TYPE_ERROR) { 323 DBUS_MESSAGE_TYPE_ERROR) {
324 // This will take |response_message| and release (unref) it. 324 // This will take |response_message| and release (unref) it.
325 scoped_ptr<ErrorResponse> error_response( 325 scoped_ptr<ErrorResponse> error_response(
326 ErrorResponse::FromRawMessage(response_message)); 326 ErrorResponse::FromRawMessage(response_message));
327 error_callback.Run(error_response.get()); 327 error_callback.Run(error_response.get());
328 // Delete the message on the D-Bus thread. See below for why. 328 // Delete the message on the D-Bus thread. See below for why.
329 bus_->GetDBusTaskRunner()->PostTask( 329 bus_->GetDBusTaskRunner()->PostTask(
330 FROM_HERE, 330 FROM_HERE,
331 base::Bind(&base::DeletePointer<ErrorResponse>, 331 base::Bind(&base::DeletePointer<ErrorResponse>,
332 error_response.release())); 332 base::Passed(&error_response)));
333 } else { 333 } else {
334 // This will take |response_message| and release (unref) it. 334 // This will take |response_message| and release (unref) it.
335 scoped_ptr<Response> response(Response::FromRawMessage(response_message)); 335 scoped_ptr<Response> response(Response::FromRawMessage(response_message));
336 // The response is successfully received. 336 // The response is successfully received.
337 response_callback.Run(response.get()); 337 response_callback.Run(response.get());
338 // The message should be deleted on the D-Bus thread for a complicated 338 // The message should be deleted on the D-Bus thread for a complicated
339 // reason: 339 // reason:
340 // 340 //
341 // libdbus keeps track of the number of bytes in the incoming message 341 // libdbus keeps track of the number of bytes in the incoming message
342 // queue to ensure that the data size in the queue is manageable. The 342 // queue to ensure that the data size in the queue is manageable. The
343 // bookkeeping is partly done via dbus_message_unref(), and immediately 343 // bookkeeping is partly done via dbus_message_unref(), and immediately
344 // asks the client code (Chrome) to stop monitoring the underlying 344 // asks the client code (Chrome) to stop monitoring the underlying
345 // socket, if the number of bytes exceeds a certian number, which is set 345 // socket, if the number of bytes exceeds a certian number, which is set
346 // to 63MB, per dbus-transport.cc: 346 // to 63MB, per dbus-transport.cc:
347 // 347 //
348 // /* Try to default to something that won't totally hose the system, 348 // /* Try to default to something that won't totally hose the system,
349 // * but doesn't impose too much of a limitation. 349 // * but doesn't impose too much of a limitation.
350 // */ 350 // */
351 // transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63; 351 // transport->max_live_messages_size = _DBUS_ONE_MEGABYTE * 63;
352 // 352 //
353 // The monitoring of the socket is done on the D-Bus thread (see Watch 353 // The monitoring of the socket is done on the D-Bus thread (see Watch
354 // class in bus.cc), hence we should stop the monitoring from D-Bus 354 // class in bus.cc), hence we should stop the monitoring from D-Bus
355 // thread, not from the current thread here, which is likely UI thread. 355 // thread, not from the current thread here, which is likely UI thread.
356 bus_->GetDBusTaskRunner()->PostTask( 356 bus_->GetDBusTaskRunner()->PostTask(
357 FROM_HERE, 357 FROM_HERE,
358 base::Bind(&base::DeletePointer<Response>, response.release())); 358 base::Bind(&base::DeletePointer<Response>, base::Passed(&response)));
359 359
360 method_call_successful = true; 360 method_call_successful = true;
361 // Record time spent for the method call. Don't include failures. 361 // Record time spent for the method call. Don't include failures.
362 UMA_HISTOGRAM_TIMES("DBus.AsyncMethodCallTime", 362 UMA_HISTOGRAM_TIMES("DBus.AsyncMethodCallTime",
363 base::TimeTicks::Now() - start_time); 363 base::TimeTicks::Now() - start_time);
364 } 364 }
365 // Record if the method call is successful, or not. 1 if successful. 365 // Record if the method call is successful, or not. 1 if successful.
366 UMA_HISTOGRAM_ENUMERATION("DBus.AsyncMethodCallSuccess", 366 UMA_HISTOGRAM_ENUMERATION("DBus.AsyncMethodCallSuccess",
367 method_call_successful, 367 method_call_successful,
368 kSuccessRatioHistogramMaxValue); 368 kSuccessRatioHistogramMaxValue);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 LOG(ERROR) << "Rejecting a message from a wrong sender."; 499 LOG(ERROR) << "Rejecting a message from a wrong sender.";
500 UMA_HISTOGRAM_COUNTS("DBus.RejectedSignalCount", 1); 500 UMA_HISTOGRAM_COUNTS("DBus.RejectedSignalCount", 1);
501 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 501 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
502 } 502 }
503 503
504 const base::TimeTicks start_time = base::TimeTicks::Now(); 504 const base::TimeTicks start_time = base::TimeTicks::Now();
505 if (bus_->HasDBusThread()) { 505 if (bus_->HasDBusThread()) {
506 // Post a task to run the method in the origin thread. 506 // Post a task to run the method in the origin thread.
507 // Transfer the ownership of |signal| to RunMethod(). 507 // Transfer the ownership of |signal| to RunMethod().
508 // |released_signal| will be deleted in RunMethod(). 508 // |released_signal| will be deleted in RunMethod().
509 Signal* released_signal = signal.release();
510 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, 509 bus_->GetOriginTaskRunner()->PostTask(FROM_HERE,
511 base::Bind(&ObjectProxy::RunMethod, 510 base::Bind(&ObjectProxy::RunMethod,
512 this, 511 this,
513 start_time, 512 start_time,
514 iter->second, 513 iter->second,
515 released_signal)); 514 base::Passed(&signal)));
516 } else { 515 } else {
517 const base::TimeTicks start_time = base::TimeTicks::Now(); 516 const base::TimeTicks start_time = base::TimeTicks::Now();
518 // If the D-Bus thread is not used, just call the callback on the 517 // If the D-Bus thread is not used, just call the callback on the
519 // current thread. Transfer the ownership of |signal| to RunMethod(). 518 // current thread. Transfer the ownership of |signal| to RunMethod().
520 Signal* released_signal = signal.release(); 519 RunMethod(start_time, iter->second, signal.Pass());
521 RunMethod(start_time, iter->second, released_signal);
522 } 520 }
523 521
524 // We don't return DBUS_HANDLER_RESULT_HANDLED for signals because other 522 // We don't return DBUS_HANDLER_RESULT_HANDLED for signals because other
525 // objects may be interested in them. (e.g. Signals from org.freedesktop.DBus) 523 // objects may be interested in them. (e.g. Signals from org.freedesktop.DBus)
526 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 524 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
527 } 525 }
528 526
529 void ObjectProxy::RunMethod(base::TimeTicks start_time, 527 void ObjectProxy::RunMethod(base::TimeTicks start_time,
530 std::vector<SignalCallback> signal_callbacks, 528 std::vector<SignalCallback> signal_callbacks,
531 Signal* signal) { 529 scoped_ptr<Signal> signal) {
532 bus_->AssertOnOriginThread(); 530 bus_->AssertOnOriginThread();
533 531
534 for (std::vector<SignalCallback>::iterator iter = signal_callbacks.begin(); 532 for (std::vector<SignalCallback>::iterator iter = signal_callbacks.begin();
535 iter != signal_callbacks.end(); ++iter) 533 iter != signal_callbacks.end(); ++iter)
536 iter->Run(signal); 534 iter->Run(signal.get());
537 535
538 // Delete the message on the D-Bus thread. See comments in 536 // Delete the message on the D-Bus thread. See comments in
539 // RunResponseCallback(). 537 // RunResponseCallback().
540 bus_->GetDBusTaskRunner()->PostTask( 538 bus_->GetDBusTaskRunner()->PostTask(
541 FROM_HERE, 539 FROM_HERE,
542 base::Bind(&base::DeletePointer<Signal>, signal)); 540 base::Bind(&base::DeletePointer<Signal>, base::Passed(&signal)));
543 541
544 // Record time spent for handling the signal. 542 // Record time spent for handling the signal.
545 UMA_HISTOGRAM_TIMES("DBus.SignalHandleTime", 543 UMA_HISTOGRAM_TIMES("DBus.SignalHandleTime",
546 base::TimeTicks::Now() - start_time); 544 base::TimeTicks::Now() - start_time);
547 } 545 }
548 546
549 DBusHandlerResult ObjectProxy::HandleMessageThunk( 547 DBusHandlerResult ObjectProxy::HandleMessageThunk(
550 DBusConnection* connection, 548 DBusConnection* connection,
551 DBusMessage* raw_message, 549 DBusMessage* raw_message,
552 void* user_data) { 550 void* user_data) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 bool service_is_available) { 698 bool service_is_available) {
701 bus_->AssertOnOriginThread(); 699 bus_->AssertOnOriginThread();
702 700
703 std::vector<WaitForServiceToBeAvailableCallback> callbacks; 701 std::vector<WaitForServiceToBeAvailableCallback> callbacks;
704 callbacks.swap(wait_for_service_to_be_available_callbacks_); 702 callbacks.swap(wait_for_service_to_be_available_callbacks_);
705 for (size_t i = 0; i < callbacks.size(); ++i) 703 for (size_t i = 0; i < callbacks.size(); ++i)
706 callbacks[i].Run(service_is_available); 704 callbacks[i].Run(service_is_available);
707 } 705 }
708 706
709 } // namespace dbus 707 } // namespace dbus
OLDNEW
« no previous file with comments | « dbus/object_proxy.h ('k') | device/core/device_monitor_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698