[go: nahoru, domu]

Convert Callbacks to OnceCallbacks for errors in BluetoothGattDescriptor

This will allow us to convert more Callbacks in the bluetooth component
over to OnceCallbacks, which will let us convert Callbacks in content
eventually.

R=reillyg@chromium.org

Bug: 953861
Change-Id: Iaca0042c4b2ed5559a70c2136f20881546673406
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574429
Auto-Submit: danakj <danakj@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653187}
diff --git a/device/bluetooth/bluetooth_remote_gatt_descriptor_winrt.cc b/device/bluetooth/bluetooth_remote_gatt_descriptor_winrt.cc
index 33efac1..ca05ae7 100644
--- a/device/bluetooth/bluetooth_remote_gatt_descriptor_winrt.cc
+++ b/device/bluetooth/bluetooth_remote_gatt_descriptor_winrt.cc
@@ -99,11 +99,11 @@
 
 void BluetoothRemoteGattDescriptorWinrt::ReadRemoteDescriptor(
     const ValueCallback& callback,
-    const ErrorCallback& error_callback) {
+    ErrorCallback error_callback) {
   if (pending_read_callbacks_ || pending_write_callbacks_) {
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS));
     return;
   }
@@ -116,7 +116,7 @@
             << logging::SystemErrorCodeToString(hr);
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_FAILED));
     return;
   }
@@ -131,23 +131,23 @@
             << logging::SystemErrorCodeToString(hr);
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_FAILED));
     return;
   }
 
-  pending_read_callbacks_ =
-      std::make_unique<PendingReadCallbacks>(callback, error_callback);
+  pending_read_callbacks_ = std::make_unique<PendingReadCallbacks>(
+      callback, std::move(error_callback));
 }
 
 void BluetoothRemoteGattDescriptorWinrt::WriteRemoteDescriptor(
     const std::vector<uint8_t>& value,
     const base::Closure& callback,
-    const ErrorCallback& error_callback) {
+    ErrorCallback error_callback) {
   if (pending_read_callbacks_ || pending_write_callbacks_) {
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_IN_PROGRESS));
     return;
   }
@@ -159,7 +159,7 @@
             << logging::SystemErrorCodeToString(hr);
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_FAILED));
     return;
   }
@@ -171,7 +171,7 @@
             << logging::SystemErrorCodeToString(hr);
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_FAILED));
     return;
   }
@@ -183,7 +183,7 @@
             << logging::SystemErrorCodeToString(hr);
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_FAILED));
     return;
   }
@@ -199,13 +199,13 @@
             << logging::SystemErrorCodeToString(hr);
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE,
-        base::BindOnce(error_callback,
+        base::BindOnce(std::move(error_callback),
                        BluetoothRemoteGattService::GATT_ERROR_FAILED));
     return;
   }
 
-  pending_write_callbacks_ =
-      std::make_unique<PendingWriteCallbacks>(callback, error_callback);
+  pending_write_callbacks_ = std::make_unique<PendingWriteCallbacks>(
+      callback, std::move(error_callback));
 }
 
 IGattDescriptor* BluetoothRemoteGattDescriptorWinrt::GetDescriptorForTesting() {
@@ -252,8 +252,8 @@
   auto pending_read_callbacks = std::move(pending_read_callbacks_);
 
   if (!read_result) {
-    pending_read_callbacks->error_callback.Run(
-        BluetoothGattService::GATT_ERROR_FAILED);
+    std::move(pending_read_callbacks->error_callback)
+        .Run(BluetoothGattService::GATT_ERROR_FAILED);
     return;
   }
 
@@ -262,8 +262,8 @@
   if (FAILED(hr)) {
     VLOG(2) << "Getting GATT Communication Status failed: "
             << logging::SystemErrorCodeToString(hr);
-    pending_read_callbacks->error_callback.Run(
-        BluetoothGattService::GATT_ERROR_FAILED);
+    std::move(pending_read_callbacks->error_callback)
+        .Run(BluetoothGattService::GATT_ERROR_FAILED);
     return;
   }
 
@@ -274,13 +274,14 @@
     if (FAILED(hr)) {
       VLOG(2) << "As IGattReadResult2 failed: "
               << logging::SystemErrorCodeToString(hr);
-      pending_read_callbacks->error_callback.Run(
-          BluetoothGattService::GATT_ERROR_FAILED);
+      std::move(pending_read_callbacks->error_callback)
+          .Run(BluetoothGattService::GATT_ERROR_FAILED);
       return;
     }
 
-    pending_read_callbacks->error_callback.Run(
-        BluetoothRemoteGattServiceWinrt::GetGattErrorCode(read_result_2.Get()));
+    std::move(pending_read_callbacks->error_callback)
+        .Run(BluetoothRemoteGattServiceWinrt::GetGattErrorCode(
+            read_result_2.Get()));
     return;
   }
 
@@ -289,8 +290,8 @@
   if (FAILED(hr)) {
     VLOG(2) << "Getting Descriptor Value failed: "
             << logging::SystemErrorCodeToString(hr);
-    pending_read_callbacks->error_callback.Run(
-        BluetoothGattService::GATT_ERROR_FAILED);
+    std::move(pending_read_callbacks->error_callback)
+        .Run(BluetoothGattService::GATT_ERROR_FAILED);
     return;
   }
 
@@ -300,8 +301,8 @@
   if (FAILED(hr)) {
     VLOG(2) << "Getting Pointer To Buffer Data failed: "
             << logging::SystemErrorCodeToString(hr);
-    pending_read_callbacks->error_callback.Run(
-        BluetoothGattService::GATT_ERROR_FAILED);
+    std::move(pending_read_callbacks->error_callback)
+        .Run(BluetoothGattService::GATT_ERROR_FAILED);
     return;
   }
 
@@ -315,8 +316,8 @@
   auto pending_write_callbacks = std::move(pending_write_callbacks_);
 
   if (!write_result) {
-    pending_write_callbacks->error_callback.Run(
-        BluetoothGattService::GATT_ERROR_FAILED);
+    std::move(pending_write_callbacks->error_callback)
+        .Run(BluetoothGattService::GATT_ERROR_FAILED);
     return;
   }
 
@@ -325,15 +326,16 @@
   if (FAILED(hr)) {
     VLOG(2) << "Getting GATT Communication Status failed: "
             << logging::SystemErrorCodeToString(hr);
-    pending_write_callbacks->error_callback.Run(
-        BluetoothGattService::GATT_ERROR_FAILED);
+    std::move(pending_write_callbacks->error_callback)
+        .Run(BluetoothGattService::GATT_ERROR_FAILED);
     return;
   }
 
   if (status != GattCommunicationStatus_Success) {
     VLOG(2) << "Unexpected GattCommunicationStatus: " << status;
-    pending_write_callbacks->error_callback.Run(
-        BluetoothRemoteGattServiceWinrt::GetGattErrorCode(write_result.Get()));
+    std::move(pending_write_callbacks->error_callback)
+        .Run(BluetoothRemoteGattServiceWinrt::GetGattErrorCode(
+            write_result.Get()));
     return;
   }