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

Unified Diff: mojo/edk/system/channel_endpoint_client.h

Issue 738453003: Add a ChannelEndpointClient abstraction. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review comments Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/system/channel_endpoint.cc ('k') | mojo/edk/system/message_pipe.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/channel_endpoint_client.h
diff --git a/mojo/edk/system/channel_endpoint_client.h b/mojo/edk/system/channel_endpoint_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..e14326fcf4072ecd3ca4e18787669b57314f319c
--- /dev/null
+++ b/mojo/edk/system/channel_endpoint_client.h
@@ -0,0 +1,62 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_
+#define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "mojo/edk/system/system_impl_export.h"
+
+namespace mojo {
+namespace system {
+
+class MessageInTransit;
+
+// Interface for receivers of messages from |ChannelEndpoint| (hence from
+// |Channel|). |port| is simply the value passed to |ChannelEndpoint| on
+// construction, and provides a lightweight way for an object to be the client
+// of multiple |ChannelEndpoint|s. (|MessagePipe| implements this interface, in
+// which case |port| is the port number for the |ProxyMessagePipeEndpoint|
+// corresdponding to the |ChannelEndpoint|.)
+//
+// Implementations of this class should be thread-safe. |ChannelEndpointClient|
+// *precedes* |ChannelEndpoint| in the lock order, so |ChannelEndpoint| should
+// never call into this class with its lock held. (Instead, it should take a
+// reference under its lock, release its lock, and make any needed call(s).)
+//
+// Note: As a consequence of this, all the client methods may be called even
+// after |ChannelEndpoint::DetachFromClient()| has been called (so the
+// |ChannelEndpoint| has apparently relinquished its pointer to the
+// |ChannelEndpointClient|).
+class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpointClient
+ : public base::RefCountedThreadSafe<ChannelEndpointClient> {
+ public:
+ // Called by |ChannelEndpoint| in response to its |OnReadMessage()|, which is
+ // called by |Channel| when it receives a message for the |ChannelEndpoint|.
+ // (|port| is the value passed to |ChannelEndpoint|'s constructor as
+ // |client_port|.)
+ virtual bool OnReadMessage(unsigned port,
+ scoped_ptr<MessageInTransit> message) = 0;
+
+ // Called by |ChannelEndpoint| when the |Channel| is relinquishing its pointer
+ // to the |ChannelEndpoint| (and vice versa). After this is called,
+ // |OnReadMessage()| will no longer be called.
+ virtual void OnDetachFromChannel(unsigned port) = 0;
+
+ protected:
+ ChannelEndpointClient() {}
+
+ virtual ~ChannelEndpointClient() {}
+ friend class base::RefCountedThreadSafe<ChannelEndpointClient>;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ChannelEndpointClient);
+};
+
+} // namespace system
+} // namespace mojo
+
+#endif // MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_
« no previous file with comments | « mojo/edk/system/channel_endpoint.cc ('k') | mojo/edk/system/message_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698