xref: /aosp_15_r20/external/cronet/components/nacl/renderer/plugin/service_runtime.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 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 // A class containing information regarding a socket connection to a
6 // service runtime instance.
7 
8 #ifndef COMPONENTS_NACL_RENDERER_PLUGIN_SERVICE_RUNTIME_H_
9 #define COMPONENTS_NACL_RENDERER_PLUGIN_SERVICE_RUNTIME_H_
10 
11 #include <memory>
12 
13 #include "base/memory/raw_ptr.h"
14 #include "base/process/process_handle.h"
15 #include "components/nacl/renderer/ppb_nacl_private.h"
16 #include "ipc/ipc_sync_channel.h"
17 #include "ppapi/cpp/completion_callback.h"
18 
19 namespace plugin {
20 
21 class Plugin;
22 class ServiceRuntime;
23 
24 // Struct of params used by StartSelLdr.  Use a struct so that callback
25 // creation templates aren't overwhelmed with too many parameters.
26 struct SelLdrStartParams {
SelLdrStartParamsSelLdrStartParams27   SelLdrStartParams(const std::string& url,
28                     const PP_NaClFileInfo& file_info,
29                     PP_NaClAppProcessType process_type)
30       : url(url),
31         file_info(file_info),
32         process_type(process_type) {
33   }
34   std::string url;
35   PP_NaClFileInfo file_info;
36   PP_NaClAppProcessType process_type;
37 };
38 
39 // ServiceRuntime abstracts a NativeClient sel_ldr instance.
40 // TODO(dschuff): Merge this with NaClSubprocess, since, that now only contains
41 // a ServiceRuntime.
42 class ServiceRuntime {
43  public:
44   ServiceRuntime(Plugin* plugin,
45                  PP_Instance pp_instance,
46                  bool main_service_runtime);
47 
48   ServiceRuntime(const ServiceRuntime&) = delete;
49   ServiceRuntime& operator=(const ServiceRuntime&) = delete;
50 
51   // The destructor terminates the sel_ldr process.
52   ~ServiceRuntime();
53 
54   // Spawn the sel_ldr instance.
55   void StartSelLdr(const SelLdrStartParams& params,
56                    pp::CompletionCallback callback);
57 
plugin()58   Plugin* plugin() const { return plugin_; }
59   void Shutdown();
60 
main_service_runtime()61   bool main_service_runtime() const { return main_service_runtime_; }
62 
TakeTranslatorChannel()63   std::unique_ptr<IPC::SyncChannel> TakeTranslatorChannel() {
64     return std::unique_ptr<IPC::SyncChannel>(translator_channel_.release());
65   }
66 
67  private:
68   raw_ptr<Plugin> plugin_;
69   PP_Instance pp_instance_;
70   bool main_service_runtime_;
71 
72   std::unique_ptr<IPC::SyncChannel> translator_channel_;
73 };
74 
75 }  // namespace plugin
76 
77 #endif  // COMPONENTS_NACL_RENDERER_PLUGIN_SERVICE_RUNTIME_H_
78