Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: mojo/edk/system/data_pipe_producer_dispatcher.h

Issue 1526923006: [mojo] Implement data pipe using a shared buffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 message_pipe,
34 char* serialized_write_buffer, size_t serialized_write_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<DataPipeProducerDispatcher> 49 static scoped_refptr<DataPipeProducerDispatcher>
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 DataPipeProducerDispatcher(const MojoCreateDataPipeOptions& options); 55 explicit DataPipeProducerDispatcher(const MojoCreateDataPipeOptions& options);
48 ~DataPipeProducerDispatcher() override; 56 ~DataPipeProducerDispatcher() 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
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 bool InTwoPhaseWrite() const; 96 bool ProcessCommand(const DataPipeCommandHeader& command,
89 bool WriteDataIntoMessages(const void* elements, uint32_t num_bytes); 97 ScopedPlatformHandleVectorPtr platform_handles);
90 98
91 // See comment in MessagePipeDispatcher for this method. 99 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 100
99 AwakableList awakable_list_; 101 AwakableList awakable_list_;
100 102
101 // 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
102 // avoid deadlocks with RawChannel calling us. 104 // avoid deadlocks with RawChannel calling us.
103 base::Lock started_transport_; 105 base::Lock started_transport_;
104 106
105 bool error_; 107 bool calling_init_;
108 bool peer_closed_;
106 109
107 bool serialized_; 110 bool in_two_phase_write_;
108 ScopedPlatformHandle serialized_platform_handle_; 111 uint32_t two_phase_max_bytes_write_;
109 std::vector<char> serialized_write_buffer_;
110 std::vector<char> two_phase_data_;
111 112
112 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); 113 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher);
113 }; 114 };
114 115
115 } // namespace edk 116 } // namespace edk
116 } // namespace mojo 117 } // namespace mojo
117 118
118 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ 119 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698