Skip to content

Commit

Permalink
Convert //tools to use std::unique_ptr
Browse files Browse the repository at this point in the history
BUG=554298

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

Cr-Commit-Position: refs/heads/master@{#386168}
  • Loading branch information
zetafunction authored and Commit bot committed Apr 8, 2016
1 parent 5c4aada commit a500b69
Show file tree
Hide file tree
Showing 111 changed files with 972 additions and 867 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

#include <stddef.h>

#include <memory>

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/common/extensions/api/developer_private.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_EXPERIENCE_SAMPLING_PRIVATE_EXPERIENCE_SAMPLING_H_
#define CHROME_BROWSER_EXTENSIONS_API_EXPERIENCE_SAMPLING_PRIVATE_EXPERIENCE_SAMPLING_H_

#include <memory>

#include "base/macros.h"
#include "chrome/common/extensions/api/experience_sampling_private.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <stdint.h>

#include <memory>

#include "base/callback.h"
#include "base/files/file.h"
#include "base/files/scoped_temp_dir.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
// found in the LICENSE file.

// devguid requires Windows.h be imported first.
#include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"

#include <windows.h>
#include <setupapi.h>
#include <winioctl.h>

#include <memory>

#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_handle.h"
#include "chrome/browser/extensions/api/image_writer_private/removable_storage_provider.h"

namespace extensions {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/extensions/api/log_private/filter_handler.h"

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

Expand Down
1 change: 1 addition & 0 deletions chrome/browser/extensions/extension_tab_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H_
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_TAB_UTIL_H_

#include <memory>
#include <string>

#include "base/callback.h"
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/extensions/window_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stdint.h>

#include <memory>
#include <string>

#include "base/compiler_specific.h"
Expand Down
1 change: 1 addition & 0 deletions extensions/browser/api/system_cpu/cpu_info_provider_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <windows.h>
#include <winternl.h>

#include "base/memory/scoped_ptr.h"
#include "base/sys_info.h"

namespace extensions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "extensions/common/api/display_source.h"
#include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h"

Expand Down
1 change: 1 addition & 0 deletions extensions/renderer/display_source_custom_bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define EXTENSIONS_RENDERER_DISPLAY_SOURCE_CUSTOM_BINDINGS_H_

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "extensions/common/api/display_source.h"
#include "extensions/renderer/api/display_source/display_source_session.h"
#include "extensions/renderer/object_backed_native_handler.h"
Expand Down
15 changes: 8 additions & 7 deletions tools/android/forwarder2/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include <cstdlib>
#include <cstring>
#include <memory>
#include <string>
#include <utility>

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -53,7 +54,7 @@ bool RunServerAcceptLoop(const std::string& welcome_message,
Daemon::ServerDelegate* server_delegate) {
bool failed = false;
for (;;) {
scoped_ptr<Socket> client_socket(new Socket());
std::unique_ptr<Socket> client_socket(new Socket());
if (!server_socket->Accept(client_socket.get())) {
if (server_socket->DidReceiveEvent())
break;
Expand Down Expand Up @@ -97,13 +98,13 @@ void SigChildHandler(int signal_number) {
SIGNAL_SAFE_LOG(ERROR, string_builder.buffer());
}

scoped_ptr<Socket> ConnectToUnixDomainSocket(
std::unique_ptr<Socket> ConnectToUnixDomainSocket(
const std::string& socket_name,
int tries_count,
int idle_time_msec,
const std::string& expected_welcome_message) {
for (int i = 0; i < tries_count; ++i) {
scoped_ptr<Socket> socket(new Socket());
std::unique_ptr<Socket> socket(new Socket());
if (!socket->ConnectUnix(socket_name)) {
if (idle_time_msec)
usleep(idle_time_msec * 1000);
Expand All @@ -122,7 +123,7 @@ scoped_ptr<Socket> ConnectToUnixDomainSocket(
}
return socket;
}
return scoped_ptr<Socket>();
return nullptr;
}

} // namespace
Expand All @@ -147,7 +148,7 @@ Daemon::~Daemon() {}
bool Daemon::SpawnIfNeeded() {
const int kSingleTry = 1;
const int kNoIdleTime = 0;
scoped_ptr<Socket> client_socket = ConnectToUnixDomainSocket(
std::unique_ptr<Socket> client_socket = ConnectToUnixDomainSocket(
identifier_, kSingleTry, kNoIdleTime, identifier_);
if (!client_socket) {
switch (fork()) {
Expand All @@ -170,7 +171,7 @@ bool Daemon::SpawnIfNeeded() {
CHECK_EQ(dup(null_fd), STDERR_FILENO);
Socket command_socket;
if (!command_socket.BindUnix(identifier_)) {
scoped_ptr<Socket> client_socket = ConnectToUnixDomainSocket(
std::unique_ptr<Socket> client_socket = ConnectToUnixDomainSocket(
identifier_, kSingleTry, kNoIdleTime, identifier_);
if (client_socket.get()) {
// The daemon was spawned by a concurrent process.
Expand Down
4 changes: 2 additions & 2 deletions tools/android/forwarder2/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#ifndef TOOLS_ANDROID_FORWARDER2_DAEMON_H_
#define TOOLS_ANDROID_FORWARDER2_DAEMON_H_

#include <memory>
#include <string>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"

namespace forwarder2 {

Expand Down Expand Up @@ -37,7 +37,7 @@ class Daemon {
// setup signal handlers or perform global initialization.
virtual void Init() = 0;

virtual void OnClientConnected(scoped_ptr<Socket> client_socket) = 0;
virtual void OnClientConnected(std::unique_ptr<Socket> client_socket) = 0;
};

// |identifier| should be a unique string identifier. It is used to
Expand Down
18 changes: 9 additions & 9 deletions tools/android/forwarder2/device_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include "tools/android/forwarder2/device_controller.h"

#include <memory>
#include <utility>

#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "tools/android/forwarder2/command.h"
Expand All @@ -20,11 +20,11 @@
namespace forwarder2 {

// static
scoped_ptr<DeviceController> DeviceController::Create(
std::unique_ptr<DeviceController> DeviceController::Create(
const std::string& adb_unix_socket,
int exit_notifier_fd) {
scoped_ptr<DeviceController> device_controller;
scoped_ptr<Socket> host_socket(new Socket());
std::unique_ptr<DeviceController> device_controller;
std::unique_ptr<Socket> host_socket(new Socket());
if (!host_socket->BindUnix(adb_unix_socket)) {
PLOG(ERROR) << "Could not BindAndListen DeviceController socket on port "
<< adb_unix_socket << ": ";
Expand All @@ -44,7 +44,7 @@ void DeviceController::Start() {
AcceptHostCommandSoon();
}

DeviceController::DeviceController(scoped_ptr<Socket> host_socket,
DeviceController::DeviceController(std::unique_ptr<Socket> host_socket,
int exit_notifier_fd)
: host_socket_(std::move(host_socket)),
exit_notifier_fd_(exit_notifier_fd),
Expand All @@ -60,7 +60,7 @@ void DeviceController::AcceptHostCommandSoon() {
}

void DeviceController::AcceptHostCommandInternal() {
scoped_ptr<Socket> socket(new Socket);
std::unique_ptr<Socket> socket(new Socket);
if (!host_socket_->Accept(socket.get())) {
if (!host_socket_->DidReceiveEvent())
PLOG(ERROR) << "Could not Accept DeviceController socket";
Expand Down Expand Up @@ -89,7 +89,7 @@ void DeviceController::AcceptHostCommandInternal() {
<< ". Attempting to restart the listener.\n";
DeleteRefCountedValueInMapFromIterator(listener_it, &listeners_);
}
scoped_ptr<DeviceListener> new_listener(DeviceListener::Create(
std::unique_ptr<DeviceListener> new_listener(DeviceListener::Create(
std::move(socket), port,
base::Bind(&DeviceController::DeleteListenerOnError,
weak_ptr_factory_.GetWeakPtr())));
Expand Down Expand Up @@ -136,8 +136,8 @@ void DeviceController::AcceptHostCommandInternal() {

// static
void DeviceController::DeleteListenerOnError(
const base::WeakPtr<DeviceController>& device_controller_ptr,
scoped_ptr<DeviceListener> device_listener) {
const base::WeakPtr<DeviceController>& device_controller_ptr,
std::unique_ptr<DeviceListener> device_listener) {
DeviceListener* const listener = device_listener.release();
DeviceController* const controller = device_controller_ptr.get();
if (!controller) {
Expand Down
13 changes: 7 additions & 6 deletions tools/android/forwarder2/device_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#ifndef TOOLS_ANDROID_FORWARDER2_DEVICE_CONTROLLER_H_
#define TOOLS_ANDROID_FORWARDER2_DEVICE_CONTROLLER_H_

#include <memory>
#include <string>

#include "base/containers/hash_tables.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "tools/android/forwarder2/socket.h"

Expand All @@ -28,8 +28,9 @@ class DeviceListener;
// DeviceListener each).
class DeviceController {
public:
static scoped_ptr<DeviceController> Create(const std::string& adb_unix_socket,
int exit_notifier_fd);
static std::unique_ptr<DeviceController> Create(
const std::string& adb_unix_socket,
int exit_notifier_fd);
~DeviceController();

void Start();
Expand All @@ -38,7 +39,7 @@ class DeviceController {
typedef base::hash_map<
int /* port */, linked_ptr<DeviceListener> > ListenersMap;

DeviceController(scoped_ptr<Socket> host_socket, int exit_notifier_fd);
DeviceController(std::unique_ptr<Socket> host_socket, int exit_notifier_fd);

void AcceptHostCommandSoon();
void AcceptHostCommandInternal();
Expand All @@ -47,9 +48,9 @@ class DeviceController {
// destroyed which is why a weak pointer is used.
static void DeleteListenerOnError(
const base::WeakPtr<DeviceController>& device_controller_ptr,
scoped_ptr<DeviceListener> device_listener);
std::unique_ptr<DeviceListener> device_listener);

const scoped_ptr<Socket> host_socket_;
const std::unique_ptr<Socket> host_socket_;
// Used to notify the controller to exit.
const int exit_notifier_fd_;
// Lets ensure DeviceListener instances are deleted on the thread they were
Expand Down
11 changes: 6 additions & 5 deletions tools/android/forwarder2/device_forwarder_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ServerDelegate : public Daemon::ServerDelegate {
controller_thread_->Start();
}

void OnClientConnected(scoped_ptr<Socket> client_socket) override {
void OnClientConnected(std::unique_ptr<Socket> client_socket) override {
if (initialized_) {
client_socket->WriteString("OK");
return;
Expand All @@ -80,9 +80,10 @@ class ServerDelegate : public Daemon::ServerDelegate {
}

private:
void StartController(int exit_notifier_fd, scoped_ptr<Socket> client_socket) {
void StartController(int exit_notifier_fd,
std::unique_ptr<Socket> client_socket) {
DCHECK(!controller_.get());
scoped_ptr<DeviceController> controller(
std::unique_ptr<DeviceController> controller(
DeviceController::Create(kUnixDomainSocketPath, exit_notifier_fd));
if (!controller.get()) {
client_socket->WriteString(
Expand All @@ -97,8 +98,8 @@ class ServerDelegate : public Daemon::ServerDelegate {
client_socket->Close();
}

scoped_ptr<DeviceController> controller_;
scoped_ptr<base::Thread> controller_thread_;
std::unique_ptr<DeviceController> controller_;
std::unique_ptr<base::Thread> controller_thread_;
bool initialized_;
};

Expand Down
18 changes: 9 additions & 9 deletions tools/android/forwarder2/device_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

#include "tools/android/forwarder2/device_listener.h"

#include <memory>
#include <utility>

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "tools/android/forwarder2/command.h"
Expand All @@ -20,12 +20,12 @@
namespace forwarder2 {

// static
scoped_ptr<DeviceListener> DeviceListener::Create(
scoped_ptr<Socket> host_socket,
std::unique_ptr<DeviceListener> DeviceListener::Create(
std::unique_ptr<Socket> host_socket,
int listener_port,
const ErrorCallback& error_callback) {
scoped_ptr<Socket> listener_socket(new Socket());
scoped_ptr<DeviceListener> device_listener;
std::unique_ptr<Socket> listener_socket(new Socket());
std::unique_ptr<DeviceListener> device_listener;
if (!listener_socket->BindTcp("", listener_port)) {
LOG(ERROR) << "Device could not bind and listen to local port "
<< listener_port;
Expand All @@ -52,15 +52,15 @@ void DeviceListener::Start() {
AcceptNextClientSoon();
}

void DeviceListener::SetAdbDataSocket(scoped_ptr<Socket> adb_data_socket) {
void DeviceListener::SetAdbDataSocket(std::unique_ptr<Socket> adb_data_socket) {
thread_.task_runner()->PostTask(
FROM_HERE,
base::Bind(&DeviceListener::OnAdbDataSocketReceivedOnInternalThread,
base::Unretained(this), base::Passed(&adb_data_socket)));
}

DeviceListener::DeviceListener(scoped_ptr<Socket> listener_socket,
scoped_ptr<Socket> host_socket,
DeviceListener::DeviceListener(std::unique_ptr<Socket> listener_socket,
std::unique_ptr<Socket> host_socket,
int port,
const ErrorCallback& error_callback)
: self_deleter_helper_(this, error_callback),
Expand Down Expand Up @@ -116,7 +116,7 @@ void DeviceListener::AcceptClientOnInternalThread() {
}

void DeviceListener::OnAdbDataSocketReceivedOnInternalThread(
scoped_ptr<Socket> adb_data_socket) {
std::unique_ptr<Socket> adb_data_socket) {
DCHECK(adb_data_socket);
SendCommand(command::ADB_DATA_SOCKET_SUCCESS, listener_port_,
host_socket_.get());
Expand Down
Loading

0 comments on commit a500b69

Please sign in to comment.