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

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

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanup Created 5 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_
6 #define MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "mojo/edk/system/awakable_list.h"
10 #include "mojo/edk/system/dispatcher.h"
11 #include "mojo/edk/system/raw_channel.h"
12 #include "mojo/edk/system/system_impl_export.h"
13 #include "mojo/public/cpp/system/macros.h"
14
15 namespace mojo {
16 namespace edk {
17
18 // This is the |Dispatcher| implementation for the producer handle for data
19 // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is
20 // thread-safe.
21 class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final
22 : public Dispatcher, public RawChannel::Delegate {
23 public:
24 static scoped_refptr<DataPipeProducerDispatcher> Create(
25 const MojoCreateDataPipeOptions& options) {
26 return make_scoped_refptr(new DataPipeProducerDispatcher(options));
27 }
28
29 // Must be called before any other methods.
30 void Init(ScopedPlatformHandle message_pipe);
31
32 // |Dispatcher| public methods:
33 Type GetType() const override;
34
35 // The "opposite" of |SerializeAndClose()|. (Typically this is called by
36 // |Dispatcher::Deserialize()|.)
37 static scoped_refptr<DataPipeProducerDispatcher>
38 Deserialize(const void* source,
39 size_t size,
40 PlatformHandleVector* platform_handles);
41
42 private:
43 DataPipeProducerDispatcher(const MojoCreateDataPipeOptions& options);
44 ~DataPipeProducerDispatcher() override;
45
46 void InitOnIO();
47 void CloseOnIO();
48
49 // |Dispatcher| protected methods:
50 void CancelAllAwakablesNoLock() override;
51 void CloseImplNoLock() override;
52 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock()
53 override;
54 MojoResult WriteDataImplNoLock(const void* elements,
55 uint32_t* num_bytes,
56 MojoWriteDataFlags flags) override;
57 MojoResult BeginWriteDataImplNoLock(void** buffer,
58 uint32_t* buffer_num_bytes,
59 MojoWriteDataFlags flags) override;
60 MojoResult EndWriteDataImplNoLock(uint32_t num_bytes_written) override;
61 HandleSignalsState GetHandleSignalsStateImplNoLock() const override;
62 MojoResult AddAwakableImplNoLock(Awakable* awakable,
63 MojoHandleSignals signals,
64 uint32_t context,
65 HandleSignalsState* signals_state) override;
66 void RemoveAwakableImplNoLock(Awakable* awakable,
67 HandleSignalsState* signals_state) override;
68 void StartSerializeImplNoLock(size_t* max_size,
69 size_t* max_platform_handles) override;
70 bool EndSerializeAndCloseImplNoLock(
71 void* destination,
72 size_t* actual_size,
73 PlatformHandleVector* platform_handles) override;
74 void TransportStarted() override;
75 void TransportEnded() override;
76 bool IsBusyNoLock() const override;
77
78 // |RawChannel::Delegate methods:
79 void OnReadMessage(
80 const MessageInTransit::View& message_view,
81 ScopedPlatformHandleVectorPtr platform_handles) override;
82 void OnError(Error error) override;
83
84 bool InTwoPhaseWrite() const;
85 bool WriteDataIntoMessages(const void* elements, uint32_t num_bytes);
86
87 MojoCreateDataPipeOptions options_;
88
89 // Protected by |lock()|:
90 RawChannel* channel_; // This will be null if closed.
91
92 AwakableList awakable_list_;
93
94 // If DispatcherTransport is created. Must be set before lock() is called to
95 // avoid deadlocks with RawChannel calling us.
96 base::Lock started_transport_;
97
98 bool error_;
99
100 ScopedPlatformHandle serialized_platform_handle_;
101
102 std::vector<char> two_phase_data_;
103
104 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher);
105 };
106
107 } // namespace edk
108 } // namespace mojo
109
110 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698