| 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 "base/atomicops.h" | 7 #include "base/atomicops.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
| 15 #include "mojo/edk/embedder/embedder_internal.h" | 15 #include "mojo/edk/embedder/embedder_internal.h" |
| 16 #include "mojo/edk/embedder/platform_channel_pair.h" | 16 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 17 #include "mojo/edk/embedder/process_delegate.h" | 17 #include "mojo/edk/embedder/process_delegate.h" |
| 18 #include "mojo/edk/embedder/simple_platform_support.h" | 18 #include "mojo/edk/embedder/simple_platform_support.h" |
| 19 #include "mojo/edk/system/broker_state.h" |
| 20 #include "mojo/edk/system/child_broker.h" |
| 21 #include "mojo/edk/system/child_broker_host.h" |
| 19 #include "mojo/edk/system/configuration.h" | 22 #include "mojo/edk/system/configuration.h" |
| 20 #include "mojo/edk/system/core.h" | 23 #include "mojo/edk/system/core.h" |
| 21 #include "mojo/edk/system/message_pipe_dispatcher.h" | 24 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 22 #include "mojo/edk/system/platform_handle_dispatcher.h" | 25 #include "mojo/edk/system/platform_handle_dispatcher.h" |
| 23 | 26 #include "mojo/edk/system/simple_broker.h" |
| 24 #if defined(OS_WIN) | |
| 25 #include "mojo/edk/system/child_token_serializer_win.h" | |
| 26 #include "mojo/edk/system/parent_token_serializer_state_win.h" | |
| 27 #include "mojo/edk/system/parent_token_serializer_win.h" | |
| 28 #include "mojo/edk/system/simple_token_serializer_win.h" | |
| 29 #endif | |
| 30 | 27 |
| 31 namespace mojo { | 28 namespace mojo { |
| 32 namespace edk { | 29 namespace edk { |
| 33 | 30 |
| 34 // TODO(jam): move into annonymous namespace. Keep outside for debugging in VS | 31 // TODO(jam): move into annonymous namespace. Keep outside for debugging in VS |
| 35 // temporarily. | 32 // temporarily. |
| 36 int g_channel_count = 0; | 33 int g_channel_count = 0; |
| 37 bool g_wait_for_no_more_channels = false; | 34 bool g_wait_for_no_more_channels = false; |
| 38 base::TaskRunner* g_delegate_task_runner = nullptr; // Used at shutdown. | 35 base::TaskRunner* g_delegate_task_runner = nullptr; // Used at shutdown. |
| 39 | 36 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 FROM_HERE, base::Bind(&ProcessDelegate::OnShutdownComplete, | 47 FROM_HERE, base::Bind(&ProcessDelegate::OnShutdownComplete, |
| 51 base::Unretained(internal::g_process_delegate))); | 48 base::Unretained(internal::g_process_delegate))); |
| 52 g_delegate_task_runner = nullptr; | 49 g_delegate_task_runner = nullptr; |
| 53 } | 50 } |
| 54 | 51 |
| 55 } // namespace | 52 } // namespace |
| 56 | 53 |
| 57 namespace internal { | 54 namespace internal { |
| 58 | 55 |
| 59 // Declared in embedder_internal.h. | 56 // Declared in embedder_internal.h. |
| 60 #if defined(OS_WIN) | 57 Broker* g_broker = nullptr; |
| 61 TokenSerializer* g_token_serializer = nullptr; | |
| 62 #endif | |
| 63 PlatformSupport* g_platform_support = nullptr; | 58 PlatformSupport* g_platform_support = nullptr; |
| 64 Core* g_core = nullptr; | 59 Core* g_core = nullptr; |
| 65 | 60 |
| 66 ProcessDelegate* g_process_delegate; | 61 ProcessDelegate* g_process_delegate; |
| 67 base::TaskRunner* g_io_thread_task_runner = nullptr; | 62 base::TaskRunner* g_io_thread_task_runner = nullptr; |
| 68 | 63 |
| 69 Core* GetCore() { | 64 Core* GetCore() { |
| 70 return g_core; | 65 return g_core; |
| 71 } | 66 } |
| 72 | 67 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 86 ShutdownIPCSupportHelper(false); | 81 ShutdownIPCSupportHelper(false); |
| 87 } | 82 } |
| 88 } | 83 } |
| 89 | 84 |
| 90 } // namespace internal | 85 } // namespace internal |
| 91 | 86 |
| 92 void SetMaxMessageSize(size_t bytes) { | 87 void SetMaxMessageSize(size_t bytes) { |
| 93 GetMutableConfiguration()->max_message_num_bytes = bytes; | 88 GetMutableConfiguration()->max_message_num_bytes = bytes; |
| 94 } | 89 } |
| 95 | 90 |
| 96 #if defined(OS_WIN) | |
| 97 void PreInitializeParentProcess() { | 91 void PreInitializeParentProcess() { |
| 98 ParentTokenSerializerState::GetInstance(); | 92 BrokerState::GetInstance(); |
| 99 } | 93 } |
| 100 | 94 |
| 101 void PreInitializeChildProcess() { | 95 void PreInitializeChildProcess() { |
| 102 ChildTokenSerializer::GetInstance(); | 96 ChildBroker::GetInstance(); |
| 103 } | 97 } |
| 104 | 98 |
| 105 HANDLE ChildProcessLaunched(HANDLE child_process) { | 99 ScopedPlatformHandle ChildProcessLaunched(base::ProcessHandle child_process) { |
| 100 #if defined(OS_WIN) |
| 106 PlatformChannelPair token_channel; | 101 PlatformChannelPair token_channel; |
| 107 new ParentTokenSerializer(child_process, token_channel.PassServerHandle()); | 102 new ChildBrokerHost(child_process, token_channel.PassServerHandle()); |
| 108 return token_channel.PassClientHandle().release().handle; | 103 return token_channel.PassClientHandle(); |
| 104 #else |
| 105 // TODO(jam): create this for POSIX. Need to implement channel reading first |
| 106 // so we don't leak handles. |
| 107 return ScopedPlatformHandle(); |
| 108 #endif |
| 109 } | 109 } |
| 110 | 110 |
| 111 void ChildProcessLaunched(HANDLE child_process, HANDLE server_pipe) { | 111 void ChildProcessLaunched(base::ProcessHandle child_process, |
| 112 new ParentTokenSerializer( | 112 ScopedPlatformHandle server_pipe) { |
| 113 child_process, ScopedPlatformHandle(PlatformHandle(server_pipe))); | 113 new ChildBrokerHost(child_process, server_pipe.Pass()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void SetParentPipeHandle(HANDLE pipe) { | 116 void SetParentPipeHandle(ScopedPlatformHandle pipe) { |
| 117 ScopedPlatformHandle handle; | 117 ChildBroker::GetInstance()->SetChildBrokerHostHandle(pipe.Pass()); |
| 118 handle.reset(PlatformHandle(pipe)); | |
| 119 ChildTokenSerializer::GetInstance()-> | |
| 120 SetParentTokenSerializerHandle(handle.Pass()); | |
| 121 } | 118 } |
| 122 #endif | |
| 123 | 119 |
| 124 void Init() { | 120 void Init() { |
| 125 #if defined(OS_WIN) | 121 if (!internal::g_broker) |
| 126 if (!internal::g_token_serializer) | 122 internal::g_broker = new SimpleBroker; |
| 127 internal::g_token_serializer = new SimpleTokenSerializer; | |
| 128 #endif | |
| 129 | 123 |
| 130 DCHECK(!internal::g_platform_support); | 124 DCHECK(!internal::g_platform_support); |
| 131 internal::g_platform_support = new SimplePlatformSupport(); | 125 internal::g_platform_support = new SimplePlatformSupport(); |
| 132 | 126 |
| 133 DCHECK(!internal::g_core); | 127 DCHECK(!internal::g_core); |
| 134 internal::g_core = new Core(internal::g_platform_support); | 128 internal::g_core = new Core(internal::g_platform_support); |
| 135 } | 129 } |
| 136 | 130 |
| 137 MojoResult AsyncWait(MojoHandle handle, | 131 MojoResult AsyncWait(MojoHandle handle, |
| 138 MojoHandleSignals signals, | 132 MojoHandleSignals signals, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 CHECK(rv.is_valid()); | 208 CHECK(rv.is_valid()); |
| 215 dispatcher->Init(platform_handle.Pass(), nullptr, 0, nullptr, 0, nullptr, | 209 dispatcher->Init(platform_handle.Pass(), nullptr, 0, nullptr, 0, nullptr, |
| 216 nullptr); | 210 nullptr); |
| 217 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it | 211 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it |
| 218 // once that's fixed. | 212 // once that's fixed. |
| 219 return rv.Pass(); | 213 return rv.Pass(); |
| 220 } | 214 } |
| 221 | 215 |
| 222 } // namespace edk | 216 } // namespace edk |
| 223 } // namespace mojo | 217 } // namespace mojo |
| OLD | NEW |