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