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

Side by Side Diff: mojo/system/channel.h

Issue 570773002: Mojo: Add thread assertions to various private Channel methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | mojo/system/channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_SYSTEM_CHANNEL_H_ 5 #ifndef MOJO_SYSTEM_CHANNEL_H_
6 #define MOJO_SYSTEM_CHANNEL_H_ 6 #define MOJO_SYSTEM_CHANNEL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 17 matching lines...) Expand all
28 namespace embedder { 28 namespace embedder {
29 class PlatformSupport; 29 class PlatformSupport;
30 } 30 }
31 31
32 namespace system { 32 namespace system {
33 33
34 // This class is mostly thread-safe. It must be created on an I/O thread. 34 // This class is mostly thread-safe. It must be created on an I/O thread.
35 // |Init()| must be called on that same thread before it becomes thread-safe (in 35 // |Init()| must be called on that same thread before it becomes thread-safe (in
36 // particular, before references are given to any other thread) and |Shutdown()| 36 // particular, before references are given to any other thread) and |Shutdown()|
37 // must be called on that same thread before destruction. Its public methods are 37 // must be called on that same thread before destruction. Its public methods are
38 // otherwise thread-safe. It may be destroyed on any thread, in the sense that 38 // otherwise thread-safe. (Many private methods are restricted to the creation
39 // the last reference to it may be released on any thread, with the proviso that 39 // thread.) It may be destroyed on any thread, in the sense that the last
40 // reference to it may be released on any thread, with the proviso that
40 // |Shutdown()| must have been called first (so the pattern is that a "main" 41 // |Shutdown()| must have been called first (so the pattern is that a "main"
41 // reference is kept on its creation thread and is released after |Shutdown()| 42 // reference is kept on its creation thread and is released after |Shutdown()|
42 // is called, but other threads may have temporarily "dangling" references). 43 // is called, but other threads may have temporarily "dangling" references).
43 // 44 //
44 // Note that |MessagePipe| calls into |Channel| and the former's |lock_| must be 45 // Note that |MessagePipe| calls into |Channel| and the former's |lock_| must be
45 // acquired before the latter's. When |Channel| wants to call into a 46 // acquired before the latter's. When |Channel| wants to call into a
46 // |MessagePipe|, it must obtain a reference to the |MessagePipe| (from 47 // |MessagePipe|, it must obtain a reference to the |MessagePipe| (from
47 // |local_id_to_endpoint_info_map_|) under |Channel::lock_| and then release the 48 // |local_id_to_endpoint_info_map_|) under |Channel::lock_| and then release the
48 // lock. 49 // lock.
49 // 50 //
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 size_t GetSerializedPlatformHandleSize() const; 130 size_t GetSerializedPlatformHandleSize() const;
130 131
131 embedder::PlatformSupport* platform_support() const { 132 embedder::PlatformSupport* platform_support() const {
132 return platform_support_; 133 return platform_support_;
133 } 134 }
134 135
135 private: 136 private:
136 friend class base::RefCountedThreadSafe<Channel>; 137 friend class base::RefCountedThreadSafe<Channel>;
137 virtual ~Channel(); 138 virtual ~Channel();
138 139
139 // |RawChannel::Delegate| implementation: 140 // |RawChannel::Delegate| implementation (only called on the creation thread):
140 virtual void OnReadMessage( 141 virtual void OnReadMessage(
141 const MessageInTransit::View& message_view, 142 const MessageInTransit::View& message_view,
142 embedder::ScopedPlatformHandleVectorPtr platform_handles) OVERRIDE; 143 embedder::ScopedPlatformHandleVectorPtr platform_handles) OVERRIDE;
143 virtual void OnError(Error error) OVERRIDE; 144 virtual void OnError(Error error) OVERRIDE;
144 145
145 // Helpers for |OnReadMessage|: 146 // Helpers for |OnReadMessage| (only called on the creation thread):
146 void OnReadMessageForDownstream( 147 void OnReadMessageForDownstream(
147 const MessageInTransit::View& message_view, 148 const MessageInTransit::View& message_view,
148 embedder::ScopedPlatformHandleVectorPtr platform_handles); 149 embedder::ScopedPlatformHandleVectorPtr platform_handles);
149 void OnReadMessageForChannel( 150 void OnReadMessageForChannel(
150 const MessageInTransit::View& message_view, 151 const MessageInTransit::View& message_view,
151 embedder::ScopedPlatformHandleVectorPtr platform_handles); 152 embedder::ScopedPlatformHandleVectorPtr platform_handles);
152 153
153 // Removes the message pipe endpoint with the given local ID, which must exist 154 // Removes the message pipe endpoint with the given local ID, which must exist
154 // and be a zombie, and given remote ID. Returns false on failure, in 155 // and be a zombie, and given remote ID. Returns false on failure, in
155 // particular if no message pipe with |local_id| is attached. 156 // particular if no message pipe with |local_id| is attached. Only called on
157 // the creation thread.
156 bool RemoveMessagePipeEndpoint(MessageInTransit::EndpointId local_id, 158 bool RemoveMessagePipeEndpoint(MessageInTransit::EndpointId local_id,
157 MessageInTransit::EndpointId remote_id); 159 MessageInTransit::EndpointId remote_id);
158 160
159 // Handles errors (e.g., invalid messages) from the remote side. 161 // Handles errors (e.g., invalid messages) from the remote side. Callable from
162 // any thread.
160 void HandleRemoteError(const base::StringPiece& error_message); 163 void HandleRemoteError(const base::StringPiece& error_message);
161 // Handles internal errors/failures from the local side. 164 // Handles internal errors/failures from the local side. Callable from any
165 // thread.
162 void HandleLocalError(const base::StringPiece& error_message); 166 void HandleLocalError(const base::StringPiece& error_message);
163 167
164 // Helper to send channel control messages. Returns true on success. Should be 168 // Helper to send channel control messages. Returns true on success. Should be
165 // called *without* |lock_| held. 169 // called *without* |lock_| held. Callable from any thread.
166 bool SendControlMessage(MessageInTransit::Subtype subtype, 170 bool SendControlMessage(MessageInTransit::Subtype subtype,
167 MessageInTransit::EndpointId source_id, 171 MessageInTransit::EndpointId source_id,
168 MessageInTransit::EndpointId destination_id); 172 MessageInTransit::EndpointId destination_id);
169 173
170 base::ThreadChecker creation_thread_checker_; 174 base::ThreadChecker creation_thread_checker_;
171 175
172 embedder::PlatformSupport* const platform_support_; 176 embedder::PlatformSupport* const platform_support_;
173 177
174 // Note: |MessagePipe|s MUST NOT be used under |lock_|. I.e., |lock_| can only 178 // Note: |MessagePipe|s MUST NOT be used under |lock_|. I.e., |lock_| can only
175 // be acquired after |MessagePipe::lock_|, never before. Thus to call into a 179 // be acquired after |MessagePipe::lock_|, never before. Thus to call into a
(...skipping 13 matching lines...) Expand all
189 // be checked for existence before use. 193 // be checked for existence before use.
190 MessageInTransit::EndpointId next_local_id_; 194 MessageInTransit::EndpointId next_local_id_;
191 195
192 DISALLOW_COPY_AND_ASSIGN(Channel); 196 DISALLOW_COPY_AND_ASSIGN(Channel);
193 }; 197 };
194 198
195 } // namespace system 199 } // namespace system
196 } // namespace mojo 200 } // namespace mojo
197 201
198 #endif // MOJO_SYSTEM_CHANNEL_H_ 202 #endif // MOJO_SYSTEM_CHANNEL_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/system/channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698