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