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

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

Issue 898623002: Make mojo::system::Core not own the PlatformSupport. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: foo 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
« no previous file with comments | « no previous file | mojo/edk/embedder/embedder_internal.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 15 matching lines...) Expand all
26 namespace { 26 namespace {
27 27
28 // Helper for |CreateChannel...()|. Returns 0 on failure. Called on the channel 28 // Helper for |CreateChannel...()|. Returns 0 on failure. Called on the channel
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_platform_support);
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_platform_support);
39 channel->Init(system::RawChannel::Create(platform_handle.Pass())); 39 channel->Init(system::RawChannel::Create(platform_handle.Pass()));
40 channel->SetBootstrapEndpoint(channel_endpoint); 40 channel->SetBootstrapEndpoint(channel_endpoint);
41 41
42 // You can use any nonzero, unique (in the set of |Channel|s managed by the 42 // You can use any nonzero, unique (in the set of |Channel|s managed by the
43 // given |ChannelManager|) value as ID. So here we just use the address of the 43 // given |ChannelManager|) value as ID. So here we just use the address of the
44 // channel. 44 // channel.
45 system::ChannelId id = static_cast<system::ChannelId>( 45 system::ChannelId id = static_cast<system::ChannelId>(
46 reinterpret_cast<uintptr_t>(channel.get())); 46 reinterpret_cast<uintptr_t>(channel.get()));
47 DCHECK(internal::g_channel_manager); 47 DCHECK(internal::g_channel_manager);
48 internal::g_channel_manager->AddChannel(id, channel, 48 internal::g_channel_manager->AddChannel(id, channel,
(...skipping 18 matching lines...) Expand all
67 } else { 67 } else {
68 callback.Run(channel_info.release()); 68 callback.Run(channel_info.release());
69 } 69 }
70 } 70 }
71 71
72 } // namespace 72 } // namespace
73 73
74 namespace internal { 74 namespace internal {
75 75
76 // Declared in embedder_internal.h. 76 // Declared in embedder_internal.h.
77 PlatformSupport* g_platform_support = nullptr;
77 system::Core* g_core = nullptr; 78 system::Core* g_core = nullptr;
78 system::ChannelManager* g_channel_manager = nullptr; 79 system::ChannelManager* g_channel_manager = nullptr;
79 80
80 } // namespace internal 81 } // namespace internal
81 82
82 void Init(scoped_ptr<PlatformSupport> platform_support) { 83 void Init(scoped_ptr<PlatformSupport> platform_support) {
84 DCHECK(platform_support);
85
86 DCHECK(!internal::g_platform_support);
87 internal::g_platform_support = platform_support.release();
88
83 DCHECK(!internal::g_core); 89 DCHECK(!internal::g_core);
84 internal::g_core = new system::Core(platform_support.Pass()); 90 internal::g_core = new system::Core(internal::g_platform_support);
91
85 DCHECK(!internal::g_channel_manager); 92 DCHECK(!internal::g_channel_manager);
86 internal::g_channel_manager = new system::ChannelManager(); 93 internal::g_channel_manager = new system::ChannelManager();
87 } 94 }
88 95
89 Configuration* GetConfiguration() { 96 Configuration* GetConfiguration() {
90 return system::GetMutableConfiguration(); 97 return system::GetMutableConfiguration();
91 } 98 }
92 99
93 // TODO(vtl): Write tests for this. 100 // TODO(vtl): Write tests for this.
94 ScopedMessagePipeHandle CreateChannelOnIOThread( 101 ScopedMessagePipeHandle CreateChannelOnIOThread(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 211 }
205 212
206 MojoResult AsyncWait(MojoHandle handle, 213 MojoResult AsyncWait(MojoHandle handle,
207 MojoHandleSignals signals, 214 MojoHandleSignals signals,
208 base::Callback<void(MojoResult)> callback) { 215 base::Callback<void(MojoResult)> callback) {
209 return internal::g_core->AsyncWait(handle, signals, callback); 216 return internal::g_core->AsyncWait(handle, signals, callback);
210 } 217 }
211 218
212 } // namespace embedder 219 } // namespace embedder
213 } // namespace mojo 220 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/edk/embedder/embedder_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698