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

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

Issue 885453003: Remove ChannelManager::AddChannel(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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_CHANNEL_MANAGER_H_ 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_
6 #define MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ 6 #define MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 13 matching lines...) Expand all
24 24
25 namespace system { 25 namespace system {
26 26
27 // IDs for |Channel|s managed by a |ChannelManager|. (IDs should be thought of 27 // IDs for |Channel|s managed by a |ChannelManager|. (IDs should be thought of
28 // as specific to a given |ChannelManager|.) 0 is never a valid ID. 28 // as specific to a given |ChannelManager|.) 0 is never a valid ID.
29 typedef uint64_t ChannelId; 29 typedef uint64_t ChannelId;
30 30
31 const ChannelId kInvalidChannelId = 0; 31 const ChannelId kInvalidChannelId = 0;
32 32
33 // This class manages and "owns" |Channel|s (which typically connect to other 33 // This class manages and "owns" |Channel|s (which typically connect to other
34 // processes) for a given process. This class is thread-safe. 34 // processes) for a given process. This class is thread-safe, except as
35 // specifically noted.
35 class MOJO_SYSTEM_IMPL_EXPORT ChannelManager { 36 class MOJO_SYSTEM_IMPL_EXPORT ChannelManager {
36 public: 37 public:
37 // |*platform_support| must remain alive longer than this object. 38 // |*platform_support| must remain alive longer than this object.
38 explicit ChannelManager(embedder::PlatformSupport* platform_support); 39 explicit ChannelManager(embedder::PlatformSupport* platform_support);
39 ~ChannelManager(); 40 ~ChannelManager();
40 41
41 // Creates a |Channel| and adds it to the set of channels managed by this 42 // Creates a |Channel| and adds it to the set of channels managed by this
42 // |ChannelManager|. |channel_id| should be a valid |ChannelId| (i.e., 43 // |ChannelManager|. |channel_id| should be a valid |ChannelId| (i.e.,
43 // nonzero) not "assigned" to any other |Channel| being managed by this 44 // nonzero) not "assigned" to any other |Channel| being managed by this
44 // |ChannelManager|. 45 // |ChannelManager|.
45 // TODO(vtl): Currently, this should be called on any I/O thread (which will 46 // TODO(vtl): Currently, this should be called on any I/O thread (which will
46 // become the new channel's "channel thread"). Eventually, the channel manager 47 // become the new channel's "channel thread"). Eventually, the channel manager
47 // will have an assigned I/O thread, on which this must be called. 48 // will have an assigned I/O thread, on which this must be called.
48 // TODO(vtl): Maybe this should return a message pipe dispatcher (for the 49 // TODO(vtl): Maybe this should return a message pipe dispatcher (for the
49 // bootstrap message pipe) instead. 50 // bootstrap message pipe) instead.
50 void CreateChannelOnIOThread( 51 void CreateChannelOnIOThread(
51 ChannelId channel_id, 52 ChannelId channel_id,
52 embedder::ScopedPlatformHandle platform_handle, 53 embedder::ScopedPlatformHandle platform_handle,
53 scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint); 54 scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint);
54 55
55 // DEPRECATED. TODO(vtl): Convert the tests, and delete this method. 56 // Gets the |Channel| with the given ID (which must exist).
56 // Adds |channel| to the set of |Channel|s managed by this |ChannelManager|. 57 scoped_refptr<Channel> GetChannel(ChannelId channel_id) const;
57 // |channel_id| should be a nonzero value that is not "assigned" to any other
58 // |Channel| being managed by this |ChannelManager|.
59 // |channel_thread_task_runner| should be the task runner for |channel|'s
60 // creation (a.k.a. I/O) thread. |channel| should already be initialized and
61 // not be managed by any |ChannelManager| yet.
62 void AddChannel(ChannelId channel_id,
63 scoped_refptr<Channel> channel,
64 scoped_refptr<base::TaskRunner> channel_thread_task_runner);
65 58
66 // Informs the channel manager (and thus channel) that it will be shutdown 59 // Informs the channel manager (and thus channel) that it will be shutdown
67 // soon (by calling |ShutdownChannel()|). Calling this is optional (and may in 60 // soon (by calling |ShutdownChannel()|). Calling this is optional (and may in
68 // fact be called multiple times) but it will suppress certain warnings (e.g., 61 // fact be called multiple times) but it will suppress certain warnings (e.g.,
69 // for the channel being broken) and enable others (if messages are written to 62 // for the channel being broken) and enable others (if messages are written to
70 // the channel). 63 // the channel).
71 void WillShutdownChannel(ChannelId channel_id); 64 void WillShutdownChannel(ChannelId channel_id);
72 65
73 // Shuts down the channel specified by the given ID. It is up to the caller to 66 // Shuts down the channel specified by the given ID. It is up to the caller to
74 // guarantee that this is only called once per channel (that was added using 67 // guarantee that this is only called once per channel (that was added using
75 // |CreateChannelOnIOThread()| or |AddChannel()|). If called from the 68 // |CreateChannelOnIOThread()|). If called from the channel's creation thread
76 // channel's creation thread (i.e., |base::MessageLoopProxy::current()| is the 69 // (i.e., |base::MessageLoopProxy::current()| is the channel thread's
77 // channel thread's |TaskRunner|), this will complete synchronously. 70 // |TaskRunner|), this will complete synchronously.
78 void ShutdownChannel(ChannelId channel_id); 71 void ShutdownChannel(ChannelId channel_id);
79 72
80 private: 73 private:
81 // Gets the |ChannelInfo| for the channel specified by the given ID. (This
82 // should *not* be called under lock.)
83 ChannelInfo GetChannelInfo(ChannelId channel_id);
84
85 embedder::PlatformSupport* const platform_support_; 74 embedder::PlatformSupport* const platform_support_;
86 75
87 // Note: |Channel| methods should not be called under |lock_|. 76 // Note: |Channel| methods should not be called under |lock_|.
88 base::Lock lock_; // Protects the members below. 77 mutable base::Lock lock_; // Protects the members below.
89 78
79 // TODO(vtl): Once we give the |ChannelManager| one single I/O thread, we can
80 // get rid of |ChannelInfo| (and just have ref pointers to |Channel|s).
90 base::hash_map<ChannelId, ChannelInfo> channel_infos_; 81 base::hash_map<ChannelId, ChannelInfo> channel_infos_;
91 82
92 DISALLOW_COPY_AND_ASSIGN(ChannelManager); 83 DISALLOW_COPY_AND_ASSIGN(ChannelManager);
93 }; 84 };
94 85
95 } // namespace system 86 } // namespace system
96 } // namespace mojo 87 } // namespace mojo
97 88
98 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ 89 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698