Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/ipc/copy_output_request_struct_traits.h" | 5 #include "cc/ipc/copy_output_request_struct_traits.h" |
| 6 | 6 |
| 7 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 8 | |
| 9 namespace { | |
| 10 | |
| 11 // When we're sending a CopyOutputRequest, we keep the result_callback_ in a | |
| 12 // CopyOutputResultSenderImpl and send a CopyOutputResultSenderPtr to the other | |
| 13 // process. When SendResult is called, we run the stored result_callback_. | |
| 14 class CopyOutputResultSenderImpl : public cc::mojom::CopyOutputResultSender { | |
| 15 public: | |
| 16 CopyOutputResultSenderImpl( | |
| 17 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) | |
| 18 : result_callback_(result_callback) {} | |
| 19 | |
| 20 // mojom::TextureMailboxReleaser implementation: | |
| 21 void SendResult(std::unique_ptr<cc::CopyOutputResult> result) override { | |
| 22 result_callback_.Run(std::move(result)); | |
|
danakj
2017/02/15 17:19:57
Can you also make sure this is called only once an
Saman Sami
2017/02/15 17:36:50
Will do. It's hard to test though because I have n
danakj
2017/02/15 17:41:59
Can you instantiate the CopyOutputResultSenderPtr
Saman Sami
2017/02/15 17:51:42
Yeah I think you're actually right.
| |
| 23 } | |
| 24 | |
| 25 private: | |
| 26 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback_; | |
| 27 }; | |
| 28 | |
| 29 void SendResult(cc::mojom::CopyOutputResultSenderPtr ptr, | |
| 30 std::unique_ptr<cc::CopyOutputResult> result) { | |
| 31 ptr->SendResult(std::move(result)); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 7 namespace mojo { | 36 namespace mojo { |
| 8 | 37 |
| 9 // static | 38 // static |
| 39 cc::mojom::CopyOutputResultSenderPtr | |
| 40 StructTraits<cc::mojom::CopyOutputRequestDataView, | |
| 41 std::unique_ptr<cc::CopyOutputRequest>>:: | |
| 42 result_sender(const std::unique_ptr<cc::CopyOutputRequest>& request) { | |
| 43 cc::mojom::CopyOutputResultSenderPtr result_sender; | |
| 44 auto impl = base::MakeUnique<CopyOutputResultSenderImpl>( | |
| 45 std::move(request->result_callback_)); | |
| 46 MakeStrongBinding(std::move(impl), MakeRequest(&result_sender)); | |
| 47 return result_sender; | |
| 48 } | |
| 49 | |
| 50 // static | |
| 10 bool StructTraits<cc::mojom::CopyOutputRequestDataView, | 51 bool StructTraits<cc::mojom::CopyOutputRequestDataView, |
| 11 std::unique_ptr<cc::CopyOutputRequest>>:: | 52 std::unique_ptr<cc::CopyOutputRequest>>:: |
| 12 Read(cc::mojom::CopyOutputRequestDataView data, | 53 Read(cc::mojom::CopyOutputRequestDataView data, |
| 13 std::unique_ptr<cc::CopyOutputRequest>* out_p) { | 54 std::unique_ptr<cc::CopyOutputRequest>* out_p) { |
| 14 auto request = cc::CopyOutputRequest::CreateEmptyRequest(); | 55 auto request = cc::CopyOutputRequest::CreateEmptyRequest(); |
| 15 | 56 |
| 16 request->force_bitmap_result_ = data.force_bitmap_result(); | 57 request->force_bitmap_result_ = data.force_bitmap_result(); |
| 17 | 58 |
| 18 if (!data.ReadSource(&request->source_)) | 59 if (!data.ReadSource(&request->source_)) |
| 19 return false; | 60 return false; |
| 20 | 61 |
| 21 if (!data.ReadArea(&request->area_)) | 62 if (!data.ReadArea(&request->area_)) |
| 22 return false; | 63 return false; |
| 23 | 64 |
| 24 if (!data.ReadTextureMailbox(&request->texture_mailbox_)) | 65 if (!data.ReadTextureMailbox(&request->texture_mailbox_)) |
| 25 return false; | 66 return false; |
| 26 | 67 |
| 68 auto result_sender = | |
| 69 data.TakeResultSender<cc::mojom::CopyOutputResultSenderPtr>(); | |
| 70 request->result_callback_ = | |
| 71 base::Bind(SendResult, base::Passed(&result_sender)); | |
| 72 | |
| 27 *out_p = std::move(request); | 73 *out_p = std::move(request); |
| 28 | 74 |
| 29 return true; | 75 return true; |
| 30 } | 76 } |
| 31 | 77 |
| 32 } // namespace mojo | 78 } // namespace mojo |
| OLD | NEW |