OLD | NEW |
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 <utility> |
| 8 |
7 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
8 #include "base/bind.h" | 10 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 12 #include "base/command_line.h" |
11 #include "base/location.h" | 13 #include "base/location.h" |
12 #include "base/logging.h" | 14 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
15 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
16 #include "mojo/edk/embedder/embedder_internal.h" | 18 #include "mojo/edk/embedder/embedder_internal.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 59 } |
58 | 60 |
59 ScopedPlatformHandle ChildProcessLaunched(base::ProcessHandle child_process) { | 61 ScopedPlatformHandle ChildProcessLaunched(base::ProcessHandle child_process) { |
60 PlatformChannelPair token_channel; | 62 PlatformChannelPair token_channel; |
61 new ChildBrokerHost(child_process, token_channel.PassServerHandle()); | 63 new ChildBrokerHost(child_process, token_channel.PassServerHandle()); |
62 return token_channel.PassClientHandle(); | 64 return token_channel.PassClientHandle(); |
63 } | 65 } |
64 | 66 |
65 void ChildProcessLaunched(base::ProcessHandle child_process, | 67 void ChildProcessLaunched(base::ProcessHandle child_process, |
66 ScopedPlatformHandle server_pipe) { | 68 ScopedPlatformHandle server_pipe) { |
67 new ChildBrokerHost(child_process, server_pipe.Pass()); | 69 new ChildBrokerHost(child_process, std::move(server_pipe)); |
68 } | 70 } |
69 | 71 |
70 void SetParentPipeHandle(ScopedPlatformHandle pipe) { | 72 void SetParentPipeHandle(ScopedPlatformHandle pipe) { |
71 ChildBroker::GetInstance()->SetChildBrokerHostHandle(pipe.Pass()); | 73 ChildBroker::GetInstance()->SetChildBrokerHostHandle(std::move(pipe)); |
72 } | 74 } |
73 | 75 |
74 void Init() { | 76 void Init() { |
75 const base::CommandLine& command_line = | 77 const base::CommandLine& command_line = |
76 *base::CommandLine::ForCurrentProcess(); | 78 *base::CommandLine::ForCurrentProcess(); |
77 if (command_line.HasSwitch("use-new-edk") && !internal::g_broker) | 79 if (command_line.HasSwitch("use-new-edk") && !internal::g_broker) |
78 BrokerState::GetInstance(); | 80 BrokerState::GetInstance(); |
79 | 81 |
80 DCHECK(!internal::g_platform_support); | 82 DCHECK(!internal::g_platform_support); |
81 internal::g_platform_support = new SimplePlatformSupport(); | 83 internal::g_platform_support = new SimplePlatformSupport(); |
82 | 84 |
83 DCHECK(!internal::g_core); | 85 DCHECK(!internal::g_core); |
84 internal::g_core = new Core(internal::g_platform_support); | 86 internal::g_core = new Core(internal::g_platform_support); |
85 } | 87 } |
86 | 88 |
87 MojoResult AsyncWait(MojoHandle handle, | 89 MojoResult AsyncWait(MojoHandle handle, |
88 MojoHandleSignals signals, | 90 MojoHandleSignals signals, |
89 const base::Callback<void(MojoResult)>& callback) { | 91 const base::Callback<void(MojoResult)>& callback) { |
90 return internal::g_core->AsyncWait(handle, signals, callback); | 92 return internal::g_core->AsyncWait(handle, signals, callback); |
91 } | 93 } |
92 | 94 |
93 MojoResult CreatePlatformHandleWrapper( | 95 MojoResult CreatePlatformHandleWrapper( |
94 ScopedPlatformHandle platform_handle, | 96 ScopedPlatformHandle platform_handle, |
95 MojoHandle* platform_handle_wrapper_handle) { | 97 MojoHandle* platform_handle_wrapper_handle) { |
96 DCHECK(platform_handle_wrapper_handle); | 98 DCHECK(platform_handle_wrapper_handle); |
97 | 99 |
98 scoped_refptr<Dispatcher> dispatcher = | 100 scoped_refptr<Dispatcher> dispatcher = |
99 PlatformHandleDispatcher::Create(platform_handle.Pass()); | 101 PlatformHandleDispatcher::Create(std::move(platform_handle)); |
100 | 102 |
101 DCHECK(internal::g_core); | 103 DCHECK(internal::g_core); |
102 MojoHandle h = internal::g_core->AddDispatcher(dispatcher); | 104 MojoHandle h = internal::g_core->AddDispatcher(dispatcher); |
103 if (h == MOJO_HANDLE_INVALID) { | 105 if (h == MOJO_HANDLE_INVALID) { |
104 LOG(ERROR) << "Handle table full"; | 106 LOG(ERROR) << "Handle table full"; |
105 dispatcher->Close(); | 107 dispatcher->Close(); |
106 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 108 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
107 } | 109 } |
108 | 110 |
109 *platform_handle_wrapper_handle = h; | 111 *platform_handle_wrapper_handle = h; |
110 return MOJO_RESULT_OK; | 112 return MOJO_RESULT_OK; |
111 } | 113 } |
112 | 114 |
113 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, | 115 MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle, |
114 ScopedPlatformHandle* platform_handle) { | 116 ScopedPlatformHandle* platform_handle) { |
115 DCHECK(platform_handle); | 117 DCHECK(platform_handle); |
116 | 118 |
117 DCHECK(internal::g_core); | 119 DCHECK(internal::g_core); |
118 scoped_refptr<Dispatcher> dispatcher( | 120 scoped_refptr<Dispatcher> dispatcher( |
119 internal::g_core->GetDispatcher(platform_handle_wrapper_handle)); | 121 internal::g_core->GetDispatcher(platform_handle_wrapper_handle)); |
120 if (!dispatcher) | 122 if (!dispatcher) |
121 return MOJO_RESULT_INVALID_ARGUMENT; | 123 return MOJO_RESULT_INVALID_ARGUMENT; |
122 | 124 |
123 if (dispatcher->GetType() != Dispatcher::Type::PLATFORM_HANDLE) | 125 if (dispatcher->GetType() != Dispatcher::Type::PLATFORM_HANDLE) |
124 return MOJO_RESULT_INVALID_ARGUMENT; | 126 return MOJO_RESULT_INVALID_ARGUMENT; |
125 | 127 |
126 *platform_handle = | 128 *platform_handle = static_cast<PlatformHandleDispatcher*>(dispatcher.get()) |
127 static_cast<PlatformHandleDispatcher*>(dispatcher.get()) | 129 ->PassPlatformHandle(); |
128 ->PassPlatformHandle() | |
129 .Pass(); | |
130 return MOJO_RESULT_OK; | 130 return MOJO_RESULT_OK; |
131 } | 131 } |
132 | 132 |
133 void InitIPCSupport(ProcessDelegate* process_delegate, | 133 void InitIPCSupport(ProcessDelegate* process_delegate, |
134 scoped_refptr<base::TaskRunner> io_thread_task_runner) { | 134 scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
135 // |Init()| must have already been called. | 135 // |Init()| must have already been called. |
136 DCHECK(internal::g_core); | 136 DCHECK(internal::g_core); |
137 internal::g_process_delegate = process_delegate; | 137 internal::g_process_delegate = process_delegate; |
138 internal::g_io_thread_task_runner = io_thread_task_runner.get(); | 138 internal::g_io_thread_task_runner = io_thread_task_runner.get(); |
139 } | 139 } |
(...skipping 10 matching lines...) Expand all Loading... |
150 ScopedPlatformHandle platform_handle) { | 150 ScopedPlatformHandle platform_handle) { |
151 MojoCreateMessagePipeOptions options = { | 151 MojoCreateMessagePipeOptions options = { |
152 static_cast<uint32_t>(sizeof(MojoCreateMessagePipeOptions)), | 152 static_cast<uint32_t>(sizeof(MojoCreateMessagePipeOptions)), |
153 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE}; | 153 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_TRANSFERABLE}; |
154 scoped_refptr<MessagePipeDispatcher> dispatcher = | 154 scoped_refptr<MessagePipeDispatcher> dispatcher = |
155 MessagePipeDispatcher::Create(options); | 155 MessagePipeDispatcher::Create(options); |
156 | 156 |
157 ScopedMessagePipeHandle rv( | 157 ScopedMessagePipeHandle rv( |
158 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); | 158 MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); |
159 CHECK(rv.is_valid()); | 159 CHECK(rv.is_valid()); |
160 dispatcher->Init(platform_handle.Pass(), nullptr, 0, nullptr, 0, nullptr, | 160 dispatcher->Init(std::move(platform_handle), nullptr, 0, nullptr, 0, nullptr, |
161 nullptr); | 161 nullptr); |
162 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it | 162 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it |
163 // once that's fixed. | 163 // once that's fixed. |
164 return rv.Pass(); | 164 return rv; |
165 } | 165 } |
166 | 166 |
167 } // namespace edk | 167 } // namespace edk |
168 } // namespace mojo | 168 } // namespace mojo |
OLD | NEW |