Skip to content

Commit

Permalink
Introduce new PostAsync helpers for Windows
Browse files Browse the repository at this point in the history
Adding new helper methods to eventually replace PostAsyncResults that
do not hold references to in-progress IAsyncOperations and expose the
failure information of failed IAsyncOperations to callers who want it.

This does not modify the behavior of PostAsyncResults.

Design doc covering this change:
https://docs.google.com/document/d/1_dnDOCzr_FrhnJ4I6r_tMOxQRdiF32CdKDlfX6SQC0A/edit?usp=sharing
Bug: 1128779

Change-Id: I0c242f75488c8a9e2e265db8e5e25221f6645a17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410739
Reviewed-by: Robert Liao <robliao@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#872465}
  • Loading branch information
mhochk authored and Chromium LUCI CQ committed Apr 14, 2021
1 parent afd4dca commit ec43580
Show file tree
Hide file tree
Showing 3 changed files with 657 additions and 74 deletions.
26 changes: 25 additions & 1 deletion base/test/fake_iasync_operation_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class FakeIAsyncOperation final
ADD_FAILURE() << "GetResults called on incomplete IAsyncOperation.";
return E_PENDING;
}
if (status_ != AsyncStatus::Completed)
if (status_ != AsyncStatus::Completed && !results_includes_failure_)
return E_UNEXPECTED;
return base::win::internal::CopyTo(results_, results);
}
Expand All @@ -85,6 +85,13 @@ class FakeIAsyncOperation final
return S_OK;
}
IFACEMETHODIMP get_ErrorCode(HRESULT* error_code) final {
EXPECT_FALSE(results_includes_failure_)
<< "get_ErrorCode called on IAsyncOperation whose failure is expected "
"to be expressed through the results instead. If a case arises "
"where this is actually intended this check can be removed, but is "
"most likely an indication of incorrectly assuming the error_code "
"can be used in place of get_Status or GetResults for this kind of "
"IAsyncOperation.";
*error_code = error_code_;
return S_OK;
}
Expand All @@ -108,6 +115,22 @@ class FakeIAsyncOperation final
InvokeCompletedHandler();
}

// Completes the operation with |results|, but with an AsyncStatus of Error.
// This is an uncommon combination only appropriate when |results| includes
// the failure information.
//
// The GetResults API will be set to return |results| and the get_ErrorCode
// API will be set to return S_OK, but the get_Status API will be set to
// return AsyncStatus::Error. Then the CompletedHandler (if defined) will be
// run.
void CompleteWithErrorResult(internal::AsyncOperationStorage<T> results) {
error_code_ = S_OK;
results_ = std::move(results);
results_includes_failure_ = true;
status_ = AsyncStatus::Error;
InvokeCompletedHandler();
}

// Completes the operation with |results|.
//
// The GetResults API will be set to return |results|, the remainder of the
Expand Down Expand Up @@ -136,6 +159,7 @@ class FakeIAsyncOperation final
handler_;
bool is_complete_ = false;
internal::AsyncOperationOptionalStorage<T> results_;
bool results_includes_failure_ = false;
AsyncStatus status_ = AsyncStatus::Started;
};

Expand Down
Loading

0 comments on commit ec43580

Please sign in to comment.