Add an extension override bubble and warning box for proxy extensions. (2nd attempt...
[chromium-blink-merge.git] / mojo / system / message_pipe_endpoint.h
blob331d7af149fb2e4a31dff1ee1e68d0ffc91b5072
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_ENDPOINT_H_
6 #define MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_
8 #include <stdint.h>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "mojo/public/c/system/message_pipe.h"
16 #include "mojo/public/c/system/types.h"
17 #include "mojo/system/dispatcher.h"
18 #include "mojo/system/message_in_transit.h"
19 #include "mojo/system/system_impl_export.h"
21 namespace mojo {
22 namespace system {
24 class Channel;
25 class Waiter;
27 // This is an interface to one of the ends of a message pipe, and is used by
28 // |MessagePipe|. Its most important role is to provide a sink for messages
29 // (i.e., a place where messages can be sent). It has a secondary role: When the
30 // endpoint is local (i.e., in the current process), there'll be a dispatcher
31 // corresponding to the endpoint. In that case, the implementation of
32 // |MessagePipeEndpoint| also implements the functionality required by the
33 // dispatcher, e.g., to read messages and to wait. Implementations of this class
34 // are not thread-safe; instances are protected by |MesssagePipe|'s lock.
35 class MOJO_SYSTEM_IMPL_EXPORT MessagePipeEndpoint {
36 public:
37 virtual ~MessagePipeEndpoint() {}
39 enum Type {
40 kTypeLocal,
41 kTypeProxy
43 virtual Type GetType() const = 0;
45 // All implementations must implement these.
46 // Returns false if the endpoint should be closed and destroyed, else true.
47 virtual bool OnPeerClose() = 0;
48 // Implements |MessagePipe::EnqueueMessage()|. The major differences are that:
49 // a) Dispatchers have been vetted and cloned/attached to the message.
50 // b) At this point, we cannot report failure (if, e.g., a channel is torn
51 // down at this point, we should silently swallow the message).
52 virtual void EnqueueMessage(scoped_ptr<MessageInTransit> message) = 0;
54 // Implementations must override these if they represent a local endpoint,
55 // i.e., one for which there's a |MessagePipeDispatcher| (and thus a handle).
56 // An implementation for a proxy endpoint (for which there's no dispatcher)
57 // needs not override these methods, since they should never be called.
59 // These methods implement the methods of the same name in |MessagePipe|,
60 // though |MessagePipe|'s implementation may have to do a little more if the
61 // operation involves both endpoints.
62 virtual void Close();
63 virtual void CancelAllWaiters();
64 virtual MojoResult ReadMessage(void* bytes,
65 uint32_t* num_bytes,
66 DispatcherVector* dispatchers,
67 uint32_t* num_dispatchers,
68 MojoReadMessageFlags flags);
69 virtual MojoResult AddWaiter(Waiter* waiter,
70 MojoWaitFlags flags,
71 MojoResult wake_result);
72 virtual void RemoveWaiter(Waiter* waiter);
74 // Implementations must override these if they represent a proxy endpoint. An
75 // implementation for a local endpoint needs not override these methods, since
76 // they should never be called.
77 virtual void Attach(scoped_refptr<Channel> channel,
78 MessageInTransit::EndpointId local_id);
79 // Returns false if the endpoint should be closed and destroyed, else true.
80 virtual bool Run(MessageInTransit::EndpointId remote_id);
81 virtual void OnRemove();
83 protected:
84 MessagePipeEndpoint() {}
86 private:
87 DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint);
90 } // namespace system
91 } // namespace mojo
93 #endif // MOJO_SYSTEM_MESSAGE_PIPE_ENDPOINT_H_