Home | History | Annotate | Download | only in broker
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      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_BROKER_NACL_BROKER_LISTENER_H_
      6 #define COMPONENTS_NACL_BROKER_NACL_BROKER_LISTENER_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/process/process.h"
     10 #include "components/nacl/common/nacl_types.h"
     11 #include "content/public/common/sandboxed_process_launcher_delegate.h"
     12 #include "ipc/ipc_listener.h"
     13 
     14 namespace IPC {
     15 class Channel;
     16 }
     17 
     18 // The BrokerThread class represents the thread that handles the messages from
     19 // the browser process and starts NaCl loader processes.
     20 class NaClBrokerListener : public content::SandboxedProcessLauncherDelegate,
     21                            public IPC::Listener {
     22  public:
     23   NaClBrokerListener();
     24   ~NaClBrokerListener();
     25 
     26   void Listen();
     27 
     28   // content::SandboxedProcessLauncherDelegate implementation:
     29   virtual void PreSpawnTarget(sandbox::TargetPolicy* policy,
     30                               bool* success) OVERRIDE;
     31 
     32   // IPC::Listener implementation.
     33   virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
     34   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
     35   virtual void OnChannelError() OVERRIDE;
     36 
     37  private:
     38   void OnLaunchLoaderThroughBroker(const std::string& loader_channel_id);
     39   void OnLaunchDebugExceptionHandler(int32 pid,
     40                                      base::ProcessHandle process_handle,
     41                                      const std::string& startup_info);
     42   void OnStopBroker();
     43 
     44   base::ProcessHandle browser_handle_;
     45   scoped_ptr<IPC::Channel> channel_;
     46 
     47   DISALLOW_COPY_AND_ASSIGN(NaClBrokerListener);
     48 };
     49 
     50 #endif  // COMPONENTS_NACL_BROKER_NACL_BROKER_LISTENER_H_
     51