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

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

Issue 1412283002: Convert mojo::system::Dispatcher to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: no change 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_SHARED_BUFFER_DISPATCHER_H_ 5 #ifndef MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
6 #define MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_ 6 #define MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
7 7
8 #include "mojo/edk/embedder/platform_shared_buffer.h" 8 #include "mojo/edk/embedder/platform_shared_buffer.h"
9 #include "mojo/edk/system/memory.h" 9 #include "mojo/edk/system/memory.h"
10 #include "mojo/edk/system/ref_ptr.h"
10 #include "mojo/edk/system/simple_dispatcher.h" 11 #include "mojo/edk/system/simple_dispatcher.h"
11 #include "mojo/public/cpp/system/macros.h" 12 #include "mojo/public/cpp/system/macros.h"
12 13
13 namespace mojo { 14 namespace mojo {
14 15
15 namespace embedder { 16 namespace embedder {
16 class PlatformSupport; 17 class PlatformSupport;
17 } 18 }
18 19
19 namespace system { 20 namespace system {
(...skipping 11 matching lines...) Expand all
31 // Validates and/or sets default options for |MojoCreateSharedBufferOptions|. 32 // Validates and/or sets default options for |MojoCreateSharedBufferOptions|.
32 // If non-null, |in_options| must point to a struct of at least 33 // If non-null, |in_options| must point to a struct of at least
33 // |in_options->struct_size| bytes. |out_options| must point to a (current) 34 // |in_options->struct_size| bytes. |out_options| must point to a (current)
34 // |MojoCreateSharedBufferOptions| and will be entirely overwritten on success 35 // |MojoCreateSharedBufferOptions| and will be entirely overwritten on success
35 // (it may be partly overwritten on failure). 36 // (it may be partly overwritten on failure).
36 static MojoResult ValidateCreateOptions( 37 static MojoResult ValidateCreateOptions(
37 UserPointer<const MojoCreateSharedBufferOptions> in_options, 38 UserPointer<const MojoCreateSharedBufferOptions> in_options,
38 MojoCreateSharedBufferOptions* out_options); 39 MojoCreateSharedBufferOptions* out_options);
39 40
40 // Static factory method: |validated_options| must be validated (obviously). 41 // Static factory method: |validated_options| must be validated (obviously).
41 // On failure, |*result| will be left as-is. 42 // Returns null on error; |*result| will be set to an appropriate result
42 // TODO(vtl): This should probably be made to return a scoped_refptr and have 43 // code).
43 // a MojoResult out parameter instead. 44 static RefPtr<SharedBufferDispatcher> Create(
44 static MojoResult Create(
45 embedder::PlatformSupport* platform_support, 45 embedder::PlatformSupport* platform_support,
46 const MojoCreateSharedBufferOptions& validated_options, 46 const MojoCreateSharedBufferOptions& validated_options,
47 uint64_t num_bytes, 47 uint64_t num_bytes,
48 scoped_refptr<SharedBufferDispatcher>* result); 48 MojoResult* result);
49 49
50 // |Dispatcher| public methods: 50 // |Dispatcher| public methods:
51 Type GetType() const override; 51 Type GetType() const override;
52 52
53 // The "opposite" of |SerializeAndClose()|. (Typically this is called by 53 // The "opposite" of |SerializeAndClose()|. (Typically this is called by
54 // |Dispatcher::Deserialize()|.) 54 // |Dispatcher::Deserialize()|.)
55 static scoped_refptr<SharedBufferDispatcher> Deserialize( 55 static RefPtr<SharedBufferDispatcher> Deserialize(
56 Channel* channel, 56 Channel* channel,
57 const void* source, 57 const void* source,
58 size_t size, 58 size_t size,
59 embedder::PlatformHandleVector* platform_handles); 59 embedder::PlatformHandleVector* platform_handles);
60 60
61 private: 61 private:
62 static scoped_refptr<SharedBufferDispatcher> CreateInternal( 62 static RefPtr<SharedBufferDispatcher> CreateInternal(
63 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer) { 63 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer) {
64 return make_scoped_refptr(new SharedBufferDispatcher(shared_buffer.Pass())); 64 return AdoptRef(new SharedBufferDispatcher(shared_buffer.Pass()));
65 } 65 }
66 66
67 explicit SharedBufferDispatcher( 67 explicit SharedBufferDispatcher(
68 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer); 68 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer);
69 ~SharedBufferDispatcher() override; 69 ~SharedBufferDispatcher() override;
70 70
71 // Validates and/or sets default options for 71 // Validates and/or sets default options for
72 // |MojoDuplicateBufferHandleOptions|. If non-null, |in_options| must point to 72 // |MojoDuplicateBufferHandleOptions|. If non-null, |in_options| must point to
73 // a struct of at least |in_options->struct_size| bytes. |out_options| must 73 // a struct of at least |in_options->struct_size| bytes. |out_options| must
74 // point to a (current) |MojoDuplicateBufferHandleOptions| and will be 74 // point to a (current) |MojoDuplicateBufferHandleOptions| and will be
75 // entirely overwritten on success (it may be partly overwritten on failure). 75 // entirely overwritten on success (it may be partly overwritten on failure).
76 static MojoResult ValidateDuplicateOptions( 76 static MojoResult ValidateDuplicateOptions(
77 UserPointer<const MojoDuplicateBufferHandleOptions> in_options, 77 UserPointer<const MojoDuplicateBufferHandleOptions> in_options,
78 MojoDuplicateBufferHandleOptions* out_options); 78 MojoDuplicateBufferHandleOptions* out_options);
79 79
80 // |Dispatcher| protected methods: 80 // |Dispatcher| protected methods:
81 void CloseImplNoLock() override; 81 void CloseImplNoLock() override;
82 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() 82 RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() override;
83 override;
84 MojoResult DuplicateBufferHandleImplNoLock( 83 MojoResult DuplicateBufferHandleImplNoLock(
85 UserPointer<const MojoDuplicateBufferHandleOptions> options, 84 UserPointer<const MojoDuplicateBufferHandleOptions> options,
86 scoped_refptr<Dispatcher>* new_dispatcher) override; 85 RefPtr<Dispatcher>* new_dispatcher) override;
87 MojoResult MapBufferImplNoLock( 86 MojoResult MapBufferImplNoLock(
88 uint64_t offset, 87 uint64_t offset,
89 uint64_t num_bytes, 88 uint64_t num_bytes,
90 MojoMapBufferFlags flags, 89 MojoMapBufferFlags flags,
91 std::unique_ptr<embedder::PlatformSharedBufferMapping>* mapping) override; 90 std::unique_ptr<embedder::PlatformSharedBufferMapping>* mapping) override;
92 void StartSerializeImplNoLock(Channel* channel, 91 void StartSerializeImplNoLock(Channel* channel,
93 size_t* max_size, 92 size_t* max_size,
94 size_t* max_platform_handles) override 93 size_t* max_platform_handles) override
95 MOJO_NOT_THREAD_SAFE; 94 MOJO_NOT_THREAD_SAFE;
96 bool EndSerializeAndCloseImplNoLock( 95 bool EndSerializeAndCloseImplNoLock(
97 Channel* channel, 96 Channel* channel,
98 void* destination, 97 void* destination,
99 size_t* actual_size, 98 size_t* actual_size,
100 embedder::PlatformHandleVector* platform_handles) override 99 embedder::PlatformHandleVector* platform_handles) override
101 MOJO_NOT_THREAD_SAFE; 100 MOJO_NOT_THREAD_SAFE;
102 101
103 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer_ 102 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer_
104 MOJO_GUARDED_BY(mutex()); 103 MOJO_GUARDED_BY(mutex());
105 104
106 MOJO_DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher); 105 MOJO_DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher);
107 }; 106 };
108 107
109 } // namespace system 108 } // namespace system
110 } // namespace mojo 109 } // namespace mojo
111 110
112 #endif // MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_ 111 #endif // MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/remote_message_pipe_unittest.cc ('k') | mojo/edk/system/shared_buffer_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698