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 3 // found in the LICENSE file. 4 5 #ifndef MOJO_CORE_EMBEDDER_EMBEDDER_H_ 6 #define MOJO_CORE_EMBEDDER_EMBEDDER_H_ 7 8 #include <stddef.h> 9 10 #include <string> 11 12 #include "base/callback.h" 13 #include "base/component_export.h" 14 #include "base/memory/ref_counted.h" 15 #include "base/memory/shared_memory_handle.h" 16 #include "base/process/process_handle.h" 17 #include "base/task_runner.h" 18 #include "build/build_config.h" 19 #include "mojo/core/embedder/configuration.h" 20 21 namespace base { 22 class PortProvider; 23 } 24 25 namespace mojo { 26 namespace core { 27 28 using ProcessErrorCallback = base::Callback<void(const std::string& error)>; 29 30 // Basic configuration/initialization ------------------------------------------ 31 32 // Must be called first, or just after setting configuration parameters, to 33 // initialize the (global, singleton) system state. There is no corresponding 34 // shutdown operation: once the embedder is initialized, public Mojo C API calls 35 // remain available for the remainder of the process's lifetime. 36 COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) 37 void Init(const Configuration& configuration); 38 39 // Like above but uses a default Configuration. 40 COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) void Init(); 41 42 // Sets a default callback to invoke when an internal error is reported but 43 // cannot be associated with a specific child process. Calling this is optional. 44 COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) 45 void SetDefaultProcessErrorCallback(const ProcessErrorCallback& callback); 46 47 // Initialialization/shutdown for interprocess communication (IPC) ------------- 48 49 // Retrieves the TaskRunner used for IPC I/O, as set by ScopedIPCSupport. 50 COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) 51 scoped_refptr<base::TaskRunner> GetIOTaskRunner(); 52 53 #if defined(OS_MACOSX) && !defined(OS_IOS) 54 // Set the |base::PortProvider| for this process. Can be called on any thread, 55 // but must be set in the root process before any Mach ports can be transferred. 56 // 57 // If called at all, this must be called while a ScopedIPCSupport exists. 58 COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) 59 void SetMachPortProvider(base::PortProvider* port_provider); 60 #endif 61 62 } // namespace core 63 } // namespace mojo 64 65 #endif // MOJO_CORE_EMBEDDER_EMBEDDER_H_ 66