OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ |
6 #define MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "mojo/edk/embedder/platform_shared_buffer.h" |
12 #include "mojo/edk/system/awakable_list.h" | 13 #include "mojo/edk/system/awakable_list.h" |
| 14 #include "mojo/edk/system/data_pipe.h" |
13 #include "mojo/edk/system/dispatcher.h" | 15 #include "mojo/edk/system/dispatcher.h" |
14 #include "mojo/edk/system/raw_channel.h" | 16 #include "mojo/edk/system/raw_channel.h" |
15 #include "mojo/edk/system/system_impl_export.h" | 17 #include "mojo/edk/system/system_impl_export.h" |
16 #include "mojo/public/cpp/system/macros.h" | 18 #include "mojo/public/cpp/system/macros.h" |
17 | 19 |
18 namespace mojo { | 20 namespace mojo { |
19 namespace edk { | 21 namespace edk { |
20 | 22 |
21 // This is the |Dispatcher| implementation for the producer handle for data | 23 // This is the |Dispatcher| implementation for the producer handle for data |
22 // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is | 24 // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is |
23 // thread-safe. | 25 // thread-safe. |
24 class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final | 26 class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final |
25 : public Dispatcher, public RawChannel::Delegate { | 27 : public Dispatcher, public RawChannel::Delegate { |
26 public: | 28 public: |
27 static scoped_refptr<DataPipeProducerDispatcher> Create( | 29 static scoped_refptr<DataPipeProducerDispatcher> Create( |
28 const MojoCreateDataPipeOptions& options) { | 30 const MojoCreateDataPipeOptions& options) { |
29 return make_scoped_refptr(new DataPipeProducerDispatcher(options)); | 31 return make_scoped_refptr(new DataPipeProducerDispatcher(options)); |
30 } | 32 } |
31 | 33 |
32 // Must be called before any other methods. | 34 // Must be called before any other methods. |
33 void Init(ScopedPlatformHandle message_pipe, | 35 void Init(ScopedPlatformHandle channel_handle, |
34 char* serialized_write_buffer, size_t serialized_write_buffer_size); | 36 scoped_refptr<PlatformSharedBuffer> shared_buffer); |
35 | 37 |
36 // |Dispatcher| public methods: | 38 // |Dispatcher| public methods: |
37 Type GetType() const override; | 39 Type GetType() const override; |
38 | 40 |
39 // The "opposite" of |SerializeAndClose()|. (Typically this is called by | 41 // The "opposite" of |SerializeAndClose()|. (Typically this is called by |
40 // |Dispatcher::Deserialize()|.) | 42 // |Dispatcher::Deserialize()|.) |
41 static scoped_refptr<DataPipeProducerDispatcher> | 43 static scoped_refptr<DataPipeProducerDispatcher> |
42 Deserialize(const void* source, | 44 Deserialize(const void* source, |
43 size_t size, | 45 size_t size, |
44 PlatformHandleVector* platform_handles); | 46 PlatformHandleVector* platform_handles); |
45 | 47 |
46 private: | 48 private: |
47 DataPipeProducerDispatcher(const MojoCreateDataPipeOptions& options); | 49 explicit DataPipeProducerDispatcher(const MojoCreateDataPipeOptions& options); |
| 50 explicit DataPipeProducerDispatcher(scoped_refptr<DataPipe> data_pipe); |
48 ~DataPipeProducerDispatcher() override; | 51 ~DataPipeProducerDispatcher() override; |
49 | 52 |
| 53 void InitInternal(); |
50 void InitOnIO(); | 54 void InitOnIO(); |
51 void CloseOnIO(); | 55 void CloseOnIO(); |
52 | 56 |
53 // |Dispatcher| protected methods: | 57 // |Dispatcher| protected methods: |
54 void CancelAllAwakablesNoLock() override; | 58 void CancelAllAwakablesNoLock() override; |
55 void CloseImplNoLock() override; | 59 void CloseImplNoLock() override; |
56 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | 60 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() |
57 override; | 61 override; |
58 MojoResult WriteDataImplNoLock(const void* elements, | 62 MojoResult WriteDataImplNoLock(const void* elements, |
59 uint32_t* num_bytes, | 63 uint32_t* num_bytes, |
(...skipping 18 matching lines...) Expand all Loading... |
78 void TransportStarted() override; | 82 void TransportStarted() override; |
79 void TransportEnded() override; | 83 void TransportEnded() override; |
80 bool IsBusyNoLock() const override; | 84 bool IsBusyNoLock() const override; |
81 | 85 |
82 // |RawChannel::Delegate methods: | 86 // |RawChannel::Delegate methods: |
83 void OnReadMessage( | 87 void OnReadMessage( |
84 const MessageInTransit::View& message_view, | 88 const MessageInTransit::View& message_view, |
85 ScopedPlatformHandleVectorPtr platform_handles) override; | 89 ScopedPlatformHandleVectorPtr platform_handles) override; |
86 void OnError(Error error) override; | 90 void OnError(Error error) override; |
87 | 91 |
88 bool InTwoPhaseWrite() const; | 92 bool ProcessCommand(const DataPipeCommandHeader& command, |
89 bool WriteDataIntoMessages(const void* elements, uint32_t num_bytes); | 93 ScopedPlatformHandleVectorPtr platform_handles); |
90 | 94 |
91 // See comment in MessagePipeDispatcher for this method. | 95 scoped_refptr<DataPipe> data_pipe_; |
92 void SerializeInternal(); | |
93 | |
94 MojoCreateDataPipeOptions options_; | |
95 | |
96 // Protected by |lock()|: | |
97 RawChannel* channel_; // This will be null if closed. | |
98 | 96 |
99 AwakableList awakable_list_; | 97 AwakableList awakable_list_; |
100 | 98 |
101 // If DispatcherTransport is created. Must be set before lock() is called to | 99 // If DispatcherTransport is created. Must be set before lock() is called to |
102 // avoid deadlocks with RawChannel calling us. | 100 // avoid deadlocks with RawChannel calling us. |
103 base::Lock started_transport_; | 101 base::Lock started_transport_; |
104 | 102 |
105 bool error_; | 103 bool calling_init_; |
| 104 bool peer_closed_; |
106 | 105 |
107 bool serialized_; | 106 bool in_two_phase_write_; |
108 ScopedPlatformHandle serialized_platform_handle_; | 107 uint32_t two_phase_max_bytes_write_; |
109 std::vector<char> serialized_write_buffer_; | |
110 std::vector<char> two_phase_data_; | |
111 | 108 |
112 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); | 109 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); |
113 }; | 110 }; |
114 | 111 |
115 } // namespace edk | 112 } // namespace edk |
116 } // namespace mojo | 113 } // namespace mojo |
117 | 114 |
118 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ | 115 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ |
OLD | NEW |