X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fexported_object.cc;h=308c14a7c13899419c4209b30bdec563a173a49a;hb=e503926ac19db158edb5aeb2f5938dbf67ba1f72;hp=cabf1a22f325716ec1ebaeb368451b78521d1969;hpb=2d6607648a3ab1d8a8f39f04bacee720eee5e06d;p=platform%2Fframework%2Fweb%2Fchromium-efl.git diff --git a/dbus/exported_object.cc b/dbus/exported_object.cc index cabf1a2..308c14a 100644 --- a/dbus/exported_object.cc +++ b/dbus/exported_object.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,14 +7,15 @@ #include #include -#include "base/bind.h" +#include "base/containers/contains.h" +#include "base/functional/bind.h" #include "base/logging.h" #include "base/memory/ref_counted.h" -#include "base/metrics/histogram_macros.h" -#include "base/task_runner.h" +#include "base/task/sequenced_task_runner.h" +#include "base/task/task_runner.h" #include "base/threading/thread_restrictions.h" -#include "base/time/time.h" #include "dbus/bus.h" +#include "dbus/error.h" #include "dbus/message.h" #include "dbus/object_path.h" #include "dbus/scoped_dbus_error.h" @@ -22,13 +23,6 @@ namespace dbus { -namespace { - -// Used for success ratio histograms. 1 for success, 0 for failure. -const int kSuccessRatioHistogramMaxValue = 2; - -} // namespace - ExportedObject::ExportedObject(Bus* bus, const ObjectPath& object_path) : bus_(bus), @@ -44,13 +38,13 @@ ExportedObject::~ExportedObject() { bool ExportedObject::ExportMethodAndBlock( const std::string& interface_name, const std::string& method_name, - MethodCallCallback method_call_callback) { + const MethodCallCallback& method_call_callback) { bus_->AssertOnDBusThread(); // Check if the method is already exported. const std::string absolute_method_name = GetAbsoluteMemberName(interface_name, method_name); - if (method_table_.find(absolute_method_name) != method_table_.end()) { + if (base::Contains(method_table_, absolute_method_name)) { LOG(ERROR) << absolute_method_name << " is already exported"; return false; } @@ -85,31 +79,29 @@ bool ExportedObject::UnexportMethodAndBlock(const std::string& interface_name, return true; } -void ExportedObject::ExportMethod(const std::string& interface_name, - const std::string& method_name, - MethodCallCallback method_call_callback, - OnExportedCallback on_exported_calback) { +void ExportedObject::ExportMethod( + const std::string& interface_name, + const std::string& method_name, + const MethodCallCallback& method_call_callback, + OnExportedCallback on_exported_callback) { bus_->AssertOnOriginThread(); - base::Closure task = base::Bind(&ExportedObject::ExportMethodInternal, - this, - interface_name, - method_name, - method_call_callback, - on_exported_calback); - bus_->GetDBusTaskRunner()->PostTask(FROM_HERE, task); + base::OnceClosure task = base::BindOnce( + &ExportedObject::ExportMethodInternal, this, interface_name, method_name, + method_call_callback, std::move(on_exported_callback)); + bus_->GetDBusTaskRunner()->PostTask(FROM_HERE, std::move(task)); } void ExportedObject::UnexportMethod( const std::string& interface_name, const std::string& method_name, - OnUnexportedCallback on_unexported_calback) { + OnUnexportedCallback on_unexported_callback) { bus_->AssertOnOriginThread(); - base::Closure task = - base::Bind(&ExportedObject::UnexportMethodInternal, this, interface_name, - method_name, on_unexported_calback); - bus_->GetDBusTaskRunner()->PostTask(FROM_HERE, task); + base::OnceClosure task = base::BindOnce( + &ExportedObject::UnexportMethodInternal, this, interface_name, + method_name, std::move(on_unexported_callback)); + bus_->GetDBusTaskRunner()->PostTask(FROM_HERE, std::move(task)); } void ExportedObject::SendSignal(Signal* signal) { @@ -123,21 +115,17 @@ void ExportedObject::SendSignal(Signal* signal) { DBusMessage* signal_message = signal->raw_message(); dbus_message_ref(signal_message); - const base::TimeTicks start_time = base::TimeTicks::Now(); if (bus_->GetDBusTaskRunner()->RunsTasksInCurrentSequence()) { // The Chrome OS power manager doesn't use a dedicated TaskRunner for // sending DBus messages. Sending signals asynchronously can cause an // inversion in the message order if the power manager calls // ObjectProxy::CallMethodAndBlock() before going back to the top level of // the MessageLoop: crbug.com/472361. - SendSignalInternal(start_time, signal_message); + SendSignalInternal(signal_message); } else { bus_->GetDBusTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&ExportedObject::SendSignalInternal, - this, - start_time, - signal_message)); + FROM_HERE, base::BindOnce(&ExportedObject::SendSignalInternal, this, + signal_message)); } } @@ -154,33 +142,30 @@ void ExportedObject::Unregister() { void ExportedObject::ExportMethodInternal( const std::string& interface_name, const std::string& method_name, - MethodCallCallback method_call_callback, - OnExportedCallback on_exported_calback) { + const MethodCallCallback& method_call_callback, + OnExportedCallback on_exported_callback) { bus_->AssertOnDBusThread(); const bool success = ExportMethodAndBlock(interface_name, method_name, method_call_callback); - bus_->GetOriginTaskRunner()->PostTask(FROM_HERE, - base::Bind(&ExportedObject::OnExported, - this, - on_exported_calback, - interface_name, - method_name, - success)); + bus_->GetOriginTaskRunner()->PostTask( + FROM_HERE, base::BindOnce(&ExportedObject::OnExported, this, + std::move(on_exported_callback), interface_name, + method_name, success)); } void ExportedObject::UnexportMethodInternal( const std::string& interface_name, const std::string& method_name, - OnUnexportedCallback on_unexported_calback) { + OnUnexportedCallback on_unexported_callback) { bus_->AssertOnDBusThread(); const bool success = UnexportMethodAndBlock(interface_name, method_name); bus_->GetOriginTaskRunner()->PostTask( - FROM_HERE, - base::Bind(&ExportedObject::OnUnexported, this, on_unexported_calback, - interface_name, method_name, success)); + FROM_HERE, base::BindOnce(&ExportedObject::OnUnexported, this, + std::move(on_unexported_callback), + interface_name, method_name, success)); } void ExportedObject::OnExported(OnExportedCallback on_exported_callback, @@ -189,7 +174,7 @@ void ExportedObject::OnExported(OnExportedCallback on_exported_callback, bool success) { bus_->AssertOnOriginThread(); - on_exported_callback.Run(interface_name, method_name, success); + std::move(on_exported_callback).Run(interface_name, method_name, success); } void ExportedObject::OnUnexported(OnExportedCallback on_unexported_callback, @@ -198,19 +183,13 @@ void ExportedObject::OnUnexported(OnExportedCallback on_unexported_callback, bool success) { bus_->AssertOnOriginThread(); - on_unexported_callback.Run(interface_name, method_name, success); + std::move(on_unexported_callback).Run(interface_name, method_name, success); } -void ExportedObject::SendSignalInternal(base::TimeTicks start_time, - DBusMessage* signal_message) { +void ExportedObject::SendSignalInternal(DBusMessage* signal_message) { uint32_t serial = 0; bus_->Send(signal_message, &serial); dbus_message_unref(signal_message); - // Record time spent to send the the signal. This is not accurate as the - // signal will actually be sent from the next run of the message loop, - // but we can at least tell the number of signals sent. - UMA_HISTOGRAM_TIMES("DBus.SignalSendTime", - base::TimeTicks::Now() - start_time); } bool ExportedObject::Register() { @@ -219,18 +198,16 @@ bool ExportedObject::Register() { if (object_is_registered_) return true; - ScopedDBusError error; + Error error; DBusObjectPathVTable vtable = {}; vtable.message_function = &ExportedObject::HandleMessageThunk; vtable.unregister_function = &ExportedObject::OnUnregisteredThunk; - const bool success = bus_->TryRegisterObjectPath(object_path_, - &vtable, - this, - error.get()); + const bool success = + bus_->TryRegisterObjectPath(object_path_, &vtable, this, &error); if (!success) { LOG(ERROR) << "Failed to register the object: " << object_path_.value() - << ": " << (error.is_set() ? error.message() : ""); + << ": " << error.message(); return false; } @@ -271,21 +248,16 @@ DBusHandlerResult ExportedObject::HandleMessage( return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - const base::TimeTicks start_time = base::TimeTicks::Now(); if (bus_->HasDBusThread()) { // Post a task to run the method in the origin thread. bus_->GetOriginTaskRunner()->PostTask( - FROM_HERE, - base::BindOnce(&ExportedObject::RunMethod, this, iter->second, - std::move(method_call), start_time)); + FROM_HERE, base::BindOnce(&ExportedObject::RunMethod, this, + iter->second, std::move(method_call))); } else { // If the D-Bus thread is not used, just call the method directly. MethodCall* method = method_call.get(); - iter->second.Run(method, - base::Bind(&ExportedObject::SendResponse, - this, - start_time, - base::Passed(&method_call))); + iter->second.Run(method, base::BindOnce(&ExportedObject::SendResponse, this, + std::move(method_call))); } // It's valid to say HANDLED here, and send a method response at a later @@ -293,42 +265,31 @@ DBusHandlerResult ExportedObject::HandleMessage( return DBUS_HANDLER_RESULT_HANDLED; } -void ExportedObject::RunMethod(MethodCallCallback method_call_callback, - std::unique_ptr method_call, - base::TimeTicks start_time) { +void ExportedObject::RunMethod(const MethodCallCallback& method_call_callback, + std::unique_ptr method_call) { bus_->AssertOnOriginThread(); MethodCall* method = method_call.get(); method_call_callback.Run(method, - base::Bind(&ExportedObject::SendResponse, - this, - start_time, - base::Passed(&method_call))); + base::BindOnce(&ExportedObject::SendResponse, this, + std::move(method_call))); } -void ExportedObject::SendResponse(base::TimeTicks start_time, - std::unique_ptr method_call, +void ExportedObject::SendResponse(std::unique_ptr method_call, std::unique_ptr response) { DCHECK(method_call); if (bus_->HasDBusThread()) { bus_->GetDBusTaskRunner()->PostTask( FROM_HERE, base::BindOnce(&ExportedObject::OnMethodCompleted, this, - std::move(method_call), std::move(response), - start_time)); + std::move(method_call), std::move(response))); } else { - OnMethodCompleted(std::move(method_call), std::move(response), start_time); + OnMethodCompleted(std::move(method_call), std::move(response)); } } void ExportedObject::OnMethodCompleted(std::unique_ptr method_call, - std::unique_ptr response, - base::TimeTicks start_time) { + std::unique_ptr response) { bus_->AssertOnDBusThread(); - // Record if the method call is successful, or not. 1 if successful. - UMA_HISTOGRAM_ENUMERATION("DBus.ExportedMethodHandleSuccess", - response ? 1 : 0, - kSuccessRatioHistogramMaxValue); - // Check if the bus is still connected. If the method takes long to // complete, the bus may be shut down meanwhile. if (!bus_->IsConnected()) @@ -345,10 +306,6 @@ void ExportedObject::OnMethodCompleted(std::unique_ptr method_call, // The method call was successful. bus_->Send(response->raw_message(), nullptr); - - // Record time spent to handle the the method call. Don't include failures. - UMA_HISTOGRAM_TIMES("DBus.ExportedMethodHandleTime", - base::TimeTicks::Now() - start_time); } void ExportedObject::OnUnregistered(DBusConnection* connection) {