Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1154)

Unified Diff: cc/ipc/copy_output_request_struct_traits.cc

Issue 2700533002: CopyOutputRequest must have a working result_callback_ when received over mojo (Closed)
Patch Set: c Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/ipc/copy_output_request_struct_traits.h ('k') | cc/ipc/struct_traits_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/ipc/copy_output_request_struct_traits.cc
diff --git a/cc/ipc/copy_output_request_struct_traits.cc b/cc/ipc/copy_output_request_struct_traits.cc
index 3985ba41eb744a7c114458b4bc94e1c8b26ce9b8..dc93b7c0467f5b9472d644686cb99df53f416c47 100644
--- a/cc/ipc/copy_output_request_struct_traits.cc
+++ b/cc/ipc/copy_output_request_struct_traits.cc
@@ -4,9 +4,60 @@
#include "cc/ipc/copy_output_request_struct_traits.h"
+#include "base/callback_helpers.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+
+namespace {
+
+// When we're sending a CopyOutputRequest, we keep the result_callback_ in a
+// CopyOutputResultSenderImpl and send a CopyOutputResultSenderPtr to the other
+// process. When SendResult is called, we run the stored result_callback_.
+class CopyOutputResultSenderImpl : public cc::mojom::CopyOutputResultSender {
+ public:
+ CopyOutputResultSenderImpl(
+ cc::CopyOutputRequest::CopyOutputRequestCallback result_callback)
+ : result_callback_(result_callback) {
+ DCHECK(result_callback_);
+ }
+
+ ~CopyOutputResultSenderImpl() override {
+ if (result_callback_)
+ result_callback_.Run(cc::CopyOutputResult::CreateEmptyResult());
+ }
+
+ // mojom::TextureMailboxReleaser implementation:
+ void SendResult(std::unique_ptr<cc::CopyOutputResult> result) override {
+ if (!result_callback_)
+ return;
+ base::ResetAndReturn(&result_callback_).Run(std::move(result));
+ }
+
+ private:
+ cc::CopyOutputRequest::CopyOutputRequestCallback result_callback_;
+};
+
+void SendResult(cc::mojom::CopyOutputResultSenderPtr ptr,
+ std::unique_ptr<cc::CopyOutputResult> result) {
+ ptr->SendResult(std::move(result));
+}
+
+} // namespace
+
namespace mojo {
// static
+cc::mojom::CopyOutputResultSenderPtr
+StructTraits<cc::mojom::CopyOutputRequestDataView,
+ std::unique_ptr<cc::CopyOutputRequest>>::
+ result_sender(const std::unique_ptr<cc::CopyOutputRequest>& request) {
+ cc::mojom::CopyOutputResultSenderPtr result_sender;
+ auto impl = base::MakeUnique<CopyOutputResultSenderImpl>(
+ std::move(request->result_callback_));
+ MakeStrongBinding(std::move(impl), MakeRequest(&result_sender));
+ return result_sender;
+}
+
+// static
bool StructTraits<cc::mojom::CopyOutputRequestDataView,
std::unique_ptr<cc::CopyOutputRequest>>::
Read(cc::mojom::CopyOutputRequestDataView data,
@@ -24,6 +75,11 @@ bool StructTraits<cc::mojom::CopyOutputRequestDataView,
if (!data.ReadTextureMailbox(&request->texture_mailbox_))
return false;
+ auto result_sender =
+ data.TakeResultSender<cc::mojom::CopyOutputResultSenderPtr>();
+ request->result_callback_ =
+ base::Bind(SendResult, base::Passed(&result_sender));
+
*out_p = std::move(request);
return true;
« no previous file with comments | « cc/ipc/copy_output_request_struct_traits.h ('k') | cc/ipc/struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698