• 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 #ifndef COMPONENTS_NACL_BROWSER_NACL_BROKER_HOST_WIN_H_
6 #define COMPONENTS_NACL_BROWSER_NACL_BROKER_HOST_WIN_H_
7 
8 #include <stdint.h>
9 
10 #include <memory>
11 #include <string>
12 
13 #include "base/process/process.h"
14 #include "content/public/browser/browser_child_process_host_delegate.h"
15 #include "mojo/public/cpp/system/message_pipe.h"
16 
17 namespace content {
18 class BrowserChildProcessHost;
19 }
20 
21 namespace nacl {
22 
23 class NaClBrokerHost : public content::BrowserChildProcessHostDelegate {
24  public:
25   NaClBrokerHost();
26 
27   NaClBrokerHost(const NaClBrokerHost&) = delete;
28   NaClBrokerHost& operator=(const NaClBrokerHost&) = delete;
29 
30   ~NaClBrokerHost() override;
31 
32   // This function starts the broker process. It needs to be called
33   // before loaders can be launched.
34   bool Init();
35 
36   // Send a message to the broker process, causing it to launch
37   // a Native Client loader process.
38   bool LaunchLoader(int launch_id,
39                     mojo::ScopedMessagePipeHandle ipc_channel_handle);
40 
41   bool LaunchDebugExceptionHandler(int32_t pid,
42                                    base::ProcessHandle process_handle,
43                                    const std::string& startup_info);
44 
45   // Stop the broker process.
46   void StopBroker();
47 
48   // Returns true if the process has been asked to terminate. If true, this
49   // object should no longer be used; it will eventually be destroyed by
50   // BrowserChildProcessHostImpl::OnChildDisconnected()
IsTerminating()51   bool IsTerminating() { return is_terminating_; }
52 
53  private:
54   // Handler for NaClProcessMsg_LoaderLaunched message
55   void OnLoaderLaunched(int launch_id, base::ProcessHandle handle);
56 
57   // Handler for NaClProcessMsg_DebugExceptionHandlerLaunched message
58   void OnDebugExceptionHandlerLaunched(int32_t pid, bool success);
59 
60   // BrowserChildProcessHostDelegate implementation:
61   bool OnMessageReceived(const IPC::Message& msg) override;
62 
63   std::unique_ptr<content::BrowserChildProcessHost> process_;
64   bool is_terminating_;
65 };
66 
67 }  // namespace nacl
68 
69 #endif  // COMPONENTS_NACL_BROWSER_NACL_BROKER_HOST_WIN_H_
70