summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryuki@chromium.org <yuki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-07 09:46:24 +0000
committeryuki@chromium.org <yuki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-07 09:46:24 +0000
commit9b25d4557040da82c582d7dca22bc7a334a97f48 (patch)
tree4abc6ffa62f5cb58262d182843aade883eaed1e5
parentd43177fa5c889a451b6a033c970a7e25bcb6ad37 (diff)
downloadchromium_src-9b25d4557040da82c582d7dca22bc7a334a97f48.zip
chromium_src-9b25d4557040da82c582d7dca22bc7a334a97f48.tar.gz
chromium_src-9b25d4557040da82c582d7dca22bc7a334a97f48.tar.bz2
Code cleaning: Uses scoped_ptr<> to express ownership rather than writing ownership in comments.
Replaces Response* with scoped_ptr<Response> in dbus code and its related code. BUG=163231 TEST=no regression / no behavior changes Review URL: https://chromiumcodereview.appspot.com/12092061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181266 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/dbus/liveness_service_provider.cc3
-rw-r--r--chrome/browser/chromeos/dbus/proxy_resolution_service_provider.cc7
-rw-r--r--chrome/browser/chromeos/dbus/service_provider_test_helper.cc19
-rw-r--r--chrome/browser/chromeos/dbus/service_provider_test_helper.h10
-rw-r--r--chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc32
-rw-r--r--chromeos/dbus/blocking_method_caller.cc8
-rw-r--r--chromeos/dbus/blocking_method_caller.h6
-rw-r--r--chromeos/dbus/blocking_method_caller_unittest.cc8
-rw-r--r--chromeos/dbus/bluetooth_agent_service_provider.cc71
-rw-r--r--chromeos/dbus/ibus/ibus_engine_factory_service.cc8
-rw-r--r--chromeos/dbus/ibus/ibus_engine_factory_service_unittest.cc22
-rw-r--r--chromeos/dbus/ibus/ibus_engine_service.cc42
-rw-r--r--chromeos/dbus/ibus/ibus_engine_service_unittest.cc60
-rw-r--r--chromeos/dbus/ibus/ibus_panel_service.cc27
-rw-r--r--chromeos/dbus/ibus/ibus_panel_service_unittest.cc23
-rw-r--r--chromeos/dbus/shill_client_unittest_base.cc4
-rw-r--r--content/browser/geolocation/wifi_data_provider_linux.cc17
-rw-r--r--content/browser/geolocation/wifi_data_provider_linux_unittest.cc38
-rw-r--r--dbus/exported_object.cc33
-rw-r--r--dbus/exported_object.h17
-rw-r--r--dbus/message.cc32
-rw-r--r--dbus/message.h34
-rw-r--r--dbus/mock_object_proxy.h14
-rw-r--r--dbus/mock_unittest.cc8
-rw-r--r--dbus/object_proxy.cc8
-rw-r--r--dbus/object_proxy.h5
-rw-r--r--dbus/test_service.cc59
27 files changed, 306 insertions, 309 deletions
diff --git a/chrome/browser/chromeos/dbus/liveness_service_provider.cc b/chrome/browser/chromeos/dbus/liveness_service_provider.cc
index 3954974..9be70e3 100644
--- a/chrome/browser/chromeos/dbus/liveness_service_provider.cc
+++ b/chrome/browser/chromeos/dbus/liveness_service_provider.cc
@@ -47,8 +47,7 @@ void LivenessServiceProvider::CheckLiveness(
dbus::MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/dbus/proxy_resolution_service_provider.cc b/chrome/browser/chromeos/dbus/proxy_resolution_service_provider.cc
index a2ecec4..2f4a639 100644
--- a/chrome/browser/chromeos/dbus/proxy_resolution_service_provider.cc
+++ b/chrome/browser/chromeos/dbus/proxy_resolution_service_provider.cc
@@ -239,7 +239,7 @@ void ProxyResolutionServiceProvider::ResolveProxyHandler(
!reader.PopString(&signal_interface) ||
!reader.PopString(&signal_name)) {
LOG(ERROR) << "Unexpected method call: " << method_call->ToString();
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
@@ -250,8 +250,7 @@ void ProxyResolutionServiceProvider::ResolveProxyHandler(
// Send an empty response for now. We'll send a signal once the network proxy
// resolution is completed.
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// static
@@ -261,7 +260,7 @@ void ProxyResolutionServiceProvider::CallResolveProxyHandler(
dbus::ExportedObject::ResponseSender response_sender) {
if (!provider_weak_ptr) {
LOG(WARNING) << "Called after the object is deleted";
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
provider_weak_ptr->ResolveProxyHandler(method_call, response_sender);
diff --git a/chrome/browser/chromeos/dbus/service_provider_test_helper.cc b/chrome/browser/chromeos/dbus/service_provider_test_helper.cc
index afc9ec6..57ee646 100644
--- a/chrome/browser/chromeos/dbus/service_provider_test_helper.cc
+++ b/chrome/browser/chromeos/dbus/service_provider_test_helper.cc
@@ -57,17 +57,17 @@ void ServiceProviderTestHelper::SetUp(
new dbus::MockObjectProxy(mock_bus_.get(),
kLibCrosServiceName,
dbus::ObjectPath(kLibCrosServicePath));
- // |mock_object_proxy_|'s CallMethodAndBlock() will use
+ // |mock_object_proxy_|'s MockCallMethodAndBlock() will use
// MockCallMethodAndBlock() to return responses.
EXPECT_CALL(*mock_object_proxy_,
- CallMethodAndBlock(
+ MockCallMethodAndBlock(
AllOf(
ResultOf(
std::mem_fun(&dbus::MethodCall::GetInterface),
- kLibCrosServiceInterface),
+ kLibCrosServiceInterface),
ResultOf(
std::mem_fun(&dbus::MethodCall::GetMember),
- exported_method_name)),
+ exported_method_name)),
_))
.WillOnce(Invoke(this,
&ServiceProviderTestHelper::MockCallMethodAndBlock));
@@ -102,9 +102,10 @@ void ServiceProviderTestHelper::SetUpReturnSignal(
signal_callback, on_connected_callback);
}
-dbus::Response* ServiceProviderTestHelper::CallMethod(
+scoped_ptr<dbus::Response> ServiceProviderTestHelper::CallMethod(
dbus::MethodCall* method_call) {
- return mock_object_proxy_->CallMethodAndBlock(method_call,
+ return mock_object_proxy_->CallMethodAndBlock(
+ method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
}
@@ -155,12 +156,12 @@ void ServiceProviderTestHelper::MockSendSignal(dbus::Signal* signal) {
on_signal_callback_.Run(signal);
}
-void ServiceProviderTestHelper::OnResponse(dbus::Response* response) {
- response_.reset(response);
+void ServiceProviderTestHelper::OnResponse(
+ scoped_ptr<dbus::Response> response) {
+ response_ = response.Pass();
response_received_ = true;
if (message_loop_.is_running())
message_loop_.Quit();
}
} // namespace chromeos
-
diff --git a/chrome/browser/chromeos/dbus/service_provider_test_helper.h b/chrome/browser/chromeos/dbus/service_provider_test_helper.h
index af5cb8e..17f6f8a 100644
--- a/chrome/browser/chromeos/dbus/service_provider_test_helper.h
+++ b/chrome/browser/chromeos/dbus/service_provider_test_helper.h
@@ -52,7 +52,7 @@ class ServiceProviderTestHelper {
dbus::ObjectProxy::OnConnectedCallback on_connected_callback);
// Calls tested dbus method.
- dbus::Response* CallMethod(dbus::MethodCall* method_call);
+ scoped_ptr<dbus::Response> CallMethod(dbus::MethodCall* method_call);
// Cleanups helper. Should be called after |CallMethod()|.
void TearDown();
@@ -66,8 +66,9 @@ class ServiceProviderTestHelper {
dbus::ExportedObject::OnExportedCallback on_exported_callback);
// Calls exported method and waits for a response for |mock_object_proxy_|.
- dbus::Response* MockCallMethodAndBlock(dbus::MethodCall* method_call,
- ::testing::Unused);
+ dbus::Response* MockCallMethodAndBlock(
+ dbus::MethodCall* method_call,
+ ::testing::Unused);
// Behaves as |mock_object_proxy_|'s ConnectToSignal().
void MockConnectToSignal(
@@ -80,7 +81,7 @@ class ServiceProviderTestHelper {
void MockSendSignal(dbus::Signal* signal);
// Receives a response and makes it available to MockCallMethodAndBlock().
- void OnResponse(dbus::Response* response);
+ void OnResponse(scoped_ptr<dbus::Response> response);
scoped_refptr<dbus::MockBus> mock_bus_;
scoped_refptr<dbus::MockExportedObject> mock_exported_object_;
@@ -95,4 +96,3 @@ class ServiceProviderTestHelper {
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_DBUS_SERVICE_PROVIDER_TEST_HELPER_H_
-
diff --git a/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc b/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc
index 12e6ca4..190b40e 100644
--- a/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc
+++ b/chrome/browser/password_manager/native_backend_kwallet_x_unittest.cc
@@ -251,7 +251,7 @@ void NativeBackendKWalletTest::SetUp() {
"org.kde.klauncher",
dbus::ObjectPath("/KLauncher"));
EXPECT_CALL(*mock_klauncher_proxy_,
- CallMethodAndBlock(_, _))
+ MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(this,
&NativeBackendKWalletTest::KLauncherMethodCall));
@@ -260,7 +260,7 @@ void NativeBackendKWalletTest::SetUp() {
"org.kde.kwalletd",
dbus::ObjectPath("/modules/kwalletd"));
EXPECT_CALL(*mock_kwallet_proxy_,
- CallMethodAndBlock(_, _))
+ MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(this,
&NativeBackendKWalletTest::KWalletMethodCall));
@@ -312,13 +312,13 @@ dbus::Response* NativeBackendKWalletTest::KLauncherMethodCall(
if (kwallet_runnable_)
kwallet_running_ = true;
- dbus::Response* response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
+ dbus::MessageWriter writer(response.get());
writer.AppendInt32(klauncher_ret_);
writer.AppendString(""); // dbus_name
writer.AppendString(klauncher_error_);
writer.AppendInt32(1234); // pid
- return response;
+ return response.release();
}
dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
@@ -327,14 +327,14 @@ dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
return NULL;
EXPECT_EQ("org.kde.KWallet", method_call->GetInterface());
- dbus::Response* response = NULL;
+ scoped_ptr<dbus::Response> response;
if (method_call->GetMember() == "isEnabled") {
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendBool(kwallet_enabled_);
} else if (method_call->GetMember() == "networkWallet") {
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendString("test_wallet"); // Should match |open| below.
} else if (method_call->GetMember() == "open") {
dbus::MessageReader reader(method_call);
@@ -346,7 +346,7 @@ dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
EXPECT_TRUE(reader.PopString(&app_name));
EXPECT_EQ("test_wallet", wallet_name); // Should match |networkWallet|.
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendInt32(1); // Can be anything but kInvalidKWalletHandle.
} else if (method_call->GetMember() == "hasFolder" ||
method_call->GetMember() == "createFolder") {
@@ -359,7 +359,7 @@ dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
EXPECT_TRUE(reader.PopString(&app_name));
EXPECT_NE(NativeBackendKWalletStub::kInvalidKWalletHandle, handle);
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
if (method_call->GetMember() == "hasFolder")
writer.AppendBool(wallet_.hasFolder(folder_name));
else
@@ -377,7 +377,7 @@ dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
EXPECT_TRUE(reader.PopString(&app_name));
EXPECT_NE(NativeBackendKWalletStub::kInvalidKWalletHandle, handle);
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
if (method_call->GetMember() == "hasEntry")
writer.AppendBool(wallet_.hasEntry(folder_name, key));
else
@@ -394,7 +394,7 @@ dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
std::vector<std::string> entries;
if (wallet_.entryList(folder_name, &entries)) {
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendArrayOfStrings(entries);
}
} else if (method_call->GetMember() == "readEntry") {
@@ -411,7 +411,7 @@ dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
TestKWallet::Blob value;
if (wallet_.readEntry(folder_name, key, &value)) {
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendArrayOfBytes(value.data(), value.size());
}
} else if (method_call->GetMember() == "writeEntry") {
@@ -429,14 +429,14 @@ dbus::Response* NativeBackendKWalletTest::KWalletMethodCall(
EXPECT_TRUE(reader.PopString(&app_name));
EXPECT_NE(NativeBackendKWalletStub::kInvalidKWalletHandle, handle);
response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendInt32(
wallet_.writeEntry(folder_name, key,
TestKWallet::Blob(bytes, length)) ? 0 : 1);
}
- EXPECT_FALSE(response == NULL);
- return response;
+ EXPECT_FALSE(response.get() == NULL);
+ return response.release();
}
void NativeBackendKWalletTest::CheckPasswordForms(
diff --git a/chromeos/dbus/blocking_method_caller.cc b/chromeos/dbus/blocking_method_caller.cc
index 91c796c..5fc0c9a 100644
--- a/chromeos/dbus/blocking_method_caller.cc
+++ b/chromeos/dbus/blocking_method_caller.cc
@@ -15,7 +15,7 @@ namespace {
// This function is a part of CallMethodAndBlock implementation.
void CallMethodAndBlockInternal(
- dbus::Response** response,
+ scoped_ptr<dbus::Response>* response,
base::ScopedClosureRunner* signaler,
dbus::ObjectProxy* proxy,
dbus::MethodCall* method_call) {
@@ -36,7 +36,7 @@ BlockingMethodCaller::BlockingMethodCaller(dbus::Bus* bus,
BlockingMethodCaller::~BlockingMethodCaller() {
}
-dbus::Response* BlockingMethodCaller::CallMethodAndBlock(
+scoped_ptr<dbus::Response> BlockingMethodCaller::CallMethodAndBlock(
dbus::MethodCall* method_call) {
// on_blocking_method_call_->Signal() will be called when |signaler| is
// destroyed.
@@ -46,7 +46,7 @@ dbus::Response* BlockingMethodCaller::CallMethodAndBlock(
base::ScopedClosureRunner* signaler =
new base::ScopedClosureRunner(signal_task);
- dbus::Response* response = NULL;
+ scoped_ptr<dbus::Response> response;
bus_->PostTaskToDBusThread(
FROM_HERE,
base::Bind(&CallMethodAndBlockInternal,
@@ -57,7 +57,7 @@ dbus::Response* BlockingMethodCaller::CallMethodAndBlock(
// http://crbug.com/125360
base::ThreadRestrictions::ScopedAllowWait allow_wait;
on_blocking_method_call_.Wait();
- return response;
+ return response.Pass();
}
} // namespace chromeos
diff --git a/chromeos/dbus/blocking_method_caller.h b/chromeos/dbus/blocking_method_caller.h
index 95aa440..6291f47 100644
--- a/chromeos/dbus/blocking_method_caller.h
+++ b/chromeos/dbus/blocking_method_caller.h
@@ -8,13 +8,12 @@
#include "base/callback.h"
#include "base/synchronization/waitable_event.h"
#include "chromeos/chromeos_export.h"
+#include "dbus/message.h"
namespace dbus {
class Bus;
class ObjectProxy;
-class MethodCall;
-class Response;
} // namespace dbus
@@ -29,8 +28,7 @@ class CHROMEOS_EXPORT BlockingMethodCaller {
virtual ~BlockingMethodCaller();
// Calls the method and blocks until it returns.
- // The caller is responsible to delete the returned object.
- dbus::Response* CallMethodAndBlock(dbus::MethodCall* method_call);
+ scoped_ptr<dbus::Response> CallMethodAndBlock(dbus::MethodCall* method_call);
private:
dbus::Bus* bus_;
diff --git a/chromeos/dbus/blocking_method_caller_unittest.cc b/chromeos/dbus/blocking_method_caller_unittest.cc
index eb2394a..2abfd64 100644
--- a/chromeos/dbus/blocking_method_caller_unittest.cc
+++ b/chromeos/dbus/blocking_method_caller_unittest.cc
@@ -39,7 +39,7 @@ class BlockingMethodCallerTest : public testing::Test {
// Set an expectation so mock_proxy's CallMethodAndBlock() will use
// CreateMockProxyResponse() to return responses.
- EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _))
+ EXPECT_CALL(*mock_proxy_, MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(
this, &BlockingMethodCallerTest::CreateMockProxyResponse));
@@ -78,10 +78,10 @@ class BlockingMethodCallerTest : public testing::Test {
dbus::MessageReader reader(method_call);
std::string text_message;
if (reader.PopString(&text_message)) {
- dbus::Response* response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty();
+ dbus::MessageWriter writer(response.get());
writer.AppendString(text_message);
- return response;
+ return response.release();
}
}
diff --git a/chromeos/dbus/bluetooth_agent_service_provider.cc b/chromeos/dbus/bluetooth_agent_service_provider.cc
index 9543cc5..2b3811c 100644
--- a/chromeos/dbus/bluetooth_agent_service_provider.cc
+++ b/chromeos/dbus/bluetooth_agent_service_provider.cc
@@ -139,8 +139,7 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
delegate_->Release();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Called by dbus:: when the Release method is exported.
@@ -235,8 +234,7 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
delegate_->DisplayPinCode(device_path, pincode);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Called by dbus:: when the DisplayPinCode method is exported.
@@ -267,8 +265,7 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
delegate_->DisplayPasskey(device_path, passkey);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Called by dbus:: when the DisplayPasskey method is exported.
@@ -404,8 +401,7 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
delegate_->Cancel();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Called by dbus:: when the Cancel method is exported.
@@ -425,22 +421,25 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
switch (status) {
case Delegate::SUCCESS: {
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response(
+ dbus::Response::FromMethodCall(method_call));
+ dbus::MessageWriter writer(response.get());
writer.AppendString(pincode);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
break;
}
case Delegate::REJECTED: {
- dbus::ErrorResponse* response = dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorRejected, "rejected");
- response_sender.Run(response);
+ response_sender.Run(
+ dbus::ErrorResponse::FromMethodCall(
+ method_call, bluetooth_agent::kErrorRejected, "rejected")
+ .PassAs<dbus::Response>());
break;
}
case Delegate::CANCELLED: {
- dbus::ErrorResponse* response = dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorCanceled, "canceled");
- response_sender.Run(response);
+ response_sender.Run(
+ dbus::ErrorResponse::FromMethodCall(
+ method_call, bluetooth_agent::kErrorCanceled, "canceled")
+ .PassAs<dbus::Response>());
break;
}
default:
@@ -457,22 +456,25 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
switch (status) {
case Delegate::SUCCESS: {
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response(
+ dbus::Response::FromMethodCall(method_call));
+ dbus::MessageWriter writer(response.get());
writer.AppendUint32(passkey);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
break;
}
case Delegate::REJECTED: {
- dbus::ErrorResponse* response = dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorRejected, "rejected");
- response_sender.Run(response);
+ response_sender.Run(
+ dbus::ErrorResponse::FromMethodCall(
+ method_call, bluetooth_agent::kErrorRejected, "rejected")
+ .PassAs<dbus::Response>());
break;
}
case Delegate::CANCELLED: {
- dbus::ErrorResponse* response = dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorCanceled, "canceled");
- response_sender.Run(response);
+ response_sender.Run(
+ dbus::ErrorResponse::FromMethodCall(
+ method_call, bluetooth_agent::kErrorCanceled, "canceled")
+ .PassAs<dbus::Response>());
break;
}
default:
@@ -488,20 +490,21 @@ class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
switch (status) {
case Delegate::SUCCESS: {
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
break;
}
case Delegate::REJECTED: {
- dbus::ErrorResponse* response = dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorRejected, "rejected");
- response_sender.Run(response);
+ response_sender.Run(
+ dbus::ErrorResponse::FromMethodCall(
+ method_call, bluetooth_agent::kErrorRejected, "rejected")
+ .PassAs<dbus::Response>());
break;
}
case Delegate::CANCELLED: {
- dbus::ErrorResponse* response = dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorCanceled, "canceled");
- response_sender.Run(response);
+ response_sender.Run(
+ dbus::ErrorResponse::FromMethodCall(
+ method_call, bluetooth_agent::kErrorCanceled, "canceled")
+ .PassAs<dbus::Response>());
break;
}
default:
diff --git a/chromeos/dbus/ibus/ibus_engine_factory_service.cc b/chromeos/dbus/ibus/ibus_engine_factory_service.cc
index 936b54f..49ca041 100644
--- a/chromeos/dbus/ibus/ibus_engine_factory_service.cc
+++ b/chromeos/dbus/ibus/ibus_engine_factory_service.cc
@@ -73,19 +73,19 @@ class IBusEngineFactoryServiceImpl : public IBusEngineFactoryService {
create_engine_callback_map_[engine_name].Run(
base::Bind(&IBusEngineFactoryServiceImpl::CreateEngineSendReply,
weak_ptr_factory_.GetWeakPtr(),
- dbus::Response::FromMethodCall(method_call),
+ base::Passed(dbus::Response::FromMethodCall(method_call)),
response_sender));
}
}
// Sends reply message for CreateEngine method call.
void CreateEngineSendReply(
- dbus::Response* response,
+ scoped_ptr<dbus::Response> response,
const dbus::ExportedObject::ResponseSender response_sender,
const dbus::ObjectPath& path) {
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendObjectPath(path);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
}
// Called when the CreateEngine method is exported.
diff --git a/chromeos/dbus/ibus/ibus_engine_factory_service_unittest.cc b/chromeos/dbus/ibus/ibus_engine_factory_service_unittest.cc
index 205422d..c3c2aa6 100644
--- a/chromeos/dbus/ibus/ibus_engine_factory_service_unittest.cc
+++ b/chromeos/dbus/ibus/ibus_engine_factory_service_unittest.cc
@@ -58,16 +58,22 @@ class MockCreateEngineResponseSender {
public:
explicit MockCreateEngineResponseSender(const dbus::ObjectPath& expected_path)
: expected_path_(expected_path) {}
- MOCK_METHOD1(Run, void(dbus::Response*));
+ // GMock doesn't support mocking methods which take scoped_ptr<>.
+ MOCK_METHOD1(MockRun, void(dbus::Response*));
+ void Run(scoped_ptr<dbus::Response> response) {
+ MockRun(response.get());
+ }
// Checks the given |response| meets expectation for the CreateEngine method.
- void CheckCreateEngineResponse(dbus::Response* response) {
- scoped_ptr<dbus::Response> response_deleter(response);
+ void CheckCreateEngineResponsePtr(dbus::Response* response) {
dbus::MessageReader reader(response);
dbus::ObjectPath actual_path;
ASSERT_TRUE(reader.PopObjectPath(&actual_path));
EXPECT_EQ(expected_path_, actual_path);
}
+ void CheckCreateEngineResponse(scoped_ptr<dbus::Response> response) {
+ CheckCreateEngineResponsePtr(response.get());
+ }
private:
dbus::ObjectPath expected_path_;
@@ -143,10 +149,11 @@ TEST_F(IBusEngineFactoryServiceTest, SyncCreateEngineTest) {
const char kSampleEngine[] = "Sample Engine";
const dbus::ObjectPath kObjectPath("/org/freedesktop/IBus/Engine/10");
MockCreateEngineResponseSender response_sender(kObjectPath);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(
Invoke(&response_sender,
- &MockCreateEngineResponseSender::CheckCreateEngineResponse));
+ &MockCreateEngineResponseSender::
+ CheckCreateEngineResponsePtr));
SynchronousCreateEngineHandler handler(kObjectPath);
// Set handler expectations.
@@ -185,10 +192,11 @@ TEST_F(IBusEngineFactoryServiceTest, AsyncCreateEngineTest) {
const char kSampleEngine[] = "Sample Engine";
const dbus::ObjectPath kObjectPath("/org/freedesktop/IBus/Engine/10");
MockCreateEngineResponseSender response_sender(kObjectPath);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(
Invoke(&response_sender,
- &MockCreateEngineResponseSender::CheckCreateEngineResponse));
+ &MockCreateEngineResponseSender::
+ CheckCreateEngineResponsePtr));
AsynchronousCreateEngineHandler handler(kObjectPath, &message_loop_);
// Set handler expectations.
diff --git a/chromeos/dbus/ibus/ibus_engine_service.cc b/chromeos/dbus/ibus/ibus_engine_service.cc
index c7ec1ae..81d37c8 100644
--- a/chromeos/dbus/ibus/ibus_engine_service.cc
+++ b/chromeos/dbus/ibus/ibus_engine_service.cc
@@ -232,8 +232,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
if (engine_handler_ == NULL)
return;
engine_handler_->FocusIn();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles FocusOut method call from ibus-daemon.
@@ -242,8 +241,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
if (engine_handler_ == NULL)
return;
engine_handler_->FocusOut();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles Enable method call from ibus-daemon.
@@ -252,8 +250,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
if (engine_handler_ == NULL)
return;
engine_handler_->Enable();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles Disable method call from ibus-daemon.
@@ -262,8 +259,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
if (engine_handler_ == NULL)
return;
engine_handler_->Disable();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles PropertyActivate method call from ibus-daemon.
@@ -287,8 +283,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
engine_handler_->PropertyActivate(
property_name,
static_cast<ibus::IBusPropertyState>(property_state));
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles PropertyShow method call from ibus-daemon.
@@ -304,8 +299,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
return;
}
engine_handler_->PropertyShow(property_name);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles PropertyHide method call from ibus-daemon.
@@ -321,8 +315,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
return;
}
engine_handler_->PropertyHide(property_name);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles SetCapability method call from ibus-daemon.
@@ -339,8 +332,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
}
engine_handler_->SetCapability(
static_cast<IBusEngineHandlerInterface::IBusCapability>(capability));
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
void Reset(dbus::MethodCall* method_call,
@@ -348,8 +340,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
if (engine_handler_ == NULL)
return;
engine_handler_->Reset();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles ProcessKeyEvent method call from ibus-daemon.
@@ -380,19 +371,18 @@ class IBusEngineServiceImpl : public IBusEngineService {
keysym, keycode, state,
base::Bind(&IBusEngineServiceImpl::KeyEventDone,
weak_ptr_factory_.GetWeakPtr(),
- base::Unretained(
- dbus::Response::FromMethodCall(method_call)),
+ base::Passed(dbus::Response::FromMethodCall(method_call)),
response_sender));
}
- void KeyEventDone(dbus::Response* response,
+ void KeyEventDone(scoped_ptr<dbus::Response> response,
const dbus::ExportedObject::ResponseSender& response_sender,
bool consume) {
if (engine_handler_ == NULL)
return;
- dbus::MessageWriter writer(response);
+ dbus::MessageWriter writer(response.get());
writer.AppendBool(consume);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
}
// Handles CandidateClicked method call from ibus-daemon.
@@ -423,8 +413,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
index,
static_cast<ibus::IBusMouseButton>(button),
state);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles SetSurroundingText method call from ibus-daemon.
@@ -454,8 +443,7 @@ class IBusEngineServiceImpl : public IBusEngineService {
}
engine_handler_->SetSurroundingText(text, cursor_pos, anchor_pos);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Called when the method call is exported.
diff --git a/chromeos/dbus/ibus/ibus_engine_service_unittest.cc b/chromeos/dbus/ibus/ibus_engine_service_unittest.cc
index ae16d3c..2842401 100644
--- a/chromeos/dbus/ibus/ibus_engine_service_unittest.cc
+++ b/chromeos/dbus/ibus/ibus_engine_service_unittest.cc
@@ -56,7 +56,11 @@ class MockIBusEngineHandler : public IBusEngineHandlerInterface {
class MockResponseSender {
public:
- MOCK_METHOD1(Run, void(dbus::Response* reponse));
+ // GMock doesn't support mocking methods which take scoped_ptr<>.
+ MOCK_METHOD1(MockRun, void(dbus::Response* reponse));
+ void Run(scoped_ptr<dbus::Response> response) {
+ MockRun(response.get());
+ }
};
// Used for method call empty response evaluation.
@@ -67,7 +71,6 @@ class EmptyResponseExpectation {
// Evaluates the given |response| has no argument.
void Evaluate(dbus::Response* response) {
- scoped_ptr<dbus::Response> response_deleter(response);
EXPECT_EQ(serial_no_, response->GetReplySerial());
dbus::MessageReader reader(response);
EXPECT_FALSE(reader.HasMoreData());
@@ -89,7 +92,6 @@ class BoolResponseExpectation {
// Evaluates the given |response| has only one boolean and which is equals to
// |result_| which is given in ctor.
void Evaluate(dbus::Response* response) {
- scoped_ptr<dbus::Response> response_deleter(response);
EXPECT_EQ(serial_no_, response->GetReplySerial());
dbus::MessageReader reader(response);
bool result = false;
@@ -519,7 +521,7 @@ TEST_F(IBusEngineServiceTest, FocusInTest) {
EXPECT_CALL(*engine_handler_, FocusIn());
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -539,7 +541,7 @@ TEST_F(IBusEngineServiceTest, FocusInTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, FocusIn()).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kFocusInMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -552,7 +554,7 @@ TEST_F(IBusEngineServiceTest, FocusOutTest) {
EXPECT_CALL(*engine_handler_, FocusOut());
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -572,7 +574,7 @@ TEST_F(IBusEngineServiceTest, FocusOutTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, FocusOut()).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kFocusOutMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -585,7 +587,7 @@ TEST_F(IBusEngineServiceTest, EnableTest) {
EXPECT_CALL(*engine_handler_, Enable());
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -605,7 +607,7 @@ TEST_F(IBusEngineServiceTest, EnableTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, Enable()).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kEnableMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -618,7 +620,7 @@ TEST_F(IBusEngineServiceTest, DisableTest) {
EXPECT_CALL(*engine_handler_, Disable());
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -638,7 +640,7 @@ TEST_F(IBusEngineServiceTest, DisableTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, Disable()).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kDisableMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -655,7 +657,7 @@ TEST_F(IBusEngineServiceTest, PropertyActivateTest) {
kIBusPropertyState));
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -679,7 +681,7 @@ TEST_F(IBusEngineServiceTest, PropertyActivateTest) {
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, PropertyActivate(kPropertyName,
kIBusPropertyState)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kPropertyActivateMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -692,7 +694,7 @@ TEST_F(IBusEngineServiceTest, ResetTest) {
EXPECT_CALL(*engine_handler_, Reset());
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -712,7 +714,7 @@ TEST_F(IBusEngineServiceTest, ResetTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, Reset()).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kResetMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -726,7 +728,7 @@ TEST_F(IBusEngineServiceTest, PropertyShowTest) {
EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName));
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -748,7 +750,7 @@ TEST_F(IBusEngineServiceTest, PropertyShowTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, PropertyShow(kPropertyName)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kPropertyShowMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -762,7 +764,7 @@ TEST_F(IBusEngineServiceTest, PropertyHideTest) {
EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName));
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -784,7 +786,7 @@ TEST_F(IBusEngineServiceTest, PropertyHideTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, PropertyHide(kPropertyName)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kPropertyHideMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -799,7 +801,7 @@ TEST_F(IBusEngineServiceTest, SetCapabilityTest) {
EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability));
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -821,7 +823,7 @@ TEST_F(IBusEngineServiceTest, SetCapabilityTest) {
// Call exported function without engine.
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, SetCapability(kIBusCapability)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kSetCapabilityMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -842,7 +844,7 @@ TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) {
&ProcessKeyEventHandler::ProcessKeyEvent));
MockResponseSender response_sender;
BoolResponseExpectation response_expectation(kSerialNo, kResult);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&BoolResponseExpectation::Evaluate));
@@ -867,7 +869,7 @@ TEST_F(IBusEngineServiceTest, ProcessKeyEventTest) {
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_,
ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -888,7 +890,7 @@ TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) {
&DelayProcessKeyEventHandler::ProcessKeyEvent));
MockResponseSender response_sender;
BoolResponseExpectation response_expectation(kSerialNo, kResult);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&BoolResponseExpectation::Evaluate));
@@ -916,7 +918,7 @@ TEST_F(IBusEngineServiceTest, DelayProcessKeyEventTest) {
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_,
ProcessKeyEvent(kKeySym, kKeyCode, kState, _)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kProcessKeyEventMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -933,7 +935,7 @@ TEST_F(IBusEngineServiceTest, CandidateClickedTest) {
kState));
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -958,7 +960,7 @@ TEST_F(IBusEngineServiceTest, CandidateClickedTest) {
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, CandidateClicked(kIndex, kIBusMouseButton,
kState)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kCandidateClickedMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
@@ -975,7 +977,7 @@ TEST_F(IBusEngineServiceTest, SetSurroundingTextTest) {
kAnchorPos));
MockResponseSender response_sender;
EmptyResponseExpectation response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseExpectation::Evaluate));
@@ -1000,7 +1002,7 @@ TEST_F(IBusEngineServiceTest, SetSurroundingTextTest) {
service_->UnsetEngine();
EXPECT_CALL(*engine_handler_, SetSurroundingText(kText, kCursorPos,
kAnchorPos)).Times(0);
- EXPECT_CALL(response_sender, Run(_)).Times(0);
+ EXPECT_CALL(response_sender, MockRun(_)).Times(0);
method_callback_map_[ibus::engine::kSetSurroundingTextMethod].Run(
&method_call,
base::Bind(&MockResponseSender::Run,
diff --git a/chromeos/dbus/ibus/ibus_panel_service.cc b/chromeos/dbus/ibus/ibus_panel_service.cc
index 765318b..17457ba 100644
--- a/chromeos/dbus/ibus/ibus_panel_service.cc
+++ b/chromeos/dbus/ibus/ibus_panel_service.cc
@@ -211,8 +211,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
return;
}
candidate_window_handler_->UpdateLookupTable(table, visible);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles HideLookupTable method call from ibus-daemon.
@@ -222,8 +221,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
return;
candidate_window_handler_->HideLookupTable();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles UpdateAuxiliaryText method call from ibus-daemon.
@@ -247,8 +245,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
return;
}
candidate_window_handler_->UpdateAuxiliaryText(text, visible);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles HideAuxiliaryText method call from ibus-daemon.
@@ -258,8 +255,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
return;
candidate_window_handler_->HideAuxiliaryText();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles UpdatePreeditText method call from ibus-daemon.
@@ -288,8 +284,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
return;
}
candidate_window_handler_->UpdatePreeditText(text, cursor_pos, visible);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles HidePreeditText method call from ibus-daemon.
@@ -299,8 +294,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
return;
candidate_window_handler_->HidePreeditText();
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles RegisterProperties method call from ibus-daemon.
@@ -319,8 +313,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
}
property_handler_->RegisterProperties(properties);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Handles UpdateProperty method call from ibus-daemon.
@@ -338,8 +331,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
}
property_handler_->UpdateProperty(property);
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
void SetCursorLocation(const ibus::Rect& cursor_location,
@@ -356,8 +348,7 @@ class IBusPanelServiceImpl : public IBusPanelService {
if (!property_handler_)
return;
- dbus::Response* response = dbus::Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(dbus::Response::FromMethodCall(method_call));
}
// Called when the method call is exported.
diff --git a/chromeos/dbus/ibus/ibus_panel_service_unittest.cc b/chromeos/dbus/ibus/ibus_panel_service_unittest.cc
index a90a207..edb9d2c 100644
--- a/chromeos/dbus/ibus/ibus_panel_service_unittest.cc
+++ b/chromeos/dbus/ibus/ibus_panel_service_unittest.cc
@@ -63,7 +63,11 @@ class MockIBusPanelPropertyHandler : public IBusPanelPropertyHandlerInterface {
class MockResponseSender {
public:
- MOCK_METHOD1(Run, void(dbus::Response* reponse));
+ // GMock doesn't support mocking methods which take scoped_ptr<>.
+ MOCK_METHOD1(MockRun, void(dbus::Response* reponse));
+ void Run(scoped_ptr<dbus::Response> response) {
+ MockRun(response.get());
+ }
};
// This class is used to verify that a method call response is empty. This class
@@ -76,7 +80,6 @@ class EmptyResponseVerifier {
// Verifies the given |response| has no argument.
void Verify(dbus::Response* response) {
- scoped_ptr<dbus::Response> response_deleter(response);
EXPECT_EQ(expected_serial_number_, response->GetReplySerial());
dbus::MessageReader reader(response);
EXPECT_FALSE(reader.HasMoreData());
@@ -349,7 +352,7 @@ TEST_F(IBusPanelServiceTest, HideLookupTableTest) {
EXPECT_CALL(*candidate_window_handler_, HideLookupTable());
MockResponseSender response_sender;
EmptyResponseVerifier response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseVerifier::Verify));
@@ -373,7 +376,7 @@ TEST_F(IBusPanelServiceTest, HideAuxiliaryTextTest) {
EXPECT_CALL(*candidate_window_handler_, HideAuxiliaryText());
MockResponseSender response_sender;
EmptyResponseVerifier response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseVerifier::Verify));
@@ -397,7 +400,7 @@ TEST_F(IBusPanelServiceTest, HidePreeditTextTest) {
EXPECT_CALL(*candidate_window_handler_, HidePreeditText());
MockResponseSender response_sender;
EmptyResponseVerifier response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseVerifier::Verify));
@@ -430,7 +433,7 @@ TEST_F(IBusPanelServiceTest, UpdateLookupTableTest) {
&UpdateLookupTableVerifier::Verify));
MockResponseSender response_sender;
EmptyResponseVerifier response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseVerifier::Verify));
@@ -460,7 +463,7 @@ TEST_F(IBusPanelServiceTest, UpdateAuxiliaryTextTest) {
EXPECT_CALL(*candidate_window_handler_, UpdateAuxiliaryText(text, kVisible));
MockResponseSender response_sender;
EmptyResponseVerifier response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseVerifier::Verify));
@@ -492,7 +495,7 @@ TEST_F(IBusPanelServiceTest, UpdatePreeditTextTest) {
UpdatePreeditText(text, kCursorPos, kVisible));
MockResponseSender response_sender;
EmptyResponseVerifier response_expectation(kSerialNo);
- EXPECT_CALL(response_sender, Run(_))
+ EXPECT_CALL(response_sender, MockRun(_))
.WillOnce(Invoke(&response_expectation,
&EmptyResponseVerifier::Verify));
@@ -573,7 +576,7 @@ TEST_F(IBusPanelServiceTest, RegisterPropertiesTest) {
&PropertyListVerifier::Verify));
MockResponseSender response_sender;
- EXPECT_CALL(response_sender, Run(_));
+ EXPECT_CALL(response_sender, MockRun(_));
// Create method call;
dbus::MethodCall method_call(ibus::panel::kServiceInterface,
@@ -601,7 +604,7 @@ TEST_F(IBusPanelServiceTest, UpdatePropertyTest) {
.WillOnce(Invoke(&response_expectation, &PropertyVerifier::Verify));
MockResponseSender response_sender;
- EXPECT_CALL(response_sender, Run(_));
+ EXPECT_CALL(response_sender, MockRun(_));
// Create method call;
dbus::MethodCall method_call(ibus::panel::kServiceInterface,
diff --git a/chromeos/dbus/shill_client_unittest_base.cc b/chromeos/dbus/shill_client_unittest_base.cc
index 7488fa9..72906e5 100644
--- a/chromeos/dbus/shill_client_unittest_base.cc
+++ b/chromeos/dbus/shill_client_unittest_base.cc
@@ -115,7 +115,7 @@ void ShillClientUnittestBase::SetUp() {
// Set an expectation so mock_proxy's CallMethodAndBlock() will use
// OnCallMethodAndBlock() to return responses.
- EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _))
+ EXPECT_CALL(*mock_proxy_, MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(
this, &ShillClientUnittestBase::OnCallMethodAndBlock));
@@ -315,7 +315,7 @@ dbus::Response* ShillClientUnittestBase::OnCallMethodAndBlock(
dbus::MessageReader reader(method_call);
argument_checker_.Run(&reader);
return dbus::Response::FromRawMessage(
- dbus_message_copy(response_->raw_message()));
+ dbus_message_copy(response_->raw_message())).release();
}
} // namespace chromeos
diff --git a/content/browser/geolocation/wifi_data_provider_linux.cc b/content/browser/geolocation/wifi_data_provider_linux.cc
index 6e5d54e..fc4a30f 100644
--- a/content/browser/geolocation/wifi_data_provider_linux.cc
+++ b/content/browser/geolocation/wifi_data_provider_linux.cc
@@ -67,10 +67,11 @@ class NetworkManagerWlanApi : public WifiDataProviderCommon::WlanApiInterface {
WifiData::AccessPointDataSet* data);
// Internal method used by |GetAccessPointsForAdapter|, given a wifi access
- // point proxy retrieves the named property and returns it. Returns NULL if
- // the property could not be read.
- dbus::Response* GetAccessPointProperty(dbus::ObjectProxy* proxy,
- const std::string& property_name);
+ // point proxy retrieves the named property and returns it. Returns NULL in
+ // a scoped_ptr if the property could not be read.
+ scoped_ptr<dbus::Response> GetAccessPointProperty(
+ dbus::ObjectProxy* proxy,
+ const std::string& property_name);
scoped_refptr<dbus::Bus> system_bus_;
dbus::ObjectProxy* network_manager_proxy_;
@@ -324,20 +325,20 @@ bool NetworkManagerWlanApi::GetAccessPointsForAdapter(
return true;
}
-dbus::Response* NetworkManagerWlanApi::GetAccessPointProperty(
+scoped_ptr<dbus::Response> NetworkManagerWlanApi::GetAccessPointProperty(
dbus::ObjectProxy* access_point_proxy,
const std::string& property_name) {
dbus::MethodCall method_call(DBUS_INTERFACE_PROPERTIES, "Get");
dbus::MessageWriter builder(&method_call);
builder.AppendString("org.freedesktop.NetworkManager.AccessPoint");
builder.AppendString(property_name);
- dbus::Response* response = access_point_proxy->CallMethodAndBlock(
+ scoped_ptr<dbus::Response> response = access_point_proxy->CallMethodAndBlock(
&method_call,
dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
- if (!response) {
+ if (!response.get()) {
LOG(WARNING) << "Failed to get property for " << property_name;
}
- return response;
+ return response.Pass();
}
} // namespace
diff --git a/content/browser/geolocation/wifi_data_provider_linux_unittest.cc b/content/browser/geolocation/wifi_data_provider_linux_unittest.cc
index dfc072e..fadc97a 100644
--- a/content/browser/geolocation/wifi_data_provider_linux_unittest.cc
+++ b/content/browser/geolocation/wifi_data_provider_linux_unittest.cc
@@ -37,14 +37,14 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
"org.freedesktop.NetworkManager",
dbus::ObjectPath("/org/freedesktop/NetworkManager"));
// Set an expectation so mock_network_manager_proxy_'s
- // CallMethodAndBlock() will use CreateNetowrkManagerProxyResponse()
+ // CallMethodAndBlock() will use CreateNetworkManagerProxyResponse()
// to return responses.
EXPECT_CALL(*mock_network_manager_proxy_,
- CallMethodAndBlock(_, _))
+ MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(
this,
&GeolocationWifiDataProviderLinuxTest::
- CreateNetowrkManagerProxyResponse));
+ CreateNetworkManagerProxyResponse));
// Create a mock proxy that behaves as NetworkManager/Devices/0.
mock_device_proxy_ =
@@ -53,7 +53,7 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
"org.freedesktop.NetworkManager",
dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0"));
EXPECT_CALL(*mock_device_proxy_,
- CallMethodAndBlock(_, _))
+ MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(
this,
&GeolocationWifiDataProviderLinuxTest::CreateDeviceProxyResponse));
@@ -65,7 +65,7 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
"org.freedesktop.NetworkManager",
dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0"));
EXPECT_CALL(*mock_access_point_proxy_,
- CallMethodAndBlock(_, _))
+ MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(
this,
&GeolocationWifiDataProviderLinuxTest::
@@ -114,7 +114,7 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
private:
// Creates a response for |mock_network_manager_proxy_|.
- dbus::Response* CreateNetowrkManagerProxyResponse(
+ dbus::Response* CreateNetworkManagerProxyResponse(
dbus::MethodCall* method_call,
Unused) {
if (method_call->GetInterface() == "org.freedesktop.NetworkManager" &&
@@ -124,10 +124,10 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
object_paths.push_back(
dbus::ObjectPath("/org/freedesktop/NetworkManager/Devices/0"));
- dbus::Response* response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty();
+ dbus::MessageWriter writer(response.get());
writer.AppendArrayOfObjectPaths(object_paths);
- return response;
+ return response.release();
}
LOG(ERROR) << "Unexpected method call: " << method_call->ToString();
@@ -145,24 +145,24 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
if (reader.PopString(&interface_name) &&
reader.PopString(&property_name)) {
// The device type is asked. Respond that the device type is wifi.
- dbus::Response* response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty();
+ dbus::MessageWriter writer(response.get());
// This matches NM_DEVICE_TYPE_WIFI in wifi_data_provider_linux.cc.
const int kDeviceTypeWifi = 2;
writer.AppendVariantOfUint32(kDeviceTypeWifi);
- return response;
+ return response.release();
}
} else if (method_call->GetInterface() ==
"org.freedesktop.NetworkManager.Device.Wireless" &&
method_call->GetMember() == "GetAccessPoints") {
// The list of access points is asked. Return the object path.
- dbus::Response* response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty();
+ dbus::MessageWriter writer(response.get());
std::vector<dbus::ObjectPath> object_paths;
object_paths.push_back(
dbus::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/0"));
writer.AppendArrayOfObjectPaths(object_paths);
- return response;
+ return response.release();
}
LOG(ERROR) << "Unexpected method call: " << method_call->ToString();
@@ -181,12 +181,12 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
std::string property_name;
if (reader.PopString(&interface_name) &&
reader.PopString(&property_name)) {
- dbus::Response* response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty();
+ dbus::MessageWriter writer(response.get());
if (property_name == "Ssid") {
const uint8 kSsid[] = {0x74, 0x65, 0x73, 0x74}; // "test"
- dbus::MessageWriter variant_writer(response);
+ dbus::MessageWriter variant_writer(response.get());
writer.OpenVariant("ay", &variant_writer);
variant_writer.AppendArrayOfBytes(kSsid, arraysize(kSsid));
writer.CloseContainer(&variant_writer);
@@ -203,7 +203,7 @@ class GeolocationWifiDataProviderLinuxTest : public testing::Test {
const uint32 kFrequency = 2427;
writer.AppendVariantOfUint32(kFrequency);
}
- return response;
+ return response.release();
}
}
diff --git a/dbus/exported_object.cc b/dbus/exported_object.cc
index f9ddb62..b8cfbc5 100644
--- a/dbus/exported_object.cc
+++ b/dbus/exported_object.cc
@@ -218,16 +218,16 @@ DBusHandlerResult ExportedObject::HandleMessage(
base::Bind(&ExportedObject::RunMethod,
this,
iter->second,
- method_call.release(),
+ base::Passed(&method_call),
start_time));
} else {
// If the D-Bus thread is not used, just call the method directly.
- MethodCall* released_method_call = method_call.release();
- iter->second.Run(released_method_call,
+ MethodCall* method = method_call.get();
+ iter->second.Run(method,
base::Bind(&ExportedObject::SendResponse,
this,
start_time,
- released_method_call));
+ base::Passed(&method_call)));
}
// It's valid to say HANDLED here, and send a method response at a later
@@ -236,38 +236,37 @@ DBusHandlerResult ExportedObject::HandleMessage(
}
void ExportedObject::RunMethod(MethodCallCallback method_call_callback,
- MethodCall* method_call,
+ scoped_ptr<MethodCall> method_call,
base::TimeTicks start_time) {
bus_->AssertOnOriginThread();
- method_call_callback.Run(method_call,
+ MethodCall* method = method_call.get();
+ method_call_callback.Run(method,
base::Bind(&ExportedObject::SendResponse,
this,
start_time,
- method_call));
+ base::Passed(&method_call)));
}
void ExportedObject::SendResponse(base::TimeTicks start_time,
- MethodCall* method_call,
- Response* response) {
+ scoped_ptr<MethodCall> method_call,
+ scoped_ptr<Response> response) {
DCHECK(method_call);
if (bus_->HasDBusThread()) {
bus_->PostTaskToDBusThread(FROM_HERE,
base::Bind(&ExportedObject::OnMethodCompleted,
this,
- method_call,
- response,
+ base::Passed(&method_call),
+ base::Passed(&response),
start_time));
} else {
- OnMethodCompleted(method_call, response, start_time);
+ OnMethodCompleted(method_call.Pass(), response.Pass(), start_time);
}
}
-void ExportedObject::OnMethodCompleted(MethodCall* method_call,
- Response* response,
+void ExportedObject::OnMethodCompleted(scoped_ptr<MethodCall> method_call,
+ scoped_ptr<Response> response,
base::TimeTicks start_time) {
bus_->AssertOnDBusThread();
- scoped_ptr<MethodCall> method_call_deleter(method_call);
- scoped_ptr<Response> response_deleter(response);
// Record if the method call is successful, or not. 1 if successful.
UMA_HISTOGRAM_ENUMERATION("DBus.ExportedMethodHandleSuccess",
@@ -283,7 +282,7 @@ void ExportedObject::OnMethodCompleted(MethodCall* method_call,
// Something bad happened in the method call.
scoped_ptr<dbus::ErrorResponse> error_response(
ErrorResponse::FromMethodCall(
- method_call,
+ method_call.get(),
DBUS_ERROR_FAILED,
"error occurred in " + method_call->GetMember()));
bus_->Send(error_response->raw_message(), NULL);
diff --git a/dbus/exported_object.h b/dbus/exported_object.h
index 4e74ddb..89a4133 100644
--- a/dbus/exported_object.h
+++ b/dbus/exported_object.h
@@ -41,12 +41,7 @@ class CHROME_DBUS_EXPORT ExportedObject
// Called to send a response from an exported method. |response| is the
// response message. Callers should pass NULL in the event of an error that
// prevents the sending of a response.
- //
- // ResponseSender takes ownership of |response| hence client code should
- // not delete |response|.
- // TODO(satorux): Change this to take scoped_ptr<Response> to make
- // ownership clearer. crbug.com/163231
- typedef base::Callback<void (Response* response)> ResponseSender;
+ typedef base::Callback<void (scoped_ptr<Response> response)> ResponseSender;
// Called when an exported method is called. |method_call| is the request
// message. |sender| is the callback that's used to send a response.
@@ -134,20 +129,20 @@ class CHROME_DBUS_EXPORT ExportedObject
// Runs the method. Helper function for HandleMessage().
void RunMethod(MethodCallCallback method_call_callback,
- MethodCall* method_call,
+ scoped_ptr<MethodCall> method_call,
base::TimeTicks start_time);
// Callback invoked by service provider to send a response to a method call.
// Can be called immediately from a MethodCallCallback to implement a
// synchronous service or called later to implement an asynchronous service.
void SendResponse(base::TimeTicks start_time,
- MethodCall* method_call,
- Response* response);
+ scoped_ptr<MethodCall> method_call,
+ scoped_ptr<Response> response);
// Called on completion of the method run from SendResponse().
// Takes ownership of |method_call| and |response|.
- void OnMethodCompleted(MethodCall* method_call,
- Response* response,
+ void OnMethodCompleted(scoped_ptr<MethodCall> method_call,
+ scoped_ptr<Response> response,
base::TimeTicks start_time);
// Called when the object is unregistered.
diff --git a/dbus/message.cc b/dbus/message.cc
index afcd932..ce53a48 100644
--- a/dbus/message.cc
+++ b/dbus/message.cc
@@ -400,26 +400,27 @@ Signal* Signal::FromRawMessage(DBusMessage* raw_message) {
Response::Response() : Message() {
}
-Response* Response::FromRawMessage(DBusMessage* raw_message) {
+scoped_ptr<Response> Response::FromRawMessage(DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_RETURN,
dbus_message_get_type(raw_message));
- Response* response = new Response;
+ scoped_ptr<Response> response(new Response);
response->Init(raw_message);
- return response;
+ return response.Pass();
}
-Response* Response::FromMethodCall(MethodCall* method_call) {
- Response* response = new Response;
+scoped_ptr<Response> Response::FromMethodCall(MethodCall* method_call) {
+ scoped_ptr<Response> response(new Response);
response->Init(dbus_message_new_method_return(method_call->raw_message()));
- return response;
+ return response.Pass();
}
-Response* Response::CreateEmpty() {
- Response* response = new Response;
+scoped_ptr<Response> Response::CreateEmpty() {
+ scoped_ptr<Response> response(new Response);
response->Init(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN));
- return response;
+ return response.Pass();
}
+
//
// ErrorResponse implementation.
//
@@ -427,23 +428,24 @@ Response* Response::CreateEmpty() {
ErrorResponse::ErrorResponse() : Response() {
}
-ErrorResponse* ErrorResponse::FromRawMessage(DBusMessage* raw_message) {
+scoped_ptr<ErrorResponse> ErrorResponse::FromRawMessage(
+ DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_ERROR, dbus_message_get_type(raw_message));
- ErrorResponse* response = new ErrorResponse;
+ scoped_ptr<ErrorResponse> response(new ErrorResponse);
response->Init(raw_message);
- return response;
+ return response.Pass();
}
-ErrorResponse* ErrorResponse::FromMethodCall(
+scoped_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
MethodCall* method_call,
const std::string& error_name,
const std::string& error_message) {
- ErrorResponse* response = new ErrorResponse;
+ scoped_ptr<ErrorResponse> response(new ErrorResponse);
response->Init(dbus_message_new_error(method_call->raw_message(),
error_name.c_str(),
error_message.c_str()));
- return response;
+ return response.Pass();
}
//
diff --git a/dbus/message.h b/dbus/message.h
index 42d6860..54ca036 100644
--- a/dbus/message.h
+++ b/dbus/message.h
@@ -10,6 +10,7 @@
#include <dbus/dbus.h>
#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
#include "dbus/dbus_export.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
@@ -200,18 +201,17 @@ class CHROME_DBUS_EXPORT Signal : public Message {
class CHROME_DBUS_EXPORT Response : public Message {
public:
// Returns a newly created Response from the given raw message of the
- // type DBUS_MESSAGE_TYPE_METHOD_RETURN. The caller must delete the
- // returned object. Takes the ownership of |raw_message|.
- static Response* FromRawMessage(DBusMessage* raw_message);
+ // type DBUS_MESSAGE_TYPE_METHOD_RETURN. Takes the ownership of |raw_message|.
+ static scoped_ptr<Response> FromRawMessage(DBusMessage* raw_message);
- // Returns a newly created Response from the given method call. The
- // caller must delete the returned object. Used for implementing
- // exported methods.
- static Response* FromMethodCall(MethodCall* method_call);
+ // Returns a newly created Response from the given method call.
+ // Used for implementing exported methods. Does NOT take the ownership of
+ // |method_call|.
+ static scoped_ptr<Response> FromMethodCall(MethodCall* method_call);
- // Returns a newly created Response with an empty payload. The caller
- // must delete the returned object. Useful for testing.
- static Response* CreateEmpty();
+ // Returns a newly created Response with an empty payload.
+ // Useful for testing.
+ static scoped_ptr<Response> CreateEmpty();
protected:
// Creates a Response message. The internal raw message is NULL.
@@ -226,17 +226,17 @@ class CHROME_DBUS_EXPORT Response : public Message {
class CHROME_DBUS_EXPORT ErrorResponse: public Response {
public:
// Returns a newly created Response from the given raw message of the
- // type DBUS_MESSAGE_TYPE_METHOD_RETURN. The caller must delete the
- // returned object. Takes the ownership of |raw_message|.
- static ErrorResponse* FromRawMessage(DBusMessage* raw_message);
+ // type DBUS_MESSAGE_TYPE_METHOD_RETURN. Takes the ownership of |raw_message|.
+ static scoped_ptr<ErrorResponse> FromRawMessage(DBusMessage* raw_message);
// Returns a newly created ErrorResponse from the given method call, the
// error name, and the error message. The error name looks like
// "org.freedesktop.DBus.Error.Failed". Used for returning an error to a
- // failed method call.
- static ErrorResponse* FromMethodCall(MethodCall* method_call,
- const std::string& error_name,
- const std::string& error_message);
+ // failed method call. Does NOT take the ownership of |method_call|.
+ static scoped_ptr<ErrorResponse> FromMethodCall(
+ MethodCall* method_call,
+ const std::string& error_name,
+ const std::string& error_message);
private:
// Creates an ErrorResponse message. The internal raw message is NULL.
diff --git a/dbus/mock_object_proxy.h b/dbus/mock_object_proxy.h
index e820f45..fcad860 100644
--- a/dbus/mock_object_proxy.h
+++ b/dbus/mock_object_proxy.h
@@ -7,6 +7,7 @@
#include <string>
+#include "dbus/message.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -20,8 +21,17 @@ class MockObjectProxy : public ObjectProxy {
const std::string& service_name,
const ObjectPath& object_path);
- MOCK_METHOD2(CallMethodAndBlock, Response*(MethodCall* method_call,
- int timeout_ms));
+ // GMock doesn't support the return type of scoped_ptr<> because scoped_ptr is
+ // uncopyable. This is a workaround which defines |MockCallMethodAndBlock| as
+ // a mock method and makes |CallMethodAndBlock| call the mocked method.
+ // Use |MockCallMethodAndBlock| for setting/testing expectations.
+ MOCK_METHOD2(MockCallMethodAndBlock, Response*(MethodCall* method_call,
+ int timeout_ms));
+ virtual scoped_ptr<Response> CallMethodAndBlock(MethodCall* method_call,
+ int timeout_ms) OVERRIDE {
+ return scoped_ptr<Response>(MockCallMethodAndBlock(method_call,
+ timeout_ms));
+ }
MOCK_METHOD3(CallMethod, void(MethodCall* method_call,
int timeout_ms,
ResponseCallback callback));
diff --git a/dbus/mock_unittest.cc b/dbus/mock_unittest.cc
index cf644df..f860082 100644
--- a/dbus/mock_unittest.cc
+++ b/dbus/mock_unittest.cc
@@ -39,7 +39,7 @@ class MockTest : public testing::Test {
// Set an expectation so mock_proxy's CallMethodAndBlock() will use
// CreateMockProxyResponse() to return responses.
- EXPECT_CALL(*mock_proxy_, CallMethodAndBlock(_, _))
+ EXPECT_CALL(*mock_proxy_, MockCallMethodAndBlock(_, _))
.WillRepeatedly(Invoke(this, &MockTest::CreateMockProxyResponse));
// Set an expectation so mock_proxy's CallMethod() will use
@@ -91,10 +91,10 @@ class MockTest : public testing::Test {
dbus::MessageReader reader(method_call);
std::string text_message;
if (reader.PopString(&text_message)) {
- dbus::Response* response = dbus::Response::CreateEmpty();
- dbus::MessageWriter writer(response);
+ scoped_ptr<dbus::Response> response = dbus::Response::CreateEmpty();
+ dbus::MessageWriter writer(response.get());
writer.AppendString(text_message);
- return response;
+ return response.release();
}
}
diff --git a/dbus/object_proxy.cc b/dbus/object_proxy.cc
index b20f544..9a84f25 100644
--- a/dbus/object_proxy.cc
+++ b/dbus/object_proxy.cc
@@ -63,14 +63,14 @@ ObjectProxy::~ObjectProxy() {
// Originally we tried to make |method_call| a const reference, but we
// gave up as dbus_connection_send_with_reply_and_block() takes a
// non-const pointer of DBusMessage as the second parameter.
-Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call,
- int timeout_ms) {
+scoped_ptr<Response> ObjectProxy::CallMethodAndBlock(MethodCall* method_call,
+ int timeout_ms) {
bus_->AssertOnDBusThread();
if (!bus_->Connect() ||
!method_call->SetDestination(service_name_) ||
!method_call->SetPath(object_path_))
- return NULL;
+ return scoped_ptr<Response>();
DBusMessage* request_message = method_call->raw_message();
@@ -93,7 +93,7 @@ Response* ObjectProxy::CallMethodAndBlock(MethodCall* method_call,
method_call->GetMember(),
error.is_set() ? error.name() : "unknown error type",
error.is_set() ? error.message() : "");
- return NULL;
+ return scoped_ptr<Response>();
}
// Record time spent for the method call. Don't include failures.
UMA_HISTOGRAM_TIMES("DBus.SyncMethodCallTime",
diff --git a/dbus/object_proxy.h b/dbus/object_proxy.h
index 801c577..61576e6 100644
--- a/dbus/object_proxy.h
+++ b/dbus/object_proxy.h
@@ -81,11 +81,10 @@ class CHROME_DBUS_EXPORT ObjectProxy
// Calls the method of the remote object and blocks until the response
// is returned. Returns NULL on error.
- // The caller is responsible to delete the returned object.
//
// BLOCKING CALL.
- virtual Response* CallMethodAndBlock(MethodCall* method_call,
- int timeout_ms);
+ virtual scoped_ptr<Response> CallMethodAndBlock(MethodCall* method_call,
+ int timeout_ms);
// Requests to call the method of the remote object.
//
diff --git a/dbus/test_service.cc b/dbus/test_service.cc
index 0d99d57..d9dbf82 100644
--- a/dbus/test_service.cc
+++ b/dbus/test_service.cc
@@ -243,14 +243,14 @@ void TestService::Echo(MethodCall* method_call,
MessageReader reader(method_call);
std::string text_message;
if (!reader.PopString(&text_message)) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
- Response* response = Response::FromMethodCall(method_call);
- MessageWriter writer(response);
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response.get());
writer.AppendString(text_message);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
}
void TestService::SlowEcho(
@@ -275,7 +275,7 @@ void TestService::AsyncEcho(
void TestService::BrokenMethod(
MethodCall* method_call,
dbus::ExportedObject::ResponseSender response_sender) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
}
@@ -285,7 +285,7 @@ void TestService::GetAllProperties(
MessageReader reader(method_call);
std::string interface;
if (!reader.PopString(&interface)) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
@@ -300,8 +300,8 @@ void TestService::GetAllProperties(
// "Objects": Variant<[objectpath:"/TestObjectPath"]>
// ]
- Response* response = Response::FromMethodCall(method_call);
- MessageWriter writer(response);
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response.get());
MessageWriter array_writer(NULL);
MessageWriter dict_entry_writer(NULL);
@@ -343,7 +343,7 @@ void TestService::GetAllProperties(
writer.CloseContainer(&array_writer);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
}
void TestService::GetProperty(
@@ -352,39 +352,39 @@ void TestService::GetProperty(
MessageReader reader(method_call);
std::string interface;
if (!reader.PopString(&interface)) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
std::string name;
if (!reader.PopString(&name)) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
if (name == "Name") {
// Return the previous value for the "Name" property:
// Variant<"TestService">
- Response* response = Response::FromMethodCall(method_call);
- MessageWriter writer(response);
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response.get());
writer.AppendVariantOfString("TestService");
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
} else if (name == "Version") {
// Return a new value for the "Version" property:
// Variant<20>
- Response* response = Response::FromMethodCall(method_call);
- MessageWriter writer(response);
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response.get());
writer.AppendVariantOfInt16(20);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
} else if (name == "Methods") {
// Return the previous value for the "Methods" property:
// Variant<["Echo", "SlowEcho", "AsyncEcho", "BrokenMethod"]>
- Response* response = Response::FromMethodCall(method_call);
- MessageWriter writer(response);
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response.get());
MessageWriter variant_writer(NULL);
MessageWriter variant_array_writer(NULL);
@@ -397,12 +397,12 @@ void TestService::GetProperty(
variant_writer.CloseContainer(&variant_array_writer);
writer.CloseContainer(&variant_writer);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
} else if (name == "Objects") {
// Return the previous value for the "Objects" property:
// Variant<[objectpath:"/TestObjectPath"]>
- Response* response = Response::FromMethodCall(method_call);
- MessageWriter writer(response);
+ scoped_ptr<Response> response = Response::FromMethodCall(method_call);
+ MessageWriter writer(response.get());
MessageWriter variant_writer(NULL);
MessageWriter variant_array_writer(NULL);
@@ -412,10 +412,10 @@ void TestService::GetProperty(
variant_writer.CloseContainer(&variant_array_writer);
writer.CloseContainer(&variant_writer);
- response_sender.Run(response);
+ response_sender.Run(response.Pass());
} else {
// Return error.
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
}
@@ -426,31 +426,30 @@ void TestService::SetProperty(
MessageReader reader(method_call);
std::string interface;
if (!reader.PopString(&interface)) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
std::string name;
if (!reader.PopString(&name)) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
if (name != "Name") {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
std::string value;
if (!reader.PopVariantOfString(&value)) {
- response_sender.Run(NULL);
+ response_sender.Run(scoped_ptr<dbus::Response>());
return;
}
SendPropertyChangedSignal(value);
- Response* response = Response::FromMethodCall(method_call);
- response_sender.Run(response);
+ response_sender.Run(Response::FromMethodCall(method_call));
}
void TestService::SendPropertyChangedSignal(const std::string& name) {