| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | |
| 12 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
| 13 #include "base/bind.h" | 12 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 16 #include "base/location.h" | 15 #include "base/location.h" |
| 17 #include "base/logging.h" | 16 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 20 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
| 21 #include "mojo/edk/embedder/embedder_internal.h" | 20 #include "mojo/edk/embedder/embedder_internal.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 namespace internal { | 35 namespace internal { |
| 37 | 36 |
| 38 // Declared in embedder_internal.h. | 37 // Declared in embedder_internal.h. |
| 39 Broker* g_broker = nullptr; | 38 Broker* g_broker = nullptr; |
| 40 PlatformSupport* g_platform_support = nullptr; | 39 PlatformSupport* g_platform_support = nullptr; |
| 41 Core* g_core = nullptr; | 40 Core* g_core = nullptr; |
| 42 | 41 |
| 43 ProcessDelegate* g_process_delegate; | 42 ProcessDelegate* g_process_delegate; |
| 44 base::TaskRunner* g_io_thread_task_runner = nullptr; | 43 base::TaskRunner* g_io_thread_task_runner = nullptr; |
| 45 | 44 |
| 46 Core* GetCore() { | |
| 47 return g_core; | |
| 48 } | |
| 49 | |
| 50 } // namespace internal | 45 } // namespace internal |
| 51 | 46 |
| 52 void SetMaxMessageSize(size_t bytes) { | 47 void SetMaxMessageSize(size_t bytes) { |
| 53 GetMutableConfiguration()->max_message_num_bytes = bytes; | 48 GetMutableConfiguration()->max_message_num_bytes = bytes; |
| 54 } | 49 } |
| 55 | 50 |
| 56 void PreInitializeParentProcess() { | 51 void PreInitializeParentProcess() { |
| 57 BrokerState::GetInstance(); | 52 BrokerState::GetInstance(); |
| 58 } | 53 } |
| 59 | 54 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 70 void ChildProcessLaunched(base::ProcessHandle child_process, | 65 void ChildProcessLaunched(base::ProcessHandle child_process, |
| 71 ScopedPlatformHandle server_pipe) { | 66 ScopedPlatformHandle server_pipe) { |
| 72 new ChildBrokerHost(child_process, std::move(server_pipe)); | 67 new ChildBrokerHost(child_process, std::move(server_pipe)); |
| 73 } | 68 } |
| 74 | 69 |
| 75 void SetParentPipeHandle(ScopedPlatformHandle pipe) { | 70 void SetParentPipeHandle(ScopedPlatformHandle pipe) { |
| 76 ChildBroker::GetInstance()->SetChildBrokerHostHandle(std::move(pipe)); | 71 ChildBroker::GetInstance()->SetChildBrokerHostHandle(std::move(pipe)); |
| 77 } | 72 } |
| 78 | 73 |
| 79 void Init() { | 74 void Init() { |
| 80 const base::CommandLine& command_line = | 75 if (!internal::g_broker) |
| 81 *base::CommandLine::ForCurrentProcess(); | |
| 82 if (command_line.HasSwitch("use-new-edk") && !internal::g_broker) | |
| 83 BrokerState::GetInstance(); | 76 BrokerState::GetInstance(); |
| 84 | 77 |
| 85 DCHECK(!internal::g_platform_support); | 78 DCHECK(!internal::g_platform_support); |
| 86 internal::g_platform_support = new SimplePlatformSupport(); | 79 internal::g_platform_support = new SimplePlatformSupport(); |
| 87 | 80 |
| 88 DCHECK(!internal::g_core); | 81 DCHECK(!internal::g_core); |
| 89 internal::g_core = new Core(internal::g_platform_support); | 82 internal::g_core = new Core(internal::g_platform_support); |
| 90 } | 83 } |
| 91 | 84 |
| 85 void Init(scoped_refptr<base::TaskRunner> io_thread_task_runner) { |
| 86 Init(); |
| 87 DCHECK(!internal::g_io_thread_task_runner); |
| 88 internal::g_io_thread_task_runner = io_thread_task_runner.get(); |
| 89 } |
| 90 |
| 92 MojoResult AsyncWait(MojoHandle handle, | 91 MojoResult AsyncWait(MojoHandle handle, |
| 93 MojoHandleSignals signals, | 92 MojoHandleSignals signals, |
| 94 const base::Callback<void(MojoResult)>& callback) { | 93 const base::Callback<void(MojoResult)>& callback) { |
| 95 return internal::g_core->AsyncWait(handle, signals, callback); | 94 return internal::g_core->AsyncWait(handle, signals, callback); |
| 96 } | 95 } |
| 97 | 96 |
| 98 MojoResult CreatePlatformHandleWrapper( | 97 MojoResult CreatePlatformHandleWrapper( |
| 99 ScopedPlatformHandle platform_handle, | 98 ScopedPlatformHandle platform_handle, |
| 100 MojoHandle* platform_handle_wrapper_handle) { | 99 MojoHandle* platform_handle_wrapper_handle) { |
| 101 DCHECK(platform_handle_wrapper_handle); | 100 DCHECK(platform_handle_wrapper_handle); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 CHECK(rv.is_valid()); | 161 CHECK(rv.is_valid()); |
| 163 dispatcher->Init(std::move(platform_handle), nullptr, 0, nullptr, 0, nullptr, | 162 dispatcher->Init(std::move(platform_handle), nullptr, 0, nullptr, 0, nullptr, |
| 164 nullptr); | 163 nullptr); |
| 165 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it | 164 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it |
| 166 // once that's fixed. | 165 // once that's fixed. |
| 167 return rv; | 166 return rv; |
| 168 } | 167 } |
| 169 | 168 |
| 170 } // namespace edk | 169 } // namespace edk |
| 171 } // namespace mojo | 170 } // namespace mojo |
| OLD | NEW |