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