blob: 4ec059bf3639b9c75178f2300d0796b433e1d2ed [file] [log] [blame]
Ken Rockot4c5bd802018-07-12 01:37:111// 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"
Takuto Ikutaaa3b796c2019-02-06 02:54:5615#include "mojo/public/interfaces/bindings/native_struct.mojom-forward.h"
Ken Rockot4c5bd802018-07-12 01:37:1116
17namespace IPC {
18
19class 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
Kent Tamuraf4476ef2019-08-27 23:43:5943 base::Optional<std::vector<mojo::native::SerializedHandlePtr>> TakeHandles();
Ken Rockot4c5bd802018-07-12 01:37:1144
45 private:
46 mojo_base::BigBufferView buffer_view_;
47 base::Optional<std::vector<mojo::native::SerializedHandlePtr>> handles_;
48
49 DISALLOW_COPY_AND_ASSIGN(MessageView);
50};
51
52} // namespace IPC
53
54#endif // IPC_MESSAGE_VIEW_H_