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

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

Issue 852113002: Remove RawChannel::Init() and Channel::Init() failure cases. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | mojo/edk/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/edk/embedder/embedder.h" 5 #include "mojo/edk/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 18 matching lines...) Expand all
29 // creation thread. 29 // creation thread.
30 system::ChannelId MakeChannel( 30 system::ChannelId MakeChannel(
31 ScopedPlatformHandle platform_handle, 31 ScopedPlatformHandle platform_handle,
32 scoped_refptr<system::ChannelEndpoint> channel_endpoint) { 32 scoped_refptr<system::ChannelEndpoint> channel_endpoint) {
33 DCHECK(platform_handle.is_valid()); 33 DCHECK(platform_handle.is_valid());
34 34
35 // Create and initialize a |system::Channel|. 35 // Create and initialize a |system::Channel|.
36 DCHECK(internal::g_core); 36 DCHECK(internal::g_core);
37 scoped_refptr<system::Channel> channel = 37 scoped_refptr<system::Channel> channel =
38 new system::Channel(internal::g_core->platform_support()); 38 new system::Channel(internal::g_core->platform_support());
39 if (!channel->Init(system::RawChannel::Create(platform_handle.Pass()))) { 39 channel->Init(system::RawChannel::Create(platform_handle.Pass()));
40 // This is very unusual (e.g., maybe |platform_handle| was invalid or we
41 // reached some system resource limit).
42 LOG(ERROR) << "Channel::Init() failed";
43 // Return null, since |Shutdown()| shouldn't be called in this case.
44 return 0;
45 }
46
47 channel->SetBootstrapEndpoint(channel_endpoint); 40 channel->SetBootstrapEndpoint(channel_endpoint);
48 41
49 DCHECK(internal::g_channel_manager); 42 DCHECK(internal::g_channel_manager);
50 return internal::g_channel_manager->AddChannel( 43 return internal::g_channel_manager->AddChannel(
51 channel, base::MessageLoopProxy::current()); 44 channel, base::MessageLoopProxy::current());
52 } 45 }
53 46
54 // Helper for |CreateChannel()|. Called on the channel creation thread. 47 // Helper for |CreateChannel()|. Called on the channel creation thread.
55 void CreateChannelHelper( 48 void CreateChannelHelper(
56 ScopedPlatformHandle platform_handle, 49 ScopedPlatformHandle platform_handle,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 : io_thread_task_runner) 136 : io_thread_task_runner)
144 ->PostTask(FROM_HERE, base::Bind(callback, channel_info.release())); 137 ->PostTask(FROM_HERE, base::Bind(callback, channel_info.release()));
145 } 138 }
146 139
147 return rv.Pass(); 140 return rv.Pass();
148 } 141 }
149 142
150 // TODO(vtl): Write tests for this. 143 // TODO(vtl): Write tests for this.
151 void DestroyChannel(ChannelInfo* channel_info) { 144 void DestroyChannel(ChannelInfo* channel_info) {
152 DCHECK(channel_info); 145 DCHECK(channel_info);
153 if (!channel_info->channel_id) { 146 DCHECK(channel_info->channel_id);
154 // Presumably, |Init()| on the channel failed.
155 return;
156 }
157
158 DCHECK(internal::g_channel_manager); 147 DCHECK(internal::g_channel_manager);
159 // This will destroy the channel synchronously if called from the channel 148 // This will destroy the channel synchronously if called from the channel
160 // thread. 149 // thread.
161 internal::g_channel_manager->ShutdownChannel(channel_info->channel_id); 150 internal::g_channel_manager->ShutdownChannel(channel_info->channel_id);
162 delete channel_info; 151 delete channel_info;
163 } 152 }
164 153
165 void WillDestroyChannelSoon(ChannelInfo* channel_info) { 154 void WillDestroyChannelSoon(ChannelInfo* channel_info) {
166 DCHECK(channel_info); 155 DCHECK(channel_info);
167 DCHECK(internal::g_channel_manager); 156 DCHECK(internal::g_channel_manager);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 198 }
210 199
211 MojoResult AsyncWait(MojoHandle handle, 200 MojoResult AsyncWait(MojoHandle handle,
212 MojoHandleSignals signals, 201 MojoHandleSignals signals,
213 base::Callback<void(MojoResult)> callback) { 202 base::Callback<void(MojoResult)> callback) {
214 return internal::g_core->AsyncWait(handle, signals, callback); 203 return internal::g_core->AsyncWait(handle, signals, callback);
215 } 204 }
216 205
217 } // namespace embedder 206 } // namespace embedder
218 } // namespace mojo 207 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/system/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698