Skip to content

Commit

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

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

Cr-Commit-Position: refs/heads/master@{#386333}
  • Loading branch information
nico authored and Commit bot committed Apr 11, 2016
1 parent 2a589d1 commit 08c9d69
Show file tree
Hide file tree
Showing 113 changed files with 761 additions and 588 deletions.
15 changes: 8 additions & 7 deletions device/bluetooth/bluetooth_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "device/bluetooth/bluetooth_adapter.h"

#include <memory>
#include <utility>

#include "base/bind.h"
Expand Down Expand Up @@ -60,7 +61,7 @@ void BluetoothAdapter::StartDiscoverySession(
}

void BluetoothAdapter::StartDiscoverySessionWithFilter(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const DiscoverySessionCallback& callback,
const ErrorCallback& error_callback) {
BluetoothDiscoveryFilter* ptr = discovery_filter.get();
Expand All @@ -72,12 +73,12 @@ void BluetoothAdapter::StartDiscoverySessionWithFilter(
weak_ptr_factory_.GetWeakPtr(), error_callback));
}

scoped_ptr<BluetoothDiscoveryFilter>
std::unique_ptr<BluetoothDiscoveryFilter>
BluetoothAdapter::GetMergedDiscoveryFilter() const {
return GetMergedDiscoveryFilterHelper(nullptr, false);
}

scoped_ptr<BluetoothDiscoveryFilter>
std::unique_ptr<BluetoothDiscoveryFilter>
BluetoothAdapter::GetMergedDiscoveryFilterMasked(
BluetoothDiscoveryFilter* masked_filter) const {
return GetMergedDiscoveryFilterHelper(masked_filter, true);
Expand Down Expand Up @@ -263,13 +264,13 @@ BluetoothAdapter::~BluetoothAdapter() {
}

void BluetoothAdapter::OnStartDiscoverySession(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const DiscoverySessionCallback& callback) {
VLOG(1) << "BluetoothAdapter::OnStartDiscoverySession";
RecordBluetoothDiscoverySessionStartOutcome(
UMABluetoothDiscoverySessionOutcome::SUCCESS);

scoped_ptr<BluetoothDiscoverySession> discovery_session(
std::unique_ptr<BluetoothDiscoverySession> discovery_session(
new BluetoothDiscoverySession(scoped_refptr<BluetoothAdapter>(this),
std::move(discovery_filter)));
discovery_sessions_.insert(discovery_session.get());
Expand Down Expand Up @@ -307,11 +308,11 @@ void BluetoothAdapter::DeleteDeviceForTesting(const std::string& address) {
devices_.erase(address);
}

scoped_ptr<BluetoothDiscoveryFilter>
std::unique_ptr<BluetoothDiscoveryFilter>
BluetoothAdapter::GetMergedDiscoveryFilterHelper(
const BluetoothDiscoveryFilter* masked_filter,
bool omit) const {
scoped_ptr<BluetoothDiscoveryFilter> result;
std::unique_ptr<BluetoothDiscoveryFilter> result;
bool first_merge = true;

std::set<BluetoothDiscoverySession*> temp(discovery_sessions_);
Expand Down
25 changes: 13 additions & 12 deletions device/bluetooth/bluetooth_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdint.h>

#include <list>
#include <memory>
#include <set>
#include <string>
#include <utility>
Expand Down Expand Up @@ -185,9 +186,9 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
ServiceOptions();
~ServiceOptions();

scoped_ptr<int> channel;
scoped_ptr<int> psm;
scoped_ptr<std::string> name;
std::unique_ptr<int> channel;
std::unique_ptr<int> psm;
std::unique_ptr<std::string> name;
};

// The ErrorCallback is used for methods that can fail in which case it is
Expand All @@ -198,7 +199,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
// initialization, if initialization is asynchronous on the platform.
typedef base::Callback<void()> InitCallback;

typedef base::Callback<void(scoped_ptr<BluetoothDiscoverySession>)>
typedef base::Callback<void(std::unique_ptr<BluetoothDiscoverySession>)>
DiscoverySessionCallback;
typedef std::vector<BluetoothDevice*> DeviceList;
typedef std::vector<const BluetoothDevice*> ConstDeviceList;
Expand Down Expand Up @@ -305,17 +306,17 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
virtual void StartDiscoverySession(const DiscoverySessionCallback& callback,
const ErrorCallback& error_callback);
virtual void StartDiscoverySessionWithFilter(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const DiscoverySessionCallback& callback,
const ErrorCallback& error_callback);

// Return all discovery filters assigned to this adapter merged together.
scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilter() const;
std::unique_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilter() const;

// Works like GetMergedDiscoveryFilter, but doesn't take |masked_filter| into
// account. |masked_filter| is compared by pointer, and must be a member of
// active session.
scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterMasked(
std::unique_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterMasked(
BluetoothDiscoveryFilter* masked_filter) const;

// Requests the list of devices from the adapter. All devices are returned,
Expand Down Expand Up @@ -400,7 +401,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
// Creates and registers an advertisement for broadcast over the LE channel.
// The created advertisement will be returned via the success callback.
virtual void RegisterAdvertisement(
scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data,
const CreateAdvertisementCallback& callback,
const CreateAdvertisementErrorCallback& error_callback) = 0;

Expand Down Expand Up @@ -428,7 +429,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
friend class BluetoothDiscoverySession;
friend class BluetoothTestBase;

typedef base::ScopedPtrHashMap<std::string, scoped_ptr<BluetoothDevice>>
typedef base::ScopedPtrHashMap<std::string, std::unique_ptr<BluetoothDevice>>
DevicesMap;
typedef std::pair<BluetoothDevice::PairingDelegate*, PairingDelegatePriority>
PairingDelegatePair;
Expand Down Expand Up @@ -485,7 +486,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
// Used to set and update the discovery filter used by the underlying
// Bluetooth controller.
virtual void SetDiscoveryFilter(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
const DiscoverySessionErrorCallback& error_callback) = 0;

Expand All @@ -497,7 +498,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter

// Success callback passed to AddDiscoverySession by StartDiscoverySession.
void OnStartDiscoverySession(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const DiscoverySessionCallback& callback);

// Error callback passed to AddDiscoverySession by StartDiscoverySession.
Expand Down Expand Up @@ -541,7 +542,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter

// Return all discovery filters assigned to this adapter merged together.
// If |omit| is true, |discovery_filter| will not be processed.
scoped_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterHelper(
std::unique_ptr<BluetoothDiscoveryFilter> GetMergedDiscoveryFilterHelper(
const BluetoothDiscoveryFilter* discovery_filter,
bool omit) const;

Expand Down
9 changes: 6 additions & 3 deletions device/bluetooth/bluetooth_adapter_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "device/bluetooth/bluetooth_adapter_android.h"

#include <memory>

#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/sequenced_task_runner.h"
Expand Down Expand Up @@ -133,7 +135,7 @@ void BluetoothAdapterAndroid::RegisterAudioSink(
}

void BluetoothAdapterAndroid::RegisterAdvertisement(
scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data,
const CreateAdvertisementCallback& callback,
const CreateAdvertisementErrorCallback& error_callback) {
error_callback.Run(BluetoothAdvertisement::ERROR_UNSUPPORTED_PLATFORM);
Expand Down Expand Up @@ -168,7 +170,8 @@ void BluetoothAdapterAndroid::CreateOrUpdateDeviceOnScan(
BluetoothDeviceAndroid* device_android =
BluetoothDeviceAndroid::Create(this, bluetooth_device_wrapper);
device_android->UpdateAdvertisedUUIDs(advertised_uuids);
devices_.add(device_address, scoped_ptr<BluetoothDevice>(device_android));
devices_.add(device_address,
std::unique_ptr<BluetoothDevice>(device_android));
FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DeviceAdded(this, device_android));
} else {
Expand Down Expand Up @@ -218,7 +221,7 @@ void BluetoothAdapterAndroid::RemoveDiscoverySession(
}

void BluetoothAdapterAndroid::SetDiscoveryFilter(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
const DiscoverySessionErrorCallback& error_callback) {
// TODO(scheib): Support filters crbug.com/490401
Expand Down
6 changes: 4 additions & 2 deletions device/bluetooth/bluetooth_adapter_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_
#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_ANDROID_H_

#include <memory>

#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
Expand Down Expand Up @@ -80,7 +82,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final
const AcquiredCallback& callback,
const BluetoothAudioSink::ErrorCallback& error_callback) override;
void RegisterAdvertisement(
scoped_ptr<BluetoothAdvertisement::Data> advertisement_data,
std::unique_ptr<BluetoothAdvertisement::Data> advertisement_data,
const CreateAdvertisementCallback& callback,
const CreateAdvertisementErrorCallback& error_callback) override;

Expand Down Expand Up @@ -118,7 +120,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterAndroid final
const base::Closure& callback,
const DiscoverySessionErrorCallback& error_callback) override;
void SetDiscoveryFilter(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
const DiscoverySessionErrorCallback& error_callback) override;
void RemovePairingDelegateInternal(
Expand Down
21 changes: 11 additions & 10 deletions device/bluetooth/bluetooth_adapter_bluez.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "device/bluetooth/bluetooth_adapter_bluez.h"

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

Expand Down Expand Up @@ -389,7 +390,7 @@ void BluetoothAdapterBlueZ::RegisterAudioSink(
}

void BluetoothAdapterBlueZ::RegisterAdvertisement(
scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data,
std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data,
const CreateAdvertisementCallback& callback,
const CreateAdvertisementErrorCallback& error_callback) {
scoped_refptr<BluetoothAdvertisementBlueZ> advertisement(
Expand Down Expand Up @@ -459,7 +460,7 @@ void BluetoothAdapterBlueZ::DeviceAdded(const dbus::ObjectPath& object_path) {
DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end());

devices_.set(device_bluez->GetAddress(),
scoped_ptr<BluetoothDevice>(device_bluez));
std::unique_ptr<BluetoothDevice>(device_bluez));

FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
DeviceAdded(this, device_bluez));
Expand All @@ -471,7 +472,7 @@ void BluetoothAdapterBlueZ::DeviceRemoved(const dbus::ObjectPath& object_path) {
BluetoothDeviceBlueZ* device_bluez =
static_cast<BluetoothDeviceBlueZ*>(iter->second);
if (device_bluez->object_path() == object_path) {
scoped_ptr<BluetoothDevice> scoped_device =
std::unique_ptr<BluetoothDevice> scoped_device =
devices_.take_and_erase(iter->first);

FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
Expand Down Expand Up @@ -499,13 +500,13 @@ void BluetoothAdapterBlueZ::DevicePropertyChanged(
std::string old_address = iter->first;
VLOG(1) << "Device changed address, old: " << old_address
<< " new: " << device_bluez->GetAddress();
scoped_ptr<BluetoothDevice> scoped_device =
std::unique_ptr<BluetoothDevice> scoped_device =
devices_.take_and_erase(iter);
ignore_result(scoped_device.release());

DCHECK(devices_.find(device_bluez->GetAddress()) == devices_.end());
devices_.set(device_bluez->GetAddress(),
scoped_ptr<BluetoothDevice>(device_bluez));
std::unique_ptr<BluetoothDevice>(device_bluez));
NotifyDeviceAddressChanged(device_bluez, old_address);
break;
}
Expand Down Expand Up @@ -1022,7 +1023,7 @@ void BluetoothAdapterBlueZ::RemoveProfile(const BluetoothUUID& uuid) {

void BluetoothAdapterBlueZ::OnRegisterProfile(
const BluetoothUUID& uuid,
scoped_ptr<BluetoothAdapterProfileBlueZ> profile) {
std::unique_ptr<BluetoothAdapterProfileBlueZ> profile) {
profiles_[uuid] = profile.release();

if (profile_queues_.find(uuid) == profile_queues_.end())
Expand Down Expand Up @@ -1139,7 +1140,7 @@ void BluetoothAdapterBlueZ::AddDiscoverySession(
if (discovery_filter) {
discovery_request_pending_ = true;

scoped_ptr<BluetoothDiscoveryFilter> df(new BluetoothDiscoveryFilter(
std::unique_ptr<BluetoothDiscoveryFilter> df(new BluetoothDiscoveryFilter(
BluetoothDiscoveryFilter::Transport::TRANSPORT_DUAL));
df->CopyFrom(*discovery_filter);
SetDiscoveryFilter(
Expand Down Expand Up @@ -1217,7 +1218,7 @@ void BluetoothAdapterBlueZ::RemoveDiscoverySession(
}

void BluetoothAdapterBlueZ::SetDiscoveryFilter(
scoped_ptr<BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
const DiscoverySessionErrorCallback& error_callback) {
if (!IsPresent()) {
Expand Down Expand Up @@ -1269,8 +1270,8 @@ void BluetoothAdapterBlueZ::SetDiscoveryFilter(

current_filter_->GetUUIDs(uuids);
if (uuids.size()) {
dbus_discovery_filter.uuids =
scoped_ptr<std::vector<std::string>>(new std::vector<std::string>);
dbus_discovery_filter.uuids = std::unique_ptr<std::vector<std::string>>(
new std::vector<std::string>);

for (const auto& it : uuids)
dbus_discovery_filter.uuids.get()->push_back(it.value());
Expand Down
11 changes: 6 additions & 5 deletions device/bluetooth/bluetooth_adapter_bluez.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdint.h>

#include <map>
#include <memory>
#include <queue>
#include <string>
#include <utility>
Expand Down Expand Up @@ -112,7 +113,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ
const device::BluetoothAudioSink::ErrorCallback& error_callback) override;

void RegisterAdvertisement(
scoped_ptr<device::BluetoothAdvertisement::Data> advertisement_data,
std::unique_ptr<device::BluetoothAdvertisement::Data> advertisement_data,
const CreateAdvertisementCallback& callback,
const CreateAdvertisementErrorCallback& error_callback) override;

Expand Down Expand Up @@ -283,7 +284,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ
const base::Closure& callback,
const DiscoverySessionErrorCallback& error_callback) override;
void SetDiscoveryFilter(
scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter,
std::unique_ptr<device::BluetoothDiscoveryFilter> discovery_filter,
const base::Closure& callback,
const DiscoverySessionErrorCallback& error_callback) override;

Expand Down Expand Up @@ -320,7 +321,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ

// Called by dbus:: on completion of the D-Bus method to register a profile.
void OnRegisterProfile(const device::BluetoothUUID& uuid,
scoped_ptr<BluetoothAdapterProfileBlueZ> profile);
std::unique_ptr<BluetoothAdapterProfileBlueZ> profile);

void SetProfileDelegate(
const device::BluetoothUUID& uuid,
Expand Down Expand Up @@ -371,7 +372,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ

// Instance of the D-Bus agent object used for pairing, initialized with
// our own class as its delegate.
scoped_ptr<bluez::BluetoothAgentServiceProvider> agent_;
std::unique_ptr<bluez::BluetoothAgentServiceProvider> agent_;

// UI thread task runner and socket thread object used to create sockets.
scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
Expand All @@ -384,7 +385,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterBlueZ
std::map<device::BluetoothUUID, std::vector<RegisterProfileCompletionPair>*>
profile_queues_;

scoped_ptr<device::BluetoothDiscoveryFilter> current_filter_;
std::unique_ptr<device::BluetoothDiscoveryFilter> current_filter_;

// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
Expand Down
Loading

0 comments on commit 08c9d69

Please sign in to comment.