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_CONSUMER_DISPATCHER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ |
6 #define MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ | 6 #define MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_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 consumer handle for data | 23 // This is the |Dispatcher| implementation for the consumer 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 DataPipeConsumerDispatcher final | 26 class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final |
25 : public Dispatcher, public RawChannel::Delegate { | 27 : public Dispatcher, public RawChannel::Delegate { |
26 public: | 28 public: |
27 static scoped_refptr<DataPipeConsumerDispatcher> Create( | 29 static scoped_refptr<DataPipeConsumerDispatcher> Create( |
28 const MojoCreateDataPipeOptions& options) { | 30 const MojoCreateDataPipeOptions& options) { |
29 return make_scoped_refptr(new DataPipeConsumerDispatcher(options)); | 31 return make_scoped_refptr(new DataPipeConsumerDispatcher(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 message_pipe, |
34 char* serialized_read_buffer, size_t serialized_read_buffer_size); | 36 char* serialized_write_buffer, |
| 37 uint32_t serialized_write_buffer_size, |
| 38 char* serialized_read_buffer, |
| 39 uint32_t serialized_read_buffer_size, |
| 40 ScopedPlatformHandle shared_buffer_handle, |
| 41 uint32_t ring_buffer_start, |
| 42 uint32_t ring_buffer_size); |
35 | 43 |
36 // |Dispatcher| public methods: | 44 // |Dispatcher| public methods: |
37 Type GetType() const override; | 45 Type GetType() const override; |
38 | 46 |
39 // The "opposite" of |SerializeAndClose()|. (Typically this is called by | 47 // The "opposite" of |SerializeAndClose()|. (Typically this is called by |
40 // |Dispatcher::Deserialize()|.) | 48 // |Dispatcher::Deserialize()|.) |
41 static scoped_refptr<DataPipeConsumerDispatcher> | 49 static scoped_refptr<DataPipeConsumerDispatcher> |
42 Deserialize(const void* source, | 50 Deserialize(const void* source, |
43 size_t size, | 51 size_t size, |
44 PlatformHandleVector* platform_handles); | 52 PlatformHandleVector* platform_handles); |
45 | 53 |
46 private: | 54 private: |
47 DataPipeConsumerDispatcher(const MojoCreateDataPipeOptions& options); | 55 explicit DataPipeConsumerDispatcher(const MojoCreateDataPipeOptions& options); |
48 ~DataPipeConsumerDispatcher() override; | 56 ~DataPipeConsumerDispatcher() override; |
49 | 57 |
50 void InitOnIO(); | 58 void InitOnIO(); |
51 void CloseOnIO(); | 59 void CloseOnIO(); |
52 | 60 |
53 // |Dispatcher| protected methods: | 61 // |Dispatcher| protected methods: |
54 void CancelAllAwakablesNoLock() override; | 62 void CancelAllAwakablesNoLock() override; |
55 void CloseImplNoLock() override; | 63 void CloseImplNoLock() override; |
56 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | 64 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() |
57 override; | 65 override; |
(...skipping 20 matching lines...) Expand all Loading... |
78 void TransportStarted() override; | 86 void TransportStarted() override; |
79 void TransportEnded() override; | 87 void TransportEnded() override; |
80 bool IsBusyNoLock() const override; | 88 bool IsBusyNoLock() const override; |
81 | 89 |
82 // |RawChannel::Delegate methods: | 90 // |RawChannel::Delegate methods: |
83 void OnReadMessage( | 91 void OnReadMessage( |
84 const MessageInTransit::View& message_view, | 92 const MessageInTransit::View& message_view, |
85 ScopedPlatformHandleVectorPtr platform_handles) override; | 93 ScopedPlatformHandleVectorPtr platform_handles) override; |
86 void OnError(Error error) override; | 94 void OnError(Error error) override; |
87 | 95 |
88 // See comment in MessagePipeDispatcher for this method. | 96 bool ProcessCommand(const DataPipeCommandHeader& command, |
89 void SerializeInternal(); | 97 ScopedPlatformHandleVectorPtr platform_handles); |
90 | 98 |
91 MojoCreateDataPipeOptions options_; | 99 scoped_refptr<DataPipe> data_pipe_; |
92 | 100 |
93 // Protected by |lock()|: | |
94 RawChannel* channel_; // This will be null if closed. | |
95 | |
96 // Queue of incoming messages. | |
97 std::vector<char> data_; | |
98 AwakableList awakable_list_; | 101 AwakableList awakable_list_; |
99 | 102 |
100 // If DispatcherTransport is created. Must be set before lock() is called to | 103 // If DispatcherTransport is created. Must be set before lock() is called to |
101 // avoid deadlocks with RawChannel calling us. | 104 // avoid deadlocks with RawChannel calling us. |
102 base::Lock started_transport_; | 105 base::Lock started_transport_; |
103 | 106 |
104 bool calling_init_; | 107 bool calling_init_; |
| 108 bool peer_closed_; |
105 | 109 |
106 bool in_two_phase_read_; | 110 bool in_two_phase_read_; |
107 uint32_t two_phase_max_bytes_read_; | 111 uint32_t two_phase_max_bytes_read_; |
108 // If we get data from the channel while we're in two-phase read, we can't | |
109 // resize data_ since it's being used. So instead we store it temporarly. | |
110 std::vector<char> data_received_during_two_phase_read_; | |
111 | |
112 bool error_; | |
113 | |
114 bool serialized_; | |
115 std::vector<char> serialized_read_buffer_; | |
116 ScopedPlatformHandle serialized_platform_handle_; | |
117 | 112 |
118 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); | 113 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); |
119 }; | 114 }; |
120 | 115 |
121 } // namespace edk | 116 } // namespace edk |
122 } // namespace mojo | 117 } // namespace mojo |
123 | 118 |
124 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ | 119 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ |
OLD | NEW |