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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "mojo/edk/system/dispatcher.h" | 9 #include "mojo/edk/system/dispatcher.h" |
10 #include "mojo/edk/system/system_impl_export.h" | 10 #include "mojo/edk/system/system_impl_export.h" |
11 #include "mojo/public/cpp/system/macros.h" | 11 #include "mojo/public/cpp/system/macros.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace system { | 14 namespace system { |
15 | 15 |
16 class DataPipe; | 16 class DataPipe; |
17 | 17 |
18 // This is the |Dispatcher| implementation for the consumer handle for data | 18 // This is the |Dispatcher| implementation for the consumer handle for data |
19 // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is | 19 // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is |
20 // thread-safe. | 20 // thread-safe. |
21 class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final | 21 class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final |
22 : public Dispatcher { | 22 : public Dispatcher { |
23 public: | 23 public: |
24 static scoped_refptr<DataPipeConsumerDispatcher> Create() { | 24 static scoped_refptr<DataPipeConsumerDispatcher> Create() { |
25 return make_scoped_refptr(new DataPipeConsumerDispatcher()); | 25 return make_scoped_refptr(new DataPipeConsumerDispatcher()); |
26 } | 26 } |
27 | 27 |
28 // Must be called before any other methods. | 28 // Must be called before any other methods. |
29 void Init(scoped_refptr<DataPipe> data_pipe); | 29 void Init(scoped_refptr<DataPipe> data_pipe) MOJO_NOT_THREAD_SAFE; |
30 | 30 |
31 // |Dispatcher| public methods: | 31 // |Dispatcher| public methods: |
32 Type GetType() const override; | 32 Type GetType() const override; |
33 | 33 |
34 // The "opposite" of |SerializeAndClose()|. (Typically this is called by | 34 // The "opposite" of |SerializeAndClose()|. (Typically this is called by |
35 // |Dispatcher::Deserialize()|.) | 35 // |Dispatcher::Deserialize()|.) |
36 static scoped_refptr<DataPipeConsumerDispatcher> | 36 static scoped_refptr<DataPipeConsumerDispatcher> |
37 Deserialize(Channel* channel, const void* source, size_t size); | 37 Deserialize(Channel* channel, const void* source, size_t size); |
38 | 38 |
39 // Get access to the |DataPipe| for testing. | 39 // Get access to the |DataPipe| for testing. |
40 DataPipe* GetDataPipeForTest() { return data_pipe_.get(); } | 40 DataPipe* GetDataPipeForTest(); |
41 | 41 |
42 private: | 42 private: |
43 DataPipeConsumerDispatcher(); | 43 DataPipeConsumerDispatcher(); |
44 ~DataPipeConsumerDispatcher() override; | 44 ~DataPipeConsumerDispatcher() override; |
45 | 45 |
46 // |Dispatcher| protected methods: | 46 // |Dispatcher| protected methods: |
47 void CancelAllAwakablesNoLock() override; | 47 void CancelAllAwakablesNoLock() override; |
48 void CloseImplNoLock() override; | 48 void CloseImplNoLock() override; |
49 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() | 49 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() |
50 override; | 50 override; |
51 MojoResult ReadDataImplNoLock(UserPointer<void> elements, | 51 MojoResult ReadDataImplNoLock(UserPointer<void> elements, |
52 UserPointer<uint32_t> num_bytes, | 52 UserPointer<uint32_t> num_bytes, |
53 MojoReadDataFlags flags) override; | 53 MojoReadDataFlags flags) override; |
54 MojoResult BeginReadDataImplNoLock(UserPointer<const void*> buffer, | 54 MojoResult BeginReadDataImplNoLock(UserPointer<const void*> buffer, |
55 UserPointer<uint32_t> buffer_num_bytes, | 55 UserPointer<uint32_t> buffer_num_bytes, |
56 MojoReadDataFlags flags) override; | 56 MojoReadDataFlags flags) override; |
57 MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read) override; | 57 MojoResult EndReadDataImplNoLock(uint32_t num_bytes_read) override; |
58 HandleSignalsState GetHandleSignalsStateImplNoLock() const override; | 58 HandleSignalsState GetHandleSignalsStateImplNoLock() const override; |
59 MojoResult AddAwakableImplNoLock(Awakable* awakable, | 59 MojoResult AddAwakableImplNoLock(Awakable* awakable, |
60 MojoHandleSignals signals, | 60 MojoHandleSignals signals, |
61 uint32_t context, | 61 uint32_t context, |
62 HandleSignalsState* signals_state) override; | 62 HandleSignalsState* signals_state) override; |
63 void RemoveAwakableImplNoLock(Awakable* awakable, | 63 void RemoveAwakableImplNoLock(Awakable* awakable, |
64 HandleSignalsState* signals_state) override; | 64 HandleSignalsState* signals_state) override; |
65 void StartSerializeImplNoLock(Channel* channel, | 65 void StartSerializeImplNoLock(Channel* channel, |
66 size_t* max_size, | 66 size_t* max_size, |
67 size_t* max_platform_handles) override; | 67 size_t* max_platform_handles) override |
| 68 MOJO_NOT_THREAD_SAFE; |
68 bool EndSerializeAndCloseImplNoLock( | 69 bool EndSerializeAndCloseImplNoLock( |
69 Channel* channel, | 70 Channel* channel, |
70 void* destination, | 71 void* destination, |
71 size_t* actual_size, | 72 size_t* actual_size, |
72 embedder::PlatformHandleVector* platform_handles) override; | 73 embedder::PlatformHandleVector* platform_handles) override |
| 74 MOJO_NOT_THREAD_SAFE; |
73 bool IsBusyNoLock() const override; | 75 bool IsBusyNoLock() const override; |
74 | 76 |
75 // Protected by |lock()|: | 77 // This will be null if closed. |
76 scoped_refptr<DataPipe> data_pipe_; // This will be null if closed. | 78 scoped_refptr<DataPipe> data_pipe_ MOJO_GUARDED_BY(mutex()); |
77 | 79 |
78 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); | 80 MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); |
79 }; | 81 }; |
80 | 82 |
81 } // namespace system | 83 } // namespace system |
82 } // namespace mojo | 84 } // namespace mojo |
83 | 85 |
84 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ | 86 #endif // MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ |
OLD | NEW |