summaryrefslogtreecommitdiff
path: root/chromium/mojo/public/cpp/system
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/mojo/public/cpp/system')
-rw-r--r--chromium/mojo/public/cpp/system/BUILD.gn3
-rw-r--r--chromium/mojo/public/cpp/system/buffer.h2
-rw-r--r--chromium/mojo/public/cpp/system/data_pipe.h2
-rw-r--r--chromium/mojo/public/cpp/system/data_pipe_producer.cc9
-rw-r--r--chromium/mojo/public/cpp/system/dynamic_library_support.cc64
-rw-r--r--chromium/mojo/public/cpp/system/dynamic_library_support.h45
-rw-r--r--chromium/mojo/public/cpp/system/functions.cc36
-rw-r--r--chromium/mojo/public/cpp/system/functions.h15
-rw-r--r--chromium/mojo/public/cpp/system/handle.h2
-rw-r--r--chromium/mojo/public/cpp/system/message_pipe.h2
-rw-r--r--chromium/mojo/public/cpp/system/platform_handle.h1
11 files changed, 176 insertions, 5 deletions
diff --git a/chromium/mojo/public/cpp/system/BUILD.gn b/chromium/mojo/public/cpp/system/BUILD.gn
index 8608e7b8f0d..7f8eaefbb1f 100644
--- a/chromium/mojo/public/cpp/system/BUILD.gn
+++ b/chromium/mojo/public/cpp/system/BUILD.gn
@@ -17,10 +17,13 @@ component("system") {
"data_pipe_producer.h",
"data_pipe_utils.cc",
"data_pipe_utils.h",
+ "dynamic_library_support.cc",
+ "dynamic_library_support.h",
"file_data_source.cc",
"file_data_source.h",
"filtered_data_source.cc",
"filtered_data_source.h",
+ "functions.cc",
"functions.h",
"handle.h",
"handle_signal_tracker.cc",
diff --git a/chromium/mojo/public/cpp/system/buffer.h b/chromium/mojo/public/cpp/system/buffer.h
index e20a8fe14d9..9b8700badf8 100644
--- a/chromium/mojo/public/cpp/system/buffer.h
+++ b/chromium/mojo/public/cpp/system/buffer.h
@@ -16,8 +16,8 @@
#include <memory>
+#include "base/check_op.h"
#include "base/compiler_specific.h"
-#include "base/logging.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/system_export.h"
diff --git a/chromium/mojo/public/cpp/system/data_pipe.h b/chromium/mojo/public/cpp/system/data_pipe.h
index eb7d6e279ad..6cd2eb35428 100644
--- a/chromium/mojo/public/cpp/system/data_pipe.h
+++ b/chromium/mojo/public/cpp/system/data_pipe.h
@@ -14,8 +14,8 @@
#include <stdint.h>
+#include "base/check.h"
#include "base/compiler_specific.h"
-#include "base/logging.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/cpp/system/handle.h"
diff --git a/chromium/mojo/public/cpp/system/data_pipe_producer.cc b/chromium/mojo/public/cpp/system/data_pipe_producer.cc
index 056620a794d..bb474ca29df 100644
--- a/chromium/mojo/public/cpp/system/data_pipe_producer.cc
+++ b/chromium/mojo/public/cpp/system/data_pipe_producer.cc
@@ -53,6 +53,8 @@ class DataPipeProducer::SequenceState
void Cancel() {
base::AutoLock lock(lock_);
is_cancelled_ = true;
+ owning_task_runner()->PostTask(
+ FROM_HERE, base::BindOnce(&SequenceState::CancelOnSequence, this));
}
void Start(std::unique_ptr<DataSource> data_source) {
@@ -151,6 +153,13 @@ class DataPipeProducer::SequenceState
std::move(producer_handle_), result));
}
+ void CancelOnSequence() {
+ if (!data_source_)
+ return;
+ data_source_->Abort();
+ Finish(MOJO_RESULT_CANCELLED);
+ }
+
const scoped_refptr<base::SequencedTaskRunner> callback_task_runner_;
// State which is effectively owned and used only on the file sequence.
diff --git a/chromium/mojo/public/cpp/system/dynamic_library_support.cc b/chromium/mojo/public/cpp/system/dynamic_library_support.cc
new file mode 100644
index 00000000000..c106778e69c
--- /dev/null
+++ b/chromium/mojo/public/cpp/system/dynamic_library_support.cc
@@ -0,0 +1,64 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/system/dynamic_library_support.h"
+
+#include <stdint.h>
+
+#include "base/command_line.h"
+#include "build/build_config.h"
+#include "mojo/public/c/system/functions.h"
+
+namespace mojo {
+
+namespace {
+
+// Helper for temporary storage related to |MojoInitialize()| calls.
+struct InitializationState {
+ InitializationState(const base::Optional<base::FilePath>& path,
+ MojoInitializeFlags flags) {
+ options.flags = flags;
+
+ if (path) {
+ utf8_path = path->AsUTF8Unsafe();
+ options.mojo_core_path = utf8_path.c_str();
+ options.mojo_core_path_length = static_cast<uint32_t>(utf8_path.size());
+ }
+
+#if defined(OS_POSIX) || defined(OS_FUCHSIA)
+ // Build a temporary reconstructed argv to pass into the library so it can
+ // inspect the application command line if needed.
+ for (const std::string& s : base::CommandLine::ForCurrentProcess()->argv())
+ argv.push_back(s.c_str());
+ options.argc = static_cast<uint32_t>(argv.size());
+ options.argv = argv.data();
+#endif
+ }
+
+ MojoInitializeOptions options = {sizeof(MojoInitializeOptions)};
+ std::string utf8_path;
+ std::vector<const char*> argv;
+};
+
+} // namespace
+
+MojoResult LoadCoreLibrary(base::Optional<base::FilePath> path) {
+ InitializationState state(path, MOJO_INITIALIZE_FLAG_LOAD_ONLY);
+ return MojoInitialize(&state.options);
+}
+
+MojoResult InitializeCoreLibrary(MojoInitializeFlags flags) {
+ DCHECK_EQ(flags & MOJO_INITIALIZE_FLAG_LOAD_ONLY, 0u);
+ InitializationState state(base::nullopt, flags);
+ return MojoInitialize(&state.options);
+}
+
+MojoResult LoadAndInitializeCoreLibrary(base::Optional<base::FilePath> path,
+ MojoInitializeFlags flags) {
+ DCHECK_EQ(flags & MOJO_INITIALIZE_FLAG_LOAD_ONLY, 0u);
+ InitializationState state(path, flags);
+ return MojoInitialize(&state.options);
+}
+
+} // namespace mojo
diff --git a/chromium/mojo/public/cpp/system/dynamic_library_support.h b/chromium/mojo/public/cpp/system/dynamic_library_support.h
new file mode 100644
index 00000000000..97c30427cb6
--- /dev/null
+++ b/chromium/mojo/public/cpp/system/dynamic_library_support.h
@@ -0,0 +1,45 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_PUBLIC_CPP_SYSTEM_DYNAMIC_LIBRARY_SUPPORT_H_
+#define MOJO_PUBLIC_CPP_SYSTEM_DYNAMIC_LIBRARY_SUPPORT_H_
+
+#include "base/files/file_path.h"
+#include "base/optional.h"
+#include "mojo/public/c/system/types.h"
+#include "mojo/public/cpp/system/system_export.h"
+
+namespace mojo {
+
+// Helper to load Mojo Core dynamically from a shared library. If |path| is
+// not given, the library path is assumed to be set in the
+// MOJO_CORE_LIBRARY_PATH environment variable, or the library is searched for
+// in the current working directory.
+//
+// This may only be called in a process that hasn't already initialized Mojo.
+// Mojo is still not fully initialized or usable until |InitializeCoreLibrary()|
+// is also called. These two functions are kept distinct to facilitate use
+// cases where the client application must perform some work (e.g. sandbox
+// configuration, forking, etc) between the loading and initialization steps.
+MOJO_CPP_SYSTEM_EXPORT MojoResult
+LoadCoreLibrary(base::Optional<base::FilePath> path);
+
+// Initializes the dynamic Mojo Core library previously loaded by
+// |LoadCoreLibrary()| above.
+//
+// This may only be called in a process that hasn't already initialized Mojo.
+MOJO_CPP_SYSTEM_EXPORT MojoResult
+InitializeCoreLibrary(MojoInitializeFlags flags);
+
+// Loads and initializes Mojo Core from a shared library. This combines
+// |LoadCoreLibrary()| and |InitializeCoreLibrary()| for convenience in cases
+// where they don't need to be performed at different times by the client
+// application.
+MOJO_CPP_SYSTEM_EXPORT MojoResult
+LoadAndInitializeCoreLibrary(base::Optional<base::FilePath> path,
+ MojoInitializeFlags flags);
+
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_SYSTEM_DYNAMIC_LIBRARY_SUPPORT_H_
diff --git a/chromium/mojo/public/cpp/system/functions.cc b/chromium/mojo/public/cpp/system/functions.cc
new file mode 100644
index 00000000000..74aee1a0973
--- /dev/null
+++ b/chromium/mojo/public/cpp/system/functions.cc
@@ -0,0 +1,36 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/system/functions.h"
+
+#include "base/callback.h"
+#include "base/no_destructor.h"
+
+namespace mojo {
+
+namespace {
+
+DefaultProcessErrorHandler& GetDefaultProcessErrorHandler() {
+ static base::NoDestructor<DefaultProcessErrorHandler> handler;
+ return *handler;
+}
+
+void HandleError(const MojoProcessErrorDetails* details) {
+ const DefaultProcessErrorHandler& handler = GetDefaultProcessErrorHandler();
+ handler.Run(
+ std::string(details->error_message, details->error_message_length));
+}
+
+} // namespace
+
+void SetDefaultProcessErrorHandler(DefaultProcessErrorHandler handler) {
+ // Ensure any previously set handler is wiped out.
+ MojoSetDefaultProcessErrorHandler(nullptr, nullptr);
+ auto& global_handler = GetDefaultProcessErrorHandler();
+ global_handler = std::move(handler);
+ if (global_handler)
+ MojoSetDefaultProcessErrorHandler(&HandleError, nullptr);
+}
+
+} // namespace mojo
diff --git a/chromium/mojo/public/cpp/system/functions.h b/chromium/mojo/public/cpp/system/functions.h
index 31edf57ab54..4f45ecef20c 100644
--- a/chromium/mojo/public/cpp/system/functions.h
+++ b/chromium/mojo/public/cpp/system/functions.h
@@ -11,7 +11,11 @@
#ifndef MOJO_PUBLIC_CPP_SYSTEM_FUNCTIONS_H_
#define MOJO_PUBLIC_CPP_SYSTEM_FUNCTIONS_H_
+#include <string>
+
+#include "base/callback_forward.h"
#include "mojo/public/c/system/functions.h"
+#include "mojo/public/cpp/system/system_export.h"
namespace mojo {
@@ -21,6 +25,17 @@ inline MojoTimeTicks GetTimeTicksNow() {
return MojoGetTimeTicksNow();
}
+// Sets a callback to handle communication errors regarding peer processes whose
+// identity is not explicitly known by this process, i.e. processes that are
+// part of the same Mojo process network but which were not invited by this
+// process.
+//
+// This can be used to globally listen for reports of bad incoming IPCs.
+using DefaultProcessErrorHandler =
+ base::RepeatingCallback<void(const std::string& error)>;
+void MOJO_CPP_SYSTEM_EXPORT
+SetDefaultProcessErrorHandler(DefaultProcessErrorHandler handler);
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_SYSTEM_FUNCTIONS_H_
diff --git a/chromium/mojo/public/cpp/system/handle.h b/chromium/mojo/public/cpp/system/handle.h
index 61e1e570a2b..a0bd46ba2aa 100644
--- a/chromium/mojo/public/cpp/system/handle.h
+++ b/chromium/mojo/public/cpp/system/handle.h
@@ -8,8 +8,8 @@
#include <stdint.h>
#include <limits>
+#include "base/check_op.h"
#include "base/compiler_specific.h"
-#include "base/logging.h"
#include "base/macros.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/types.h"
diff --git a/chromium/mojo/public/cpp/system/message_pipe.h b/chromium/mojo/public/cpp/system/message_pipe.h
index 3803a20dee5..92ac7a5fcba 100644
--- a/chromium/mojo/public/cpp/system/message_pipe.h
+++ b/chromium/mojo/public/cpp/system/message_pipe.h
@@ -16,8 +16,8 @@
#include <vector>
+#include "base/check_op.h"
#include "base/compiler_specific.h"
-#include "base/logging.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/message.h"
diff --git a/chromium/mojo/public/cpp/system/platform_handle.h b/chromium/mojo/public/cpp/system/platform_handle.h
index 297be2263e7..eb69b3e661a 100644
--- a/chromium/mojo/public/cpp/system/platform_handle.h
+++ b/chromium/mojo/public/cpp/system/platform_handle.h
@@ -15,7 +15,6 @@
#include "base/compiler_specific.h"
#include "base/files/platform_file.h"
-#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/unsafe_shared_memory_region.h"