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