Commit dbaf0192 authored by Francois Beaufort's avatar Francois Beaufort Committed by Chromium LUCI CQ

[WebNFC] Remove unused CancelPushResponse callback

As WriteOnRequestCompleted is always called whether the push operation
is cancelled successfully or not, this CL removes the unused cancelled
callback.

Bug: 1151857
Change-Id: I5f5bb163e52afe2f9b163a043fa25eb5def9cc8e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2554607
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Cr-Commit-Position: refs/heads/master@{#832308}
parent f30087f5
......@@ -204,21 +204,11 @@ public class NfcImpl implements Nfc {
/**
* Cancels pending push operation.
*
* @param callback that is used to notify caller when cancelPush() is completed.
*/
@Override
public void cancelPush(CancelPushResponse callback) {
if (!checkIfReady(callback)) return;
if (mPendingPushOperation == null) {
callback.call(createError(
NdefErrorType.CANNOT_CANCEL, "No pending push operation to cancel."));
} else {
completePendingPushOperation(createError(
NdefErrorType.OPERATION_CANCELLED, "The push operation is already cancelled."));
callback.call(null);
}
public void cancelPush() {
completePendingPushOperation(createError(
NdefErrorType.OPERATION_CANCELLED, "The push operation is already cancelled."));
}
/**
......@@ -342,21 +332,7 @@ public class NfcImpl implements Nfc {
/**
* Uses checkIfReady() method and if NFC cannot be used, calls mojo callback with NdefError.
*
* @param WatchResponse Callback that is provided to watch() method.
* @return boolean true if NFC functionality can be used, false otherwise.
*/
private boolean checkIfReady(WatchResponse callback) {
NdefError error = checkIfReady();
if (error == null) return true;
callback.call(error);
return false;
}
/**
* Uses checkIfReady() method and if NFC cannot be used, calls mojo callback with NdefError.
*
* @param callback Generic callback that is provided to push() and cancelPush() methods.
* @param callback Generic callback that is provided to watch() and push() methods.
* @return boolean true if NFC functionality can be used, false otherwise.
*/
private boolean checkIfReady(Callbacks.Callback1<NdefError> callback) {
......
......@@ -50,7 +50,6 @@ import org.chromium.device.mojom.NdefMessage;
import org.chromium.device.mojom.NdefRecord;
import org.chromium.device.mojom.NdefRecordTypeCategory;
import org.chromium.device.mojom.NdefWriteOptions;
import org.chromium.device.mojom.Nfc.CancelPushResponse;
import org.chromium.device.mojom.Nfc.PushResponse;
import org.chromium.device.mojom.Nfc.WatchResponse;
import org.chromium.device.mojom.NfcClient;
......@@ -1138,7 +1137,7 @@ public class NFCTest {
}
/**
* Test that Nfc.cancelPush() cancels pending push opration and completes successfully.
* Test that Nfc.cancelPush() cancels pending push operation.
*/
@Test
@Feature({"NFCTest"})
......@@ -1146,17 +1145,12 @@ public class NFCTest {
TestNfcImpl nfc = new TestNfcImpl(mContext, mDelegate);
mDelegate.invokeCallback();
PushResponse mockPushCallback = mock(PushResponse.class);
CancelPushResponse mockCancelPushCallback = mock(CancelPushResponse.class);
nfc.push(createMojoNdefMessage(), createNdefWriteOptions(), mockPushCallback);
nfc.cancelPush(mockCancelPushCallback);
nfc.cancelPush();
// Check that push request was cancelled with OPERATION_CANCELLED.
verify(mockPushCallback).call(mErrorCaptor.capture());
assertEquals(NdefErrorType.OPERATION_CANCELLED, mErrorCaptor.getValue().errorType);
// Check that cancel request was successfuly completed.
verify(mockCancelPushCallback).call(mErrorCaptor.capture());
assertNull(mErrorCaptor.getValue());
}
/**
......@@ -1426,8 +1420,7 @@ public class NFCTest {
.enableReaderMode(any(Activity.class), any(ReaderCallback.class), anyInt(),
(Bundle) isNull());
CancelPushResponse mockCancelPushCallback = mock(CancelPushResponse.class);
nfc.cancelPush(mockCancelPushCallback);
nfc.cancelPush();
// Reader mode is disabled.
verify(mNfcAdapter, times(1)).disableReaderMode(mActivity);
......@@ -1463,8 +1456,7 @@ public class NFCTest {
assertEquals(NdefErrorType.OPERATION_CANCELLED, mErrorCaptor.getValue().errorType);
// Cancel the second push.
CancelPushResponse mockCancelPushCallback = mock(CancelPushResponse.class);
nfc.cancelPush(mockCancelPushCallback);
nfc.cancelPush();
// Reader mode is disabled after cancelPush is invoked.
verify(mNfcAdapter, times(1)).disableReaderMode(mActivity);
......@@ -1494,8 +1486,7 @@ public class NFCTest {
.enableReaderMode(any(Activity.class), any(ReaderCallback.class), anyInt(),
(Bundle) isNull());
CancelPushResponse mockCancelPushCallback = mock(CancelPushResponse.class);
nfc.cancelPush(mockCancelPushCallback);
nfc.cancelPush();
// Push was cancelled with OPERATION_CANCELLED.
verify(mockPushCallback).call(mErrorCaptor.capture());
......
......@@ -14,7 +14,6 @@ enum NDEFErrorType {
NOT_READABLE,
INVALID_MESSAGE,
OPERATION_CANCELLED,
CANNOT_CANCEL,
// Transfer data error.
IO_ERROR
};
......@@ -114,7 +113,7 @@ interface NFC {
Push(NDEFMessage message, NDEFWriteOptions? options) => (NDEFError? error);
// Cancels pending push request.
CancelPush() => (NDEFError? error);
CancelPush();
// Starts watching for nearby NFC devices. |id| identifies each watch request
// on the current Mojo connection.
......
......@@ -300,10 +300,8 @@ void NDEFReader::WriteOnRequestCompleted(
void NDEFReader::WriteAbort(ScriptPromiseResolver* resolver) {
// WriteOnRequestCompleted() should always be called whether the push
// operation is cancelled successfully or not. So do nothing for the cancelled
// callback.
// TODO(https://crbug.com/1151857) Remove the callback since it is unused.
GetNfcProxy()->CancelPush(device::mojom::blink::NFC::CancelPushCallback());
// operation is cancelled successfully or not.
GetNfcProxy()->CancelPush();
}
NFCProxy* NDEFReader::GetNfcProxy() const {
......
......@@ -84,11 +84,10 @@ void NFCProxy::Push(device::mojom::blink::NDEFMessagePtr message,
nfc_remote_->Push(std::move(message), std::move(options), std::move(cb));
}
void NFCProxy::CancelPush(
device::mojom::blink::NFC::CancelPushCallback callback) {
void NFCProxy::CancelPush() {
if (!nfc_remote_)
return;
nfc_remote_->CancelPush(std::move(callback));
nfc_remote_->CancelPush();
}
// device::mojom::blink::NFCClient implementation.
......
......@@ -45,7 +45,7 @@ class MODULES_EXPORT NFCProxy final : public GarbageCollected<NFCProxy>,
void Push(device::mojom::blink::NDEFMessagePtr,
device::mojom::blink::NDEFWriteOptionsPtr,
device::mojom::blink::NFC::PushCallback);
void CancelPush(device::mojom::blink::NFC::CancelPushCallback);
void CancelPush();
private:
// Implementation of device::mojom::blink::NFCClient.
......
......@@ -105,9 +105,7 @@ class FakeNfcService : public device::mojom::blink::NFC {
set_tag_message(std::move(message));
std::move(callback).Run(nullptr);
}
void CancelPush(CancelPushCallback callback) override {
std::move(callback).Run(nullptr);
}
void CancelPush() override {}
void Watch(uint32_t id, WatchCallback callback) override {
if (watch_error_) {
std::move(callback).Run(watch_error_.Clone());
......
......@@ -31,9 +31,6 @@ DOMException* NDEFErrorTypeToDOMException(
case device::mojom::blink::NDEFErrorType::OPERATION_CANCELLED:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError,
error_message);
case device::mojom::blink::NDEFErrorType::CANNOT_CANCEL:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNoModificationAllowedError, error_message);
case device::mojom::blink::NDEFErrorType::IO_ERROR:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kNetworkError,
error_message);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment