1 // Copyright 2018 The Chromium Authors 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 <optional> 9 #include <vector> 10 11 #include "base/component_export.h" 12 #include "base/containers/span.h" 13 #include "base/memory/raw_span.h" 14 #include "ipc/ipc_message.h" 15 #include "mojo/public/interfaces/bindings/native_struct.mojom-forward.h" 16 17 namespace IPC { 18 COMPONENT_EXPORT(IPC_MOJOM)19class COMPONENT_EXPORT(IPC_MOJOM) MessageView { 20 public: 21 MessageView(); 22 MessageView( 23 base::span<const uint8_t> bytes, 24 std::optional<std::vector<mojo::native::SerializedHandlePtr>> handles); 25 MessageView(MessageView&&); 26 27 MessageView(const MessageView&) = delete; 28 MessageView& operator=(const MessageView&) = delete; 29 30 ~MessageView(); 31 32 MessageView& operator=(MessageView&&); 33 34 base::span<const uint8_t> bytes() const { return bytes_; } 35 std::optional<std::vector<mojo::native::SerializedHandlePtr>> TakeHandles(); 36 37 private: 38 base::raw_span<const uint8_t> bytes_; 39 std::optional<std::vector<mojo::native::SerializedHandlePtr>> handles_; 40 }; 41 42 } // namespace IPC 43 44 #endif // IPC_MESSAGE_VIEW_H_ 45