Skip to content

Commit

Permalink
Convert //dbus from scoped_ptr to std::unique_ptr
Browse files Browse the repository at this point in the history
BUG=554298
R=hashimoto@chromium.org
TBR=scheib@chromium.org

Review URL: https://codereview.chromium.org/1867253002

Cr-Commit-Position: refs/heads/master@{#386236}
  • Loading branch information
zetafunction authored and Commit bot committed Apr 8, 2016
1 parent 52b9bc1 commit 2a19328
Show file tree
Hide file tree
Showing 29 changed files with 218 additions and 208 deletions.
5 changes: 3 additions & 2 deletions dbus/bus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,8 @@ std::string Bus::GetServiceOwnerAndBlock(const std::string& service_name,
return "";
}

scoped_ptr<Response> response(Response::FromRawMessage(response_message));
std::unique_ptr<Response> response(
Response::FromRawMessage(response_message));
MessageReader reader(response.get());

std::string service_owner;
Expand Down Expand Up @@ -1114,7 +1115,7 @@ void Bus::OnServiceOwnerChanged(DBusMessage* message) {
// |message| will be unrefed on exit of the function. Increment the
// reference so we can use it in Signal::FromRawMessage() below.
dbus_message_ref(message);
scoped_ptr<Signal> signal(Signal::FromRawMessage(message));
std::unique_ptr<Signal> signal(Signal::FromRawMessage(message));

// Confirm the validity of the NameOwnerChanged signal.
if (signal->GetMember() != kNameOwnerChangedSignal ||
Expand Down
2 changes: 1 addition & 1 deletion dbus/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ObjectProxy;
// bus.GetObjectProxy(service_name, object_path);
//
// dbus::MethodCall method_call(interface_name, method_name);
// scoped_ptr<dbus::Response> response(
// std::unique_ptr<dbus::Response> response(
// object_proxy.CallMethodAndBlock(&method_call, timeout_ms));
// if (response.get() != NULL) { // Success.
// ...
Expand Down
2 changes: 1 addition & 1 deletion dbus/bus_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class RunLoopWithExpectedCount {
}

private:
scoped_ptr<base::RunLoop> run_loop_;
std::unique_ptr<base::RunLoop> run_loop_;
int expected_quit_calls_;
int actual_quit_calls_;

Expand Down
4 changes: 2 additions & 2 deletions dbus/dbus_statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#include "dbus/dbus_statistics.h"

#include <memory>
#include <set>

#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/platform_thread.h"
Expand Down Expand Up @@ -108,7 +108,7 @@ class DBusStatistics {
const std::string& method,
bool add_stat) {
DCHECK_EQ(origin_thread_id_, base::PlatformThread::CurrentId());
scoped_ptr<Stat> stat(new Stat(service, interface, method));
std::unique_ptr<Stat> stat(new Stat(service, interface, method));
StatSet::iterator found = stats_.find(stat.get());
if (found != stats_.end())
return *found;
Expand Down
8 changes: 4 additions & 4 deletions dbus/end_to_end_async_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <stddef.h>

#include <algorithm>
#include <memory>
#include <string>
#include <vector>

#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
Expand Down Expand Up @@ -255,14 +255,14 @@ class EndToEndAsyncTest : public testing::Test {
}

base::MessageLoop message_loop_;
scoped_ptr<base::RunLoop> run_loop_;
std::unique_ptr<base::RunLoop> run_loop_;
std::vector<std::string> response_strings_;
std::vector<std::string> error_names_;
scoped_ptr<base::Thread> dbus_thread_;
std::unique_ptr<base::Thread> dbus_thread_;
scoped_refptr<Bus> bus_;
ObjectProxy* object_proxy_;
ObjectProxy* root_object_proxy_;
scoped_ptr<TestService> test_service_;
std::unique_ptr<TestService> test_service_;
// Text message from "Test" signal.
std::string test_signal_string_;
// Text message from "Test" signal delivered to root.
Expand Down
17 changes: 9 additions & 8 deletions dbus/end_to_end_sync_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <memory>

#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
Expand Down Expand Up @@ -47,7 +48,7 @@ class EndToEndSyncTest : public testing::Test {
}

protected:
scoped_ptr<TestService> test_service_;
std::unique_ptr<TestService> test_service_;
scoped_refptr<Bus> client_bus_;
ObjectProxy* object_proxy_;
};
Expand All @@ -62,7 +63,7 @@ TEST_F(EndToEndSyncTest, Echo) {

// Call the method.
const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
scoped_ptr<Response> response(
std::unique_ptr<Response> response(
object_proxy_->CallMethodAndBlock(&method_call, timeout_ms));
ASSERT_TRUE(response.get());

Expand All @@ -83,7 +84,7 @@ TEST_F(EndToEndSyncTest, Timeout) {

// Call the method with timeout of 0ms.
const int timeout_ms = 0;
scoped_ptr<Response> response(
std::unique_ptr<Response> response(
object_proxy_->CallMethodAndBlock(&method_call, timeout_ms));
// Should fail because of timeout.
ASSERT_FALSE(response.get());
Expand All @@ -93,7 +94,7 @@ TEST_F(EndToEndSyncTest, NonexistentMethod) {
MethodCall method_call("org.chromium.TestInterface", "Nonexistent");

const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
scoped_ptr<Response> response(
std::unique_ptr<Response> response(
object_proxy_->CallMethodAndBlock(&method_call, timeout_ms));
ASSERT_FALSE(response.get());
}
Expand All @@ -102,7 +103,7 @@ TEST_F(EndToEndSyncTest, BrokenMethod) {
MethodCall method_call("org.chromium.TestInterface", "BrokenMethod");

const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
scoped_ptr<Response> response(
std::unique_ptr<Response> response(
object_proxy_->CallMethodAndBlock(&method_call, timeout_ms));
ASSERT_FALSE(response.get());
}
Expand All @@ -118,7 +119,7 @@ TEST_F(EndToEndSyncTest, InvalidObjectPath) {
MethodCall method_call("org.chromium.TestInterface", "Echo");

const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
scoped_ptr<Response> response(
std::unique_ptr<Response> response(
object_proxy_->CallMethodAndBlock(&method_call, timeout_ms));
ASSERT_FALSE(response.get());
}
Expand All @@ -134,7 +135,7 @@ TEST_F(EndToEndSyncTest, InvalidServiceName) {
MethodCall method_call("org.chromium.TestInterface", "Echo");

const int timeout_ms = ObjectProxy::TIMEOUT_USE_DEFAULT;
scoped_ptr<Response> response(
std::unique_ptr<Response> response(
object_proxy_->CallMethodAndBlock(&method_call, timeout_ms));
ASSERT_FALSE(response.get());
}
Expand Down
20 changes: 9 additions & 11 deletions dbus/exported_object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ DBusHandlerResult ExportedObject::HandleMessage(
// raw_message will be unrefed on exit of the function. Increment the
// reference so we can use it in MethodCall.
dbus_message_ref(raw_message);
scoped_ptr<MethodCall> method_call(
std::unique_ptr<MethodCall> method_call(
MethodCall::FromRawMessage(raw_message));
const std::string interface = method_call->GetInterface();
const std::string member = method_call->GetMember();
Expand Down Expand Up @@ -241,7 +241,7 @@ DBusHandlerResult ExportedObject::HandleMessage(
}

void ExportedObject::RunMethod(MethodCallCallback method_call_callback,
scoped_ptr<MethodCall> method_call,
std::unique_ptr<MethodCall> method_call,
base::TimeTicks start_time) {
bus_->AssertOnOriginThread();
MethodCall* method = method_call.get();
Expand All @@ -253,8 +253,8 @@ void ExportedObject::RunMethod(MethodCallCallback method_call_callback,
}

void ExportedObject::SendResponse(base::TimeTicks start_time,
scoped_ptr<MethodCall> method_call,
scoped_ptr<Response> response) {
std::unique_ptr<MethodCall> method_call,
std::unique_ptr<Response> response) {
DCHECK(method_call);
if (bus_->HasDBusThread()) {
bus_->GetDBusTaskRunner()->PostTask(
Expand All @@ -269,8 +269,8 @@ void ExportedObject::SendResponse(base::TimeTicks start_time,
}
}

void ExportedObject::OnMethodCompleted(scoped_ptr<MethodCall> method_call,
scoped_ptr<Response> response,
void ExportedObject::OnMethodCompleted(std::unique_ptr<MethodCall> method_call,
std::unique_ptr<Response> response,
base::TimeTicks start_time) {
bus_->AssertOnDBusThread();

Expand All @@ -286,11 +286,9 @@ void ExportedObject::OnMethodCompleted(scoped_ptr<MethodCall> method_call,

if (!response) {
// Something bad happened in the method call.
scoped_ptr<ErrorResponse> error_response(
ErrorResponse::FromMethodCall(
method_call.get(),
DBUS_ERROR_FAILED,
"error occurred in " + method_call->GetMember()));
std::unique_ptr<ErrorResponse> error_response(ErrorResponse::FromMethodCall(
method_call.get(), DBUS_ERROR_FAILED,
"error occurred in " + method_call->GetMember()));
bus_->Send(error_response->raw_message(), NULL);
return;
}
Expand Down
15 changes: 8 additions & 7 deletions dbus/exported_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#include <dbus/dbus.h>

#include <map>
#include <memory>
#include <string>
#include <utility>

#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
Expand Down Expand Up @@ -42,7 +42,8 @@ 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.
typedef base::Callback<void (scoped_ptr<Response> response)> ResponseSender;
typedef base::Callback<void(std::unique_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.
Expand Down Expand Up @@ -139,20 +140,20 @@ class CHROME_DBUS_EXPORT ExportedObject

// Runs the method. Helper function for HandleMessage().
void RunMethod(MethodCallCallback method_call_callback,
scoped_ptr<MethodCall> method_call,
std::unique_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,
scoped_ptr<MethodCall> method_call,
scoped_ptr<Response> response);
std::unique_ptr<MethodCall> method_call,
std::unique_ptr<Response> response);

// Called on completion of the method run from SendResponse().
// Takes ownership of |method_call| and |response|.
void OnMethodCompleted(scoped_ptr<MethodCall> method_call,
scoped_ptr<Response> response,
void OnMethodCompleted(std::unique_ptr<MethodCall> method_call,
std::unique_ptr<Response> response,
base::TimeTicks start_time);

// Called when the object is unregistered.
Expand Down
5 changes: 3 additions & 2 deletions dbus/file_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef DBUS_FILE_DESCRIPTOR_H_
#define DBUS_FILE_DESCRIPTOR_H_

#include "base/memory/scoped_ptr.h"
#include <memory>

#include "base/move.h"
#include "dbus/dbus_export.h"

Expand Down Expand Up @@ -84,7 +85,7 @@ class CHROME_DBUS_EXPORT FileDescriptor {
};

using ScopedFileDescriptor =
scoped_ptr<FileDescriptor, FileDescriptor::Deleter>;
std::unique_ptr<FileDescriptor, FileDescriptor::Deleter>;

} // namespace dbus

Expand Down
20 changes: 10 additions & 10 deletions dbus/message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,23 +398,23 @@ Signal* Signal::FromRawMessage(DBusMessage* raw_message) {
Response::Response() : Message() {
}

scoped_ptr<Response> Response::FromRawMessage(DBusMessage* raw_message) {
std::unique_ptr<Response> Response::FromRawMessage(DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_METHOD_RETURN,
dbus_message_get_type(raw_message));

scoped_ptr<Response> response(new Response);
std::unique_ptr<Response> response(new Response);
response->Init(raw_message);
return response;
}

scoped_ptr<Response> Response::FromMethodCall(MethodCall* method_call) {
scoped_ptr<Response> response(new Response);
std::unique_ptr<Response> Response::FromMethodCall(MethodCall* method_call) {
std::unique_ptr<Response> response(new Response);
response->Init(dbus_message_new_method_return(method_call->raw_message()));
return response;
}

scoped_ptr<Response> Response::CreateEmpty() {
scoped_ptr<Response> response(new Response);
std::unique_ptr<Response> Response::CreateEmpty() {
std::unique_ptr<Response> response(new Response);
response->Init(dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN));
return response;
}
Expand All @@ -426,20 +426,20 @@ scoped_ptr<Response> Response::CreateEmpty() {
ErrorResponse::ErrorResponse() : Response() {
}

scoped_ptr<ErrorResponse> ErrorResponse::FromRawMessage(
std::unique_ptr<ErrorResponse> ErrorResponse::FromRawMessage(
DBusMessage* raw_message) {
DCHECK_EQ(DBUS_MESSAGE_TYPE_ERROR, dbus_message_get_type(raw_message));

scoped_ptr<ErrorResponse> response(new ErrorResponse);
std::unique_ptr<ErrorResponse> response(new ErrorResponse);
response->Init(raw_message);
return response;
}

scoped_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
std::unique_ptr<ErrorResponse> ErrorResponse::FromMethodCall(
MethodCall* method_call,
const std::string& error_name,
const std::string& error_message) {
scoped_ptr<ErrorResponse> response(new ErrorResponse);
std::unique_ptr<ErrorResponse> response(new ErrorResponse);
response->Init(dbus_message_new_error(method_call->raw_message(),
error_name.c_str(),
error_message.c_str()));
Expand Down
14 changes: 8 additions & 6 deletions dbus/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
#include <dbus/dbus.h>
#include <stddef.h>
#include <stdint.h>

#include <memory>
#include <string>
#include <vector>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "dbus/dbus_export.h"
#include "dbus/file_descriptor.h"
#include "dbus/object_path.h"
Expand Down Expand Up @@ -204,16 +205,16 @@ 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. Takes the ownership of |raw_message|.
static scoped_ptr<Response> FromRawMessage(DBusMessage* raw_message);
static std::unique_ptr<Response> FromRawMessage(DBusMessage* raw_message);

// 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);
static std::unique_ptr<Response> FromMethodCall(MethodCall* method_call);

// Returns a newly created Response with an empty payload.
// Useful for testing.
static scoped_ptr<Response> CreateEmpty();
static std::unique_ptr<Response> CreateEmpty();

protected:
// Creates a Response message. The internal raw message is NULL.
Expand All @@ -229,13 +230,14 @@ 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. Takes the ownership of |raw_message|.
static scoped_ptr<ErrorResponse> FromRawMessage(DBusMessage* raw_message);
static std::unique_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. Does NOT take the ownership of |method_call|.
static scoped_ptr<ErrorResponse> FromMethodCall(
static std::unique_ptr<ErrorResponse> FromMethodCall(
MethodCall* method_call,
const std::string& error_name,
const std::string& error_message);
Expand Down
Loading

0 comments on commit 2a19328

Please sign in to comment.