Home | History | Annotate | Download | only in nacl_host
      1 // Copyright (c) 2011 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 CHROME_BROWSER_NACL_HOST_NACL_BROKER_SERVICE_WIN_H_
      6 #define CHROME_BROWSER_NACL_HOST_NACL_BROKER_SERVICE_WIN_H_
      7 #pragma once
      8 
      9 #include <map>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/singleton.h"
     13 #include "chrome/browser/nacl_host/nacl_broker_host_win.h"
     14 
     15 class NaClProcessHost;
     16 
     17 class NaClBrokerService {
     18  public:
     19   // Returns the NaClBrokerService singleton.
     20   static NaClBrokerService* GetInstance();
     21 
     22   // Can be called several times, must be called before LaunchLoader.
     23   bool StartBroker();
     24 
     25   // Send a message to the broker process, causing it to launch
     26   // a Native Client loader process.
     27   bool LaunchLoader(NaClProcessHost* client,
     28                     const std::wstring& loader_channel_id);
     29 
     30   // Called by NaClBrokerHost to notify the service that a loader was launched.
     31   void OnLoaderLaunched(const std::wstring& channel_id,
     32                         base::ProcessHandle handle);
     33 
     34   // Called by NaClProcessHost when a loader process is terminated
     35   void OnLoaderDied();
     36 
     37  private:
     38   typedef std::map<std::wstring, NaClProcessHost*>
     39       PendingLaunchesMap;
     40 
     41   friend struct DefaultSingletonTraits<NaClBrokerService>;
     42 
     43   NaClBrokerService();
     44   ~NaClBrokerService() {}
     45 
     46   NaClBrokerHost* GetBrokerHost();
     47 
     48   int loaders_running_;
     49   PendingLaunchesMap pending_launches_;
     50 
     51   DISALLOW_COPY_AND_ASSIGN(NaClBrokerService);
     52 };
     53 
     54 #endif  // CHROME_BROWSER_NACL_HOST_NACL_BROKER_SERVICE_WIN_H_
     55