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

Side by Side Diff: mojo/embedder/embedder.cc

Issue 484893004: Mojo: Make Core own a PlatformSupport, and plumb it through to Channel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/system/channel.h » ('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 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 #include "mojo/embedder/embedder.h" 5 #include "mojo/embedder/embedder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 20 matching lines...) Expand all
31 31
32 // May be null, in which case |DestroyChannelOnIOThread()| must be used (from 32 // May be null, in which case |DestroyChannelOnIOThread()| must be used (from
33 // the IO thread), instead of |DestroyChannel()|. 33 // the IO thread), instead of |DestroyChannel()|.
34 scoped_refptr<base::TaskRunner> io_thread_task_runner; 34 scoped_refptr<base::TaskRunner> io_thread_task_runner;
35 }; 35 };
36 36
37 namespace { 37 namespace {
38 38
39 // Helper for |CreateChannel...()|. (Note: May return null for some failures.) 39 // Helper for |CreateChannel...()|. (Note: May return null for some failures.)
40 scoped_refptr<system::Channel> MakeChannel( 40 scoped_refptr<system::Channel> MakeChannel(
41 system::Core* core,
41 ScopedPlatformHandle platform_handle, 42 ScopedPlatformHandle platform_handle,
42 scoped_refptr<system::MessagePipe> message_pipe) { 43 scoped_refptr<system::MessagePipe> message_pipe) {
43 DCHECK(platform_handle.is_valid()); 44 DCHECK(platform_handle.is_valid());
44 45
45 // Create and initialize a |system::Channel|. 46 // Create and initialize a |system::Channel|.
46 scoped_refptr<system::Channel> channel = new system::Channel(); 47 scoped_refptr<system::Channel> channel =
48 new system::Channel(core->platform_support());
47 if (!channel->Init(system::RawChannel::Create(platform_handle.Pass()))) { 49 if (!channel->Init(system::RawChannel::Create(platform_handle.Pass()))) {
48 // This is very unusual (e.g., maybe |platform_handle| was invalid or we 50 // This is very unusual (e.g., maybe |platform_handle| was invalid or we
49 // reached some system resource limit). 51 // reached some system resource limit).
50 LOG(ERROR) << "Channel::Init() failed"; 52 LOG(ERROR) << "Channel::Init() failed";
51 // Return null, since |Shutdown()| shouldn't be called in this case. 53 // Return null, since |Shutdown()| shouldn't be called in this case.
52 return scoped_refptr<system::Channel>(); 54 return scoped_refptr<system::Channel>();
53 } 55 }
54 // Once |Init()| has succeeded, we have to return |channel| (since 56 // Once |Init()| has succeeded, we have to return |channel| (since
55 // |Shutdown()| will have to be called on it). 57 // |Shutdown()| will have to be called on it).
56 58
(...skipping 12 matching lines...) Expand all
69 system::Channel::kBootstrapEndpointId)) { 71 system::Channel::kBootstrapEndpointId)) {
70 // Currently, there's no reason for this to fail. 72 // Currently, there's no reason for this to fail.
71 NOTREACHED() << "Channel::RunMessagePipeEndpoint() failed"; 73 NOTREACHED() << "Channel::RunMessagePipeEndpoint() failed";
72 return channel; 74 return channel;
73 } 75 }
74 76
75 return channel; 77 return channel;
76 } 78 }
77 79
78 void CreateChannelHelper( 80 void CreateChannelHelper(
81 system::Core* core,
79 ScopedPlatformHandle platform_handle, 82 ScopedPlatformHandle platform_handle,
80 scoped_ptr<ChannelInfo> channel_info, 83 scoped_ptr<ChannelInfo> channel_info,
81 scoped_refptr<system::MessagePipe> message_pipe, 84 scoped_refptr<system::MessagePipe> message_pipe,
82 DidCreateChannelCallback callback, 85 DidCreateChannelCallback callback,
83 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { 86 scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
84 channel_info->channel = MakeChannel(platform_handle.Pass(), message_pipe); 87 channel_info->channel =
88 MakeChannel(core, platform_handle.Pass(), message_pipe);
85 89
86 // Hand the channel back to the embedder. 90 // Hand the channel back to the embedder.
87 if (callback_thread_task_runner) { 91 if (callback_thread_task_runner) {
88 callback_thread_task_runner->PostTask( 92 callback_thread_task_runner->PostTask(
89 FROM_HERE, base::Bind(callback, channel_info.release())); 93 FROM_HERE, base::Bind(callback, channel_info.release()));
90 } else { 94 } else {
91 callback.Run(channel_info.release()); 95 callback.Run(channel_info.release());
92 } 96 }
93 } 97 }
94 98
(...skipping 14 matching lines...) Expand all
109 scoped_refptr<system::MessagePipe> > remote_message_pipe = 113 scoped_refptr<system::MessagePipe> > remote_message_pipe =
110 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); 114 system::MessagePipeDispatcher::CreateRemoteMessagePipe();
111 115
112 system::Core* core = system::entrypoints::GetCore(); 116 system::Core* core = system::entrypoints::GetCore();
113 DCHECK(core); 117 DCHECK(core);
114 ScopedMessagePipeHandle rv( 118 ScopedMessagePipeHandle rv(
115 MessagePipeHandle(core->AddDispatcher(remote_message_pipe.first))); 119 MessagePipeHandle(core->AddDispatcher(remote_message_pipe.first)));
116 120
117 *channel_info = new ChannelInfo(); 121 *channel_info = new ChannelInfo();
118 (*channel_info)->channel = 122 (*channel_info)->channel =
119 MakeChannel(platform_handle.Pass(), remote_message_pipe.second); 123 MakeChannel(core, platform_handle.Pass(), remote_message_pipe.second);
120 124
121 return rv.Pass(); 125 return rv.Pass();
122 } 126 }
123 127
124 ScopedMessagePipeHandle CreateChannel( 128 ScopedMessagePipeHandle CreateChannel(
125 ScopedPlatformHandle platform_handle, 129 ScopedPlatformHandle platform_handle,
126 scoped_refptr<base::TaskRunner> io_thread_task_runner, 130 scoped_refptr<base::TaskRunner> io_thread_task_runner,
127 DidCreateChannelCallback callback, 131 DidCreateChannelCallback callback,
128 scoped_refptr<base::TaskRunner> callback_thread_task_runner) { 132 scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
129 DCHECK(platform_handle.is_valid()); 133 DCHECK(platform_handle.is_valid());
130 134
131 std::pair<scoped_refptr<system::MessagePipeDispatcher>, 135 std::pair<scoped_refptr<system::MessagePipeDispatcher>,
132 scoped_refptr<system::MessagePipe> > remote_message_pipe = 136 scoped_refptr<system::MessagePipe> > remote_message_pipe =
133 system::MessagePipeDispatcher::CreateRemoteMessagePipe(); 137 system::MessagePipeDispatcher::CreateRemoteMessagePipe();
134 138
135 system::Core* core = system::entrypoints::GetCore(); 139 system::Core* core = system::entrypoints::GetCore();
136 DCHECK(core); 140 DCHECK(core);
137 ScopedMessagePipeHandle rv( 141 ScopedMessagePipeHandle rv(
138 MessagePipeHandle(core->AddDispatcher(remote_message_pipe.first))); 142 MessagePipeHandle(core->AddDispatcher(remote_message_pipe.first)));
139 143
140 scoped_ptr<ChannelInfo> channel_info(new ChannelInfo()); 144 scoped_ptr<ChannelInfo> channel_info(new ChannelInfo());
141 channel_info->io_thread_task_runner = io_thread_task_runner; 145 channel_info->io_thread_task_runner = io_thread_task_runner;
142 146
143 if (rv.is_valid()) { 147 if (rv.is_valid()) {
144 io_thread_task_runner->PostTask(FROM_HERE, 148 io_thread_task_runner->PostTask(FROM_HERE,
145 base::Bind(&CreateChannelHelper, 149 base::Bind(&CreateChannelHelper,
150 base::Unretained(core),
146 base::Passed(&platform_handle), 151 base::Passed(&platform_handle),
147 base::Passed(&channel_info), 152 base::Passed(&channel_info),
148 remote_message_pipe.second, 153 remote_message_pipe.second,
149 callback, 154 callback,
150 callback_thread_task_runner)); 155 callback_thread_task_runner));
151 } else { 156 } else {
152 (callback_thread_task_runner ? callback_thread_task_runner 157 (callback_thread_task_runner ? callback_thread_task_runner
153 : io_thread_task_runner) 158 : io_thread_task_runner)
154 ->PostTask(FROM_HERE, base::Bind(callback, channel_info.release())); 159 ->PostTask(FROM_HERE, base::Bind(callback, channel_info.release()));
155 } 160 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 230
226 *platform_handle = 231 *platform_handle =
227 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get()) 232 static_cast<system::PlatformHandleDispatcher*>(dispatcher.get())
228 ->PassPlatformHandle() 233 ->PassPlatformHandle()
229 .Pass(); 234 .Pass();
230 return MOJO_RESULT_OK; 235 return MOJO_RESULT_OK;
231 } 236 }
232 237
233 } // namespace embedder 238 } // namespace embedder
234 } // namespace mojo 239 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/system/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698