1 // Copyright 2021 The Chromium Authors 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 BASE_FUCHSIA_PROCESS_LIFECYCLE_H_ 6 #define BASE_FUCHSIA_PROCESS_LIFECYCLE_H_ 7 8 #include <fidl/fuchsia.process.lifecycle/cpp/fidl.h> 9 #include <lib/fidl/cpp/binding.h> 10 #include <lib/fidl/cpp/wire/channel.h> 11 12 #include <optional> 13 14 #include "base/base_export.h" 15 #include "base/functional/callback.h" 16 17 namespace base { 18 19 // Registers a fuchsia.process.lifecycle.Lifecycle protocol implementation to 20 // receive graceful termination requests from the Component Framework v2 21 // ELF executable runner. 22 // 23 // The implementation consumes the PA_LIFECYCLE handle, which the ELF runner 24 // will provide only if the Component manifest contains a lifecycle/stop_event 25 // registration. 26 class BASE_EXPORT ProcessLifecycle final 27 : public fidl::Server<fuchsia_process_lifecycle::Lifecycle> { 28 public: 29 explicit ProcessLifecycle(base::OnceClosure on_stop); 30 ~ProcessLifecycle() override; 31 32 ProcessLifecycle(const ProcessLifecycle&) = delete; 33 ProcessLifecycle& operator=(const ProcessLifecycle&) = delete; 34 35 // fuchsia_process_lifecycle::Lifecycle implementation. 36 void Stop(StopCompleter::Sync& completer) override; 37 38 private: 39 base::OnceClosure on_stop_; 40 41 std::optional<fidl::ServerBinding<fuchsia_process_lifecycle::Lifecycle>> 42 binding_; 43 }; 44 45 } // namespace base 46 47 #endif // BASE_FUCHSIA_PROCESS_LIFECYCLE_H_ 48