1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/chrome_cleaner/engines/target/sandbox_request_helper.h"
6 
7 #include <utility>
8 
9 namespace chrome_cleaner {
10 
11 // static
Success()12 MojoCallStatus MojoCallStatus::Success() {
13   return MojoCallStatus{MOJO_CALL_MADE};
14 }
15 
16 // static
Failure(SandboxErrorCode error_code)17 MojoCallStatus MojoCallStatus::Failure(SandboxErrorCode error_code) {
18   return MojoCallStatus{MOJO_CALL_ERROR, error_code};
19 }
20 
21 namespace internal {
22 
SendAsyncMojoRequest(base::OnceCallback<MojoCallStatus ()> request,base::WaitableEvent * async_call_done_event,MojoCallStatus * status_out)23 void SendAsyncMojoRequest(base::OnceCallback<MojoCallStatus()> request,
24                           base::WaitableEvent* async_call_done_event,
25                           MojoCallStatus* status_out) {
26   *status_out = std::move(request).Run();
27 
28   // If the async Mojo call was made successfully, the Mojo response callback
29   // will signal the event when the response is received. Otherwise signal it
30   // now because the Mojo response callback will never be invoked.
31   if (status_out->state != MojoCallStatus::MOJO_CALL_MADE)
32     async_call_done_event->Signal();
33 }
34 
35 }  // namespace internal
36 
37 }  // namespace chrome_cleaner
38