• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #ifndef IPC_MESSAGE_VIEW_H_
6 #define IPC_MESSAGE_VIEW_H_
7 
8 #include <vector>
9 
10 #include "base/component_export.h"
11 #include "base/containers/span.h"
12 #include "base/macros.h"
13 #include "ipc/ipc_message.h"
14 #include "mojo/public/cpp/base/big_buffer.h"
15 #include "mojo/public/interfaces/bindings/native_struct.mojom.h"
16 
17 namespace IPC {
18 
COMPONENT_EXPORT(IPC_MOJOM)19 class COMPONENT_EXPORT(IPC_MOJOM) MessageView {
20  public:
21   MessageView();
22   MessageView(
23       const Message& message,
24       base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles);
25   MessageView(
26       mojo_base::BigBufferView buffer_view,
27       base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles);
28   MessageView(MessageView&&);
29   ~MessageView();
30 
31   MessageView& operator=(MessageView&&);
32 
33   const char* data() const {
34     return reinterpret_cast<const char*>(buffer_view_.data().data());
35   }
36 
37   uint32_t size() const {
38     return static_cast<uint32_t>(buffer_view_.data().size());
39   }
40 
41   mojo_base::BigBufferView TakeBufferView() { return std::move(buffer_view_); }
42 
43   base::Optional<std::vector<mojo::native::SerializedHandlePtr>> TakeHandles() {
44     return std::move(handles_);
45   }
46 
47  private:
48   mojo_base::BigBufferView buffer_view_;
49   base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles_;
50 
51   DISALLOW_COPY_AND_ASSIGN(MessageView);
52 };
53 
54 }  // namespace IPC
55 
56 #endif  // IPC_MESSAGE_VIEW_H_
57