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/process_delegate.h" | 17 #include "mojo/edk/embedder/process_delegate.h" |
17 #include "mojo/edk/embedder/simple_platform_support.h" | 18 #include "mojo/edk/embedder/simple_platform_support.h" |
18 #include "mojo/edk/system/configuration.h" | 19 #include "mojo/edk/system/configuration.h" |
19 #include "mojo/edk/system/core.h" | 20 #include "mojo/edk/system/core.h" |
20 #include "mojo/edk/system/message_pipe_dispatcher.h" | 21 #include "mojo/edk/system/message_pipe_dispatcher.h" |
21 #include "mojo/edk/system/platform_handle_dispatcher.h" | 22 #include "mojo/edk/system/platform_handle_dispatcher.h" |
22 | 23 |
| 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 |
23 namespace mojo { | 31 namespace mojo { |
24 namespace edk { | 32 namespace edk { |
25 | 33 |
26 // TODO(jam): move into annonymous namespace. Keep outside for debugging in VS | 34 // TODO(jam): move into annonymous namespace. Keep outside for debugging in VS |
27 // temporarily. | 35 // temporarily. |
28 int g_channel_count = 0; | 36 int g_channel_count = 0; |
29 bool g_wait_for_no_more_channels = false; | 37 bool g_wait_for_no_more_channels = false; |
30 base::TaskRunner* g_delegate_task_runner = nullptr; // Used at shutdown. | 38 base::TaskRunner* g_delegate_task_runner = nullptr; // Used at shutdown. |
31 | 39 |
32 namespace { | 40 namespace { |
33 | 41 |
34 // Note: Called on the I/O thread. | 42 // Note: Called on the I/O thread. |
35 void ShutdownIPCSupportHelper(bool wait_for_no_more_channels) { | 43 void ShutdownIPCSupportHelper(bool wait_for_no_more_channels) { |
36 if (wait_for_no_more_channels && g_channel_count) { | 44 if (wait_for_no_more_channels && g_channel_count) { |
37 g_wait_for_no_more_channels = true; | 45 g_wait_for_no_more_channels = true; |
38 return; | 46 return; |
39 } | 47 } |
40 | 48 |
41 g_delegate_task_runner->PostTask( | 49 g_delegate_task_runner->PostTask( |
42 FROM_HERE, base::Bind(&ProcessDelegate::OnShutdownComplete, | 50 FROM_HERE, base::Bind(&ProcessDelegate::OnShutdownComplete, |
43 base::Unretained(internal::g_process_delegate))); | 51 base::Unretained(internal::g_process_delegate))); |
44 g_delegate_task_runner = nullptr; | 52 g_delegate_task_runner = nullptr; |
45 } | 53 } |
46 | 54 |
47 } // namespace | 55 } // namespace |
48 | 56 |
49 namespace internal { | 57 namespace internal { |
50 | 58 |
51 // Declared in embedder_internal.h. | 59 // Declared in embedder_internal.h. |
| 60 #if defined(OS_WIN) |
| 61 TokenSerializer* g_token_serializer = nullptr; |
| 62 #endif |
52 PlatformSupport* g_platform_support = nullptr; | 63 PlatformSupport* g_platform_support = nullptr; |
53 Core* g_core = nullptr; | 64 Core* g_core = nullptr; |
54 | 65 |
55 ProcessDelegate* g_process_delegate; | 66 ProcessDelegate* g_process_delegate; |
56 base::TaskRunner* g_io_thread_task_runner = nullptr; | 67 base::TaskRunner* g_io_thread_task_runner = nullptr; |
57 | 68 |
58 Core* GetCore() { | 69 Core* GetCore() { |
59 return g_core; | 70 return g_core; |
60 } | 71 } |
61 | 72 |
(...skipping 13 matching lines...) Expand all Loading... |
75 ShutdownIPCSupportHelper(false); | 86 ShutdownIPCSupportHelper(false); |
76 } | 87 } |
77 } | 88 } |
78 | 89 |
79 } // namespace internal | 90 } // namespace internal |
80 | 91 |
81 void SetMaxMessageSize(size_t bytes) { | 92 void SetMaxMessageSize(size_t bytes) { |
82 GetMutableConfiguration()->max_message_num_bytes = bytes; | 93 GetMutableConfiguration()->max_message_num_bytes = bytes; |
83 } | 94 } |
84 | 95 |
| 96 #if defined(OS_WIN) |
| 97 void PreInitializeParentProcess() { |
| 98 ParentTokenSerializerState::GetInstance(); |
| 99 } |
| 100 |
| 101 void PreInitializeChildProcess() { |
| 102 ChildTokenSerializer::GetInstance(); |
| 103 } |
| 104 |
| 105 HANDLE ChildProcessLaunched(HANDLE child_process) { |
| 106 PlatformChannelPair token_channel; |
| 107 new ParentTokenSerializer(child_process, token_channel.PassServerHandle()); |
| 108 return token_channel.PassClientHandle().release().handle; |
| 109 } |
| 110 |
| 111 void ChildProcessLaunched(HANDLE child_process, HANDLE server_pipe) { |
| 112 new ParentTokenSerializer( |
| 113 child_process, ScopedPlatformHandle(PlatformHandle(server_pipe))); |
| 114 } |
| 115 |
| 116 void SetParentPipeHandle(HANDLE pipe) { |
| 117 ScopedPlatformHandle handle; |
| 118 handle.reset(PlatformHandle(pipe)); |
| 119 ChildTokenSerializer::GetInstance()-> |
| 120 SetParentTokenSerializerHandle(handle.Pass()); |
| 121 } |
| 122 #endif |
| 123 |
85 void Init() { | 124 void Init() { |
| 125 #if defined(OS_WIN) |
| 126 if (!internal::g_token_serializer) |
| 127 internal::g_token_serializer = new SimpleTokenSerializer; |
| 128 #endif |
| 129 |
86 DCHECK(!internal::g_platform_support); | 130 DCHECK(!internal::g_platform_support); |
87 internal::g_platform_support = new SimplePlatformSupport(); | 131 internal::g_platform_support = new SimplePlatformSupport(); |
88 | 132 |
89 DCHECK(!internal::g_core); | 133 DCHECK(!internal::g_core); |
90 internal::g_core = new Core(internal::g_platform_support); | 134 internal::g_core = new Core(internal::g_platform_support); |
91 } | 135 } |
92 | 136 |
93 MojoResult AsyncWait(MojoHandle handle, | 137 MojoResult AsyncWait(MojoHandle handle, |
94 MojoHandleSignals signals, | 138 MojoHandleSignals signals, |
95 const base::Callback<void(MojoResult)>& callback) { | 139 const base::Callback<void(MojoResult)>& callback) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 CHECK(rv.is_valid()); | 214 CHECK(rv.is_valid()); |
171 dispatcher->Init(platform_handle.Pass(), nullptr, 0, nullptr, 0, nullptr, | 215 dispatcher->Init(platform_handle.Pass(), nullptr, 0, nullptr, 0, nullptr, |
172 nullptr); | 216 nullptr); |
173 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it | 217 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it |
174 // once that's fixed. | 218 // once that's fixed. |
175 return rv.Pass(); | 219 return rv.Pass(); |
176 } | 220 } |
177 | 221 |
178 } // namespace edk | 222 } // namespace edk |
179 } // namespace mojo | 223 } // namespace mojo |
OLD | NEW |