Add an extension override bubble and warning box for proxy extensions. (2nd attempt...
[chromium-blink-merge.git] / mojo / system / message_pipe.h
blobca0155d9bf8dafc8e9fb1eb105e4a58f9475da7b
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.
5 #ifndef MOJO_SYSTEM_MESSAGE_PIPE_H_
6 #define MOJO_SYSTEM_MESSAGE_PIPE_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/synchronization/lock.h"
14 #include "mojo/public/c/system/message_pipe.h"
15 #include "mojo/public/c/system/types.h"
16 #include "mojo/system/dispatcher.h"
17 #include "mojo/system/message_in_transit.h"
18 #include "mojo/system/message_pipe_endpoint.h"
19 #include "mojo/system/system_impl_export.h"
21 namespace mojo {
22 namespace system {
24 class Channel;
25 class Waiter;
27 // |MessagePipe| is the secondary object implementing a message pipe (see the
28 // explanatory comment in core.cc). It is typically owned by the dispatcher(s)
29 // corresponding to the local endpoints. This class is thread-safe.
30 class MOJO_SYSTEM_IMPL_EXPORT MessagePipe :
31 public base::RefCountedThreadSafe<MessagePipe> {
32 public:
33 MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint0,
34 scoped_ptr<MessagePipeEndpoint> endpoint1);
36 // Convenience constructor that constructs a |MessagePipe| with two new
37 // |LocalMessagePipeEndpoint|s.
38 MessagePipe();
40 // Gets the other port number (i.e., 0 -> 1, 1 -> 0).
41 static unsigned GetPeerPort(unsigned port);
43 // Gets the type of the endpoint (used for assertions, etc.).
44 MessagePipeEndpoint::Type GetType(unsigned port);
46 // These are called by the dispatcher to implement its methods of
47 // corresponding names. In all cases, the port |port| must be open.
48 void CancelAllWaiters(unsigned port);
49 void Close(unsigned port);
50 // Unlike |MessagePipeDispatcher::WriteMessage()|, this does not validate its
51 // arguments.
52 MojoResult WriteMessage(unsigned port,
53 const void* bytes,
54 uint32_t num_bytes,
55 std::vector<DispatcherTransport>* transports,
56 MojoWriteMessageFlags flags);
57 // Unlike |MessagePipeDispatcher::ReadMessage()|, this does not validate its
58 // arguments.
59 MojoResult ReadMessage(unsigned port,
60 void* bytes,
61 uint32_t* num_bytes,
62 DispatcherVector* dispatchers,
63 uint32_t* num_dispatchers,
64 MojoReadMessageFlags flags);
65 MojoResult AddWaiter(unsigned port,
66 Waiter* waiter,
67 MojoWaitFlags flags,
68 MojoResult wake_result);
69 void RemoveWaiter(unsigned port, Waiter* waiter);
71 // This is called by the dispatcher to convert a local endpoint to a proxy
72 // endpoint.
73 void ConvertLocalToProxy(unsigned port);
75 // This is used by |Channel| to enqueue messages (typically to a
76 // |LocalMessagePipeEndpoint|). Unlike |WriteMessage()|, |port| is the
77 // *destination* port.
78 MojoResult EnqueueMessage(unsigned port,
79 scoped_ptr<MessageInTransit> message);
81 // These are used by |Channel|.
82 bool Attach(unsigned port,
83 scoped_refptr<Channel> channel,
84 MessageInTransit::EndpointId local_id);
85 void Run(unsigned port, MessageInTransit::EndpointId remote_id);
86 void OnRemove(unsigned port);
88 private:
89 friend class base::RefCountedThreadSafe<MessagePipe>;
90 virtual ~MessagePipe();
92 // This is used internally by |WriteMessage()| and by |EnqueueMessage()|.
93 // |transports| may be non-null only if it's nonempty and |message| has no
94 // dispatchers attached.
95 MojoResult EnqueueMessageInternal(
96 unsigned port,
97 scoped_ptr<MessageInTransit> message,
98 std::vector<DispatcherTransport>* transports);
100 // Helper for |EnqueueMessageInternal()|. Must be called with |lock_| held.
101 MojoResult AttachTransportsNoLock(
102 unsigned port,
103 MessageInTransit* message,
104 std::vector<DispatcherTransport>* transports);
106 // Used by |EnqueueMessageInternal()| to handle control messages that are
107 // actually meant for us.
108 MojoResult HandleControlMessage(unsigned port,
109 scoped_ptr<MessageInTransit> message);
111 base::Lock lock_; // Protects the following members.
112 scoped_ptr<MessagePipeEndpoint> endpoints_[2];
114 DISALLOW_COPY_AND_ASSIGN(MessagePipe);
117 } // namespace system
118 } // namespace mojo
120 #endif // MOJO_SYSTEM_MESSAGE_PIPE_H_