• 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 REMOTING_HOST_WIN_UNPRIVILEGED_PROCESS_DELEGATE_H_
6 #define REMOTING_HOST_WIN_UNPRIVILEGED_PROCESS_DELEGATE_H_
7 
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/files/file_path.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "base/win/scoped_handle.h"
15 #include "ipc/ipc_listener.h"
16 #include "remoting/host/win/worker_process_launcher.h"
17 
18 namespace base {
19 class CommandLine;
20 class SingleThreadTaskRunner;
21 } // namespace base
22 
23 namespace IPC {
24 class ChannelProxy;
25 class Message;
26 } // namespace IPC
27 
28 namespace remoting {
29 
30 // Implements logic for launching and monitoring a worker process under a less
31 // privileged user account.
32 class UnprivilegedProcessDelegate
33     : public base::NonThreadSafe,
34       public IPC::Listener,
35       public WorkerProcessLauncher::Delegate {
36  public:
37   UnprivilegedProcessDelegate(
38       scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
39       scoped_ptr<base::CommandLine> target_command);
40   virtual ~UnprivilegedProcessDelegate();
41 
42   // WorkerProcessLauncher::Delegate implementation.
43   virtual void LaunchProcess(WorkerProcessLauncher* event_handler) OVERRIDE;
44   virtual void Send(IPC::Message* message) OVERRIDE;
45   virtual void CloseChannel() OVERRIDE;
46   virtual void KillProcess() OVERRIDE;
47 
48  private:
49   // IPC::Listener implementation.
50   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
51   virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
52   virtual void OnChannelError() OVERRIDE;
53 
54   void ReportFatalError();
55   void ReportProcessLaunched(base::win::ScopedHandle worker_process);
56 
57   // The task runner serving job object notifications.
58   scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
59 
60   // Command line of the launched process.
61   scoped_ptr<base::CommandLine> target_command_;
62 
63   // The server end of the IPC channel used to communicate to the worker
64   // process.
65   scoped_ptr<IPC::ChannelProxy> channel_;
66 
67   WorkerProcessLauncher* event_handler_;
68 
69   // The handle of the worker process, if launched.
70   base::win::ScopedHandle worker_process_;
71 
72   DISALLOW_COPY_AND_ASSIGN(UnprivilegedProcessDelegate);
73 };
74 
75 }  // namespace remoting
76 
77 #endif  // REMOTING_HOST_WIN_UNPRIVILEGED_PROCESS_DELEGATE_H_
78