Skip to content

Commit

Permalink
Convert base::Bind etc in services/ (1/2)
Browse files Browse the repository at this point in the history
This covers removal of deprecated base::Bind, base::Callback,
base::Closure, base::Passed across services/data_decoder/ and
services/device/.

Bug: 1007831
Change-Id: I03ca32424d53e91e6720e9209cb19a564a19de96
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1970231
Reviewed-by: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#725374}
  • Loading branch information
krockot authored and Commit Bot committed Dec 17, 2019
1 parent b48ae3b commit c6e3166
Show file tree
Hide file tree
Showing 100 changed files with 519 additions and 494 deletions.
20 changes: 10 additions & 10 deletions device/bluetooth/dbus/bluetooth_adapter_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
// BluetoothAdapterClient override.
void RemoveDevice(const dbus::ObjectPath& object_path,
const dbus::ObjectPath& device_path,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) override {
dbus::MethodCall method_call(bluetooth_adapter::kBluetoothAdapterInterface,
bluetooth_adapter::kRemoveDevice);
Expand All @@ -346,7 +346,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
object_proxy->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&BluetoothAdapterClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback),
weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
base::BindOnce(&BluetoothAdapterClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
Expand All @@ -355,7 +355,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
// BluetoothAdapterClient override.
void SetDiscoveryFilter(const dbus::ObjectPath& object_path,
const DiscoveryFilter& discovery_filter,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) override {
dbus::MethodCall method_call(bluetooth_adapter::kBluetoothAdapterInterface,
bluetooth_adapter::kSetDiscoveryFilter);
Expand Down Expand Up @@ -426,7 +426,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
object_proxy->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&BluetoothAdapterClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback),
weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
base::BindOnce(&BluetoothAdapterClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
Expand All @@ -435,7 +435,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
// BluetoothAdapterClient override.
void CreateServiceRecord(const dbus::ObjectPath& object_path,
const bluez::BluetoothServiceRecordBlueZ& record,
const ServiceRecordCallback& callback,
ServiceRecordCallback callback,
ErrorCallback error_callback) override {
dbus::MethodCall method_call(bluetooth_adapter::kBluetoothAdapterInterface,
bluetooth_adapter::kCreateServiceRecord);
Expand Down Expand Up @@ -464,7 +464,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
object_proxy->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&BluetoothAdapterClientImpl::OnCreateServiceRecord,
weak_ptr_factory_.GetWeakPtr(), callback),
weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
base::BindOnce(&BluetoothAdapterClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
Expand All @@ -473,7 +473,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
// BluetoothAdapterClient override.
void RemoveServiceRecord(const dbus::ObjectPath& object_path,
uint32_t handle,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) override {
dbus::MethodCall method_call(bluetooth_adapter::kBluetoothAdapterInterface,
bluetooth_adapter::kRemoveServiceRecord);
Expand All @@ -490,7 +490,7 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
object_proxy->CallMethodWithErrorCallback(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::BindOnce(&BluetoothAdapterClientImpl::OnSuccess,
weak_ptr_factory_.GetWeakPtr(), callback),
weak_ptr_factory_.GetWeakPtr(), std::move(callback)),
base::BindOnce(&BluetoothAdapterClientImpl::OnError,
weak_ptr_factory_.GetWeakPtr(),
std::move(error_callback)));
Expand Down Expand Up @@ -564,14 +564,14 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient,
}

// Called when a response for successful method call is received.
void OnCreateServiceRecord(const ServiceRecordCallback& callback,
void OnCreateServiceRecord(ServiceRecordCallback callback,
dbus::Response* response) {
DCHECK(response);
dbus::MessageReader reader(response);
uint32_t handle = 0;
if (!reader.PopUint32(&handle))
LOG(ERROR) << "Invalid response from CreateServiceRecord.";
callback.Run(handle);
std::move(callback).Run(handle);
}

// Called when a response for successful method call is received.
Expand Down
10 changes: 5 additions & 5 deletions device/bluetooth/dbus/bluetooth_adapter_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterClient : public BluezDBusClient {
virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;

// Callback used to send back the handle of a created service record.
using ServiceRecordCallback = base::Callback<void(uint32_t)>;
using ServiceRecordCallback = base::OnceCallback<void(uint32_t)>;

// The ErrorCallback is used by adapter methods to indicate failure.
// It receives two arguments: the name of the error in |error_name| and
Expand Down Expand Up @@ -193,7 +193,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterClient : public BluezDBusClient {
// and discards any pairing information.
virtual void RemoveDevice(const dbus::ObjectPath& object_path,
const dbus::ObjectPath& device_path,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;

// Sets the device discovery filter on the adapter with object path
Expand All @@ -204,21 +204,21 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapterClient : public BluezDBusClient {
// will be started right after call to StartDiscovery.
virtual void SetDiscoveryFilter(const dbus::ObjectPath& object_path,
const DiscoveryFilter& discovery_filter,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;

// Creates the service record |record| on the adapter with the object path
// |object_path|.
virtual void CreateServiceRecord(const dbus::ObjectPath& object_path,
const BluetoothServiceRecordBlueZ& record,
const ServiceRecordCallback& callback,
ServiceRecordCallback callback,
ErrorCallback error_callback) = 0;

// Removes the service record with the uuid |uuid| on the adapter with the
// object path |object_path|.
virtual void RemoveServiceRecord(const dbus::ObjectPath& object_path,
uint32_t handle,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;

virtual void SetLongTermKeys(
Expand Down
16 changes: 8 additions & 8 deletions device/bluetooth/dbus/fake_bluetooth_adapter_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void FakeBluetoothAdapterClient::UnpauseDiscovery(
void FakeBluetoothAdapterClient::RemoveDevice(
const dbus::ObjectPath& object_path,
const dbus::ObjectPath& device_path,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (object_path != dbus::ObjectPath(kAdapterPath)) {
std::move(error_callback).Run(kNoResponseError, "");
Expand All @@ -229,7 +229,7 @@ void FakeBluetoothAdapterClient::RemoveDevice(

VLOG(1) << "RemoveDevice: " << object_path.value() << " "
<< device_path.value();
callback.Run();
std::move(callback).Run();

FakeBluetoothDeviceClient* device_client =
static_cast<FakeBluetoothDeviceClient*>(
Expand All @@ -248,7 +248,7 @@ void FakeBluetoothAdapterClient::MakeStartDiscoveryFail() {
void FakeBluetoothAdapterClient::SetDiscoveryFilter(
const dbus::ObjectPath& object_path,
const DiscoveryFilter& discovery_filter,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) {
if (object_path != dbus::ObjectPath(kAdapterPath)) {
PostDelayedTask(
Expand All @@ -266,24 +266,24 @@ void FakeBluetoothAdapterClient::SetDiscoveryFilter(

discovery_filter_.reset(new DiscoveryFilter());
discovery_filter_->CopyFrom(discovery_filter);
PostDelayedTask(callback);
PostDelayedTask(std::move(callback));
}

void FakeBluetoothAdapterClient::CreateServiceRecord(
const dbus::ObjectPath& object_path,
const bluez::BluetoothServiceRecordBlueZ& record,
const ServiceRecordCallback& callback,
ServiceRecordCallback callback,
ErrorCallback error_callback) {
++last_handle_;
records_.insert(
std::pair<uint32_t, BluetoothServiceRecordBlueZ>(last_handle_, record));
callback.Run(last_handle_);
std::move(callback).Run(last_handle_);
}

void FakeBluetoothAdapterClient::RemoveServiceRecord(
const dbus::ObjectPath& object_path,
uint32_t handle,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) {
auto it = records_.find(handle);
if (it == records_.end()) {
Expand All @@ -293,7 +293,7 @@ void FakeBluetoothAdapterClient::RemoveServiceRecord(
return;
}
records_.erase(it);
callback.Run();
std::move(callback).Run();
}

void FakeBluetoothAdapterClient::SetLongTermKeys(
Expand Down
8 changes: 4 additions & 4 deletions device/bluetooth/dbus/fake_bluetooth_adapter_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ class DEVICE_BLUETOOTH_EXPORT FakeBluetoothAdapterClient
ErrorCallback error_callback) override;
void RemoveDevice(const dbus::ObjectPath& object_path,
const dbus::ObjectPath& device_path,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void SetDiscoveryFilter(const dbus::ObjectPath& object_path,
const DiscoveryFilter& discovery_filter,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void CreateServiceRecord(const dbus::ObjectPath& object_path,
const bluez::BluetoothServiceRecordBlueZ& record,
const ServiceRecordCallback& callback,
ServiceRecordCallback callback,
ErrorCallback error_callback) override;
void RemoveServiceRecord(const dbus::ObjectPath& object_path,
uint32_t handle,
const base::Closure& callback,
base::OnceClosure callback,
ErrorCallback error_callback) override;
void SetLongTermKeys(const dbus::ObjectPath& object_path,
const std::vector<std::vector<uint8_t>>& long_term_keys,
Expand Down
2 changes: 1 addition & 1 deletion services/data_decoder/image_decoder_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Request {
decoder_->DecodeImage(
image, mojom::ImageCodec::DEFAULT, shrink, kTestMaxImageSize,
gfx::Size(), // Take the smallest frame (there's only one frame).
base::Bind(&Request::OnRequestDone, base::Unretained(this)));
base::BindOnce(&Request::OnRequestDone, base::Unretained(this)));
}

const SkBitmap& bitmap() const { return bitmap_; }
Expand Down
4 changes: 2 additions & 2 deletions services/data_decoder/public/cpp/decode_image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void DecodeAnimation(DataDecoder* data_decoder,

// |call_once| runs |callback| on its first invocation.
auto call_once = base::AdaptCallbackForRepeating(std::move(callback));
decoder.set_disconnect_handler(base::BindOnce(
call_once, base::Passed(std::vector<mojom::AnimationFramePtr>())));
decoder.set_disconnect_handler(
base::BindOnce(call_once, std::vector<mojom::AnimationFramePtr>()));

mojom::ImageDecoder* raw_decoder = decoder.get();
raw_decoder->DecodeAnimation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ TEST_F(SafeWebBundleParserTest, ParseGoldenFile) {
{
base::RunLoop run_loop;
parser.ParseMetadata(base::BindOnce(
[](base::Closure quit_closure,
[](base::OnceClosure quit_closure,
mojom::BundleMetadataPtr* metadata_result,
mojom::BundleMetadataPtr metadata,
mojom::BundleMetadataParseErrorPtr error) {
Expand All @@ -163,7 +163,7 @@ TEST_F(SafeWebBundleParserTest, ParseGoldenFile) {
entry.second->response_locations[0]->offset,
entry.second->response_locations[0]->length,
base::BindOnce(
[](base::Closure quit_closure, const std::string url,
[](base::OnceClosure quit_closure, const std::string url,
std::map<std::string, mojom::BundleResponsePtr>* responses,
mojom::BundleResponsePtr response,
mojom::BundleResponseParseErrorPtr error) {
Expand Down Expand Up @@ -259,7 +259,7 @@ TEST_F(SafeWebBundleParserTest, ConnectionError) {
base::RunLoop run_loop;
bool parsed = false;
parser.ParseMetadata(base::BindOnce(
[](base::Closure quit_closure, bool* parsed,
[](base::OnceClosure quit_closure, bool* parsed,
mojom::BundleMetadataPtr metadata,
mojom::BundleMetadataParseErrorPtr error) {
EXPECT_FALSE(metadata);
Expand Down
13 changes: 7 additions & 6 deletions services/data_decoder/web_bundle_parser_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class WebBundleParserFuzzer {
std::move(data_source_remote));

quit_loop_ = run_loop->QuitClosure();
parser_->ParseMetadata(base::Bind(&WebBundleParserFuzzer::OnParseMetadata,
base::Unretained(this)));
parser_->ParseMetadata(base::BindOnce(
&WebBundleParserFuzzer::OnParseMetadata, base::Unretained(this)));
}

void OnParseMetadata(data_decoder::mojom::BundleMetadataPtr metadata,
Expand All @@ -84,9 +84,10 @@ class WebBundleParserFuzzer {
return;
}

parser_->ParseResponse(locations_[index]->offset, locations_[index]->length,
base::Bind(&WebBundleParserFuzzer::OnParseResponse,
base::Unretained(this), index));
parser_->ParseResponse(
locations_[index]->offset, locations_[index]->length,
base::BindOnce(&WebBundleParserFuzzer::OnParseResponse,
base::Unretained(this), index));
}

void OnParseResponse(size_t index,
Expand All @@ -98,7 +99,7 @@ class WebBundleParserFuzzer {
private:
mojo::Remote<data_decoder::mojom::WebBundleParser> parser_;
DataSource data_source_;
base::Closure quit_loop_;
base::OnceClosure quit_loop_;
std::vector<data_decoder::mojom::BundleResponseLocationPtr> locations_;
};

Expand Down
4 changes: 2 additions & 2 deletions services/data_decoder/xml_parser_fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace {

void OnParseXml(base::Closure quit_loop,
void OnParseXml(base::OnceClosure quit_loop,
base::Optional<base::Value> value,
const base::Optional<std::string>& error) {
std::move(quit_loop).Run();
Expand All @@ -38,7 +38,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
base::SingleThreadTaskExecutor main_thread_task_executor;
base::RunLoop run_loop;
xml_parser.Parse(std::string(data_ptr, size),
base::Bind(&OnParseXml, run_loop.QuitClosure()));
base::BindOnce(&OnParseXml, run_loop.QuitClosure()));
run_loop.Run();

return 0;
Expand Down
3 changes: 2 additions & 1 deletion services/data_decoder/xml_parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void TestParseXml(const std::string& xml, const std::string& json) {

std::unique_ptr<base::Value> actual_value;
base::Optional<std::string> error;
parser.Parse(xml, base::Bind(&TestParseXmlCallback, &actual_value, &error));
parser.Parse(xml,
base::BindOnce(&TestParseXmlCallback, &actual_value, &error));
if (json.empty()) {
EXPECT_TRUE(error);
EXPECT_FALSE(actual_value)
Expand Down
5 changes: 3 additions & 2 deletions services/device/battery/battery_monitor_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ void BatteryMonitorImpl::Create(
BatteryMonitorImpl::BatteryMonitorImpl() : status_to_report_(false) {
// NOTE: DidChange may be called before AddCallback returns. This is done to
// report current status.
subscription_ = BatteryStatusService::GetInstance()->AddCallback(
base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this)));
subscription_ =
BatteryStatusService::GetInstance()->AddCallback(base::BindRepeating(
&BatteryMonitorImpl::DidChange, base::Unretained(this)));
}

BatteryMonitorImpl::~BatteryMonitorImpl() {}
Expand Down
14 changes: 7 additions & 7 deletions services/device/battery/battery_monitor_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ namespace {

void ExpectBatteryStatus(bool* out_called,
const mojom::BatteryStatus& expected,
const base::Closure& quit_closure,
base::OnceClosure quit_closure,
mojom::BatteryStatusPtr status) {
if (out_called)
*out_called = true;
EXPECT_EQ(expected.charging, status->charging);
EXPECT_EQ(expected.charging_time, status->charging_time);
EXPECT_EQ(expected.discharging_time, status->discharging_time);
EXPECT_EQ(expected.level, status->level);
quit_closure.Run();
std::move(quit_closure).Run();
}

class FakeBatteryStatusManager : public BatteryStatusManager {
Expand Down Expand Up @@ -130,7 +130,7 @@ TEST_F(BatteryMonitorImplTest, BatteryManagerDefaultValues) {
default_status.discharging_time = std::numeric_limits<double>::infinity();
default_status.level = 1.0;
base::RunLoop run_loop;
battery_monitor_->QueryNextStatus(base::Bind(
battery_monitor_->QueryNextStatus(base::BindOnce(
&ExpectBatteryStatus, nullptr, default_status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_TRUE(battery_manager()->started());
Expand All @@ -148,8 +148,8 @@ TEST_F(BatteryMonitorImplTest, BatteryManagerPredefinedValues) {
battery_manager()->set_battery_status(status);

base::RunLoop run_loop;
battery_monitor_->QueryNextStatus(base::Bind(&ExpectBatteryStatus, nullptr,
status, run_loop.QuitClosure()));
battery_monitor_->QueryNextStatus(base::BindOnce(
&ExpectBatteryStatus, nullptr, status, run_loop.QuitClosure()));
run_loop.Run();
EXPECT_TRUE(battery_manager()->started());
}
Expand All @@ -168,7 +168,7 @@ TEST_F(BatteryMonitorImplTest, BatteryManagerInvokeUpdate) {

// The first time query should succeed.
base::RunLoop run_loop1;
battery_monitor_->QueryNextStatus(base::Bind(
battery_monitor_->QueryNextStatus(base::BindOnce(
&ExpectBatteryStatus, nullptr, status, run_loop1.QuitClosure()));
run_loop1.Run();
EXPECT_TRUE(battery_manager()->started());
Expand All @@ -177,7 +177,7 @@ TEST_F(BatteryMonitorImplTest, BatteryManagerInvokeUpdate) {
bool called = false;
status.level = 0.6;
base::RunLoop run_loop2;
battery_monitor_->QueryNextStatus(base::Bind(
battery_monitor_->QueryNextStatus(base::BindOnce(
&ExpectBatteryStatus, &called, status, run_loop2.QuitClosure()));
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(called);
Expand Down
Loading

0 comments on commit c6e3166

Please sign in to comment.