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_SERVICE_WIN_H_ 6 #define COMPONENTS_NACL_BROWSER_NACL_BROKER_SERVICE_WIN_H_ 7 8 #include <stdint.h> 9 10 #include <map> 11 12 #include "base/memory/singleton.h" 13 #include "base/memory/weak_ptr.h" 14 #include "base/process/process.h" 15 #include "components/nacl/browser/nacl_broker_host_win.h" 16 #include "mojo/public/cpp/system/message_pipe.h" 17 18 namespace nacl { 19 20 class NaClProcessHost; 21 22 class NaClBrokerService { 23 public: 24 // Returns the NaClBrokerService singleton. 25 static NaClBrokerService* GetInstance(); 26 27 NaClBrokerService(const NaClBrokerService&) = delete; 28 NaClBrokerService& operator=(const NaClBrokerService&) = delete; 29 30 // Can be called several times, must be called before LaunchLoader. 31 bool StartBroker(); 32 33 // Send a message to the broker process, causing it to launch 34 // a Native Client loader process. 35 bool LaunchLoader(base::WeakPtr<NaClProcessHost> client, 36 mojo::ScopedMessagePipeHandle ipc_channel_handle); 37 38 // Called by NaClBrokerHost to notify the service that a loader was launched. 39 void OnLoaderLaunched(int launch_id, base::Process process); 40 41 // Called by NaClProcessHost when a loader process is terminated 42 void OnLoaderDied(); 43 44 bool LaunchDebugExceptionHandler(base::WeakPtr<NaClProcessHost> client, 45 int32_t pid, 46 base::ProcessHandle process_handle, 47 const std::string& startup_info); 48 49 // Called by NaClBrokerHost to notify the service that a debug 50 // exception handler was started. 51 void OnDebugExceptionHandlerLaunched(int32_t pid, bool success); 52 53 private: 54 typedef std::map<int, base::WeakPtr<NaClProcessHost>> PendingLaunchesMap; 55 typedef std::map<int, base::WeakPtr<NaClProcessHost>> 56 PendingDebugExceptionHandlersMap; 57 58 friend struct base::DefaultSingletonTraits<NaClBrokerService>; 59 60 NaClBrokerService(); 61 ~NaClBrokerService(); 62 63 NaClBrokerHost* GetBrokerHost(); 64 65 int loaders_running_; 66 int next_launch_id_ = 0; 67 PendingLaunchesMap pending_launches_; 68 PendingDebugExceptionHandlersMap pending_debuggers_; 69 }; 70 71 } // namespace nacl 72 73 #endif // COMPONENTS_NACL_BROWSER_NACL_BROKER_SERVICE_WIN_H_ 74