OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_ | 5 #ifndef REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_ |
6 #define REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_ | 6 #define REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/win/scoped_handle.h" | 12 #include "base/win/scoped_handle.h" |
13 #include "ipc/ipc_sender.h" | 13 #include "ipc/ipc_sender.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
17 class TimeDelta; | |
17 } // namespace base | 18 } // namespace base |
18 | 19 |
19 namespace IPC { | 20 namespace IPC { |
20 class Listener; | 21 class Listener; |
21 class Message; | 22 class Message; |
22 } // namespace IPC | 23 } // namespace IPC |
23 | 24 |
25 namespace tracked_objects { | |
26 class Location; | |
27 } // namespace tracked_objects | |
28 | |
24 namespace remoting { | 29 namespace remoting { |
25 | 30 |
26 class WorkerProcessIpcDelegate; | 31 class WorkerProcessIpcDelegate; |
27 | 32 |
28 // Launches a worker process that is controlled via an IPC channel. All | 33 // Launches a worker process that is controlled via an IPC channel. All |
29 // interaction with the spawned process is through WorkerProcessIpcDelegate and | 34 // interaction with the spawned process is through WorkerProcessIpcDelegate and |
30 // Send() method. In case of error the channel is closed and the worker process | 35 // Send() method. In case of error the channel is closed and the worker process |
31 // is terminated. | 36 // is terminated. |
32 class WorkerProcessLauncher { | 37 class WorkerProcessLauncher { |
33 public: | 38 public: |
34 class Delegate : public IPC::Sender { | 39 class Delegate : public IPC::Sender { |
35 public: | 40 public: |
36 virtual ~Delegate(); | 41 virtual ~Delegate(); |
37 | 42 |
43 // Closes the IPC channel. | |
44 virtual void CloseChannel() = 0; | |
45 | |
38 // Returns PID of the worker process or 0 if it is not available. | 46 // Returns PID of the worker process or 0 if it is not available. |
39 virtual DWORD GetProcessId() const = 0; | 47 virtual DWORD GetProcessId() const = 0; |
40 | 48 |
41 // Returns true if the worker process should not be restarted any more. | 49 // Returns true if the worker process should not be restarted any more. |
42 virtual bool IsPermanentError(int failure_count) const = 0; | 50 virtual bool IsPermanentError(int failure_count) const = 0; |
43 | 51 |
44 // Terminates the worker process with the given exit code. Destroys the IPC | 52 // Terminates the worker process with the given exit code. Destroys the IPC |
45 // channel created by LaunchProcess(). | 53 // channel created by LaunchProcess(). |
46 virtual void KillProcess(DWORD exit_code) = 0; | 54 virtual void KillProcess(DWORD exit_code) = 0; |
47 | 55 |
(...skipping 13 matching lines...) Expand all Loading... | |
61 // | 69 // |
62 // The caller should call all the methods on this class on | 70 // The caller should call all the methods on this class on |
63 // the |caller_task_runner| thread. Methods of both delegate interfaces are | 71 // the |caller_task_runner| thread. Methods of both delegate interfaces are |
64 // called on the |caller_task_runner| thread as well. | 72 // called on the |caller_task_runner| thread as well. |
65 WorkerProcessLauncher( | 73 WorkerProcessLauncher( |
66 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 74 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
67 scoped_ptr<Delegate> launcher_delegate, | 75 scoped_ptr<Delegate> launcher_delegate, |
68 WorkerProcessIpcDelegate* worker_delegate); | 76 WorkerProcessIpcDelegate* worker_delegate); |
69 ~WorkerProcessLauncher(); | 77 ~WorkerProcessLauncher(); |
70 | 78 |
79 // Asks the worker process to crash and generate a dump, and closes the IPC | |
80 // channel. |location| is passed to the worker so that it is on the stack in | |
81 // the dump. Restarts the worker process forcefully, if it does | |
82 // not exit on its own. | |
83 void Crash(const tracked_objects::Location& location); | |
84 | |
71 // Sends an IPC message to the worker process. The message will be silently | 85 // Sends an IPC message to the worker process. The message will be silently |
72 // dropped if Send() is called before Start() or after stutdown has been | 86 // dropped if Send() is called before Start() or after stutdown has been |
73 // initiated. | 87 // initiated. |
74 void Send(IPC::Message* message); | 88 void Send(IPC::Message* message); |
75 | 89 |
76 private: | 90 private: |
91 friend class WorkerProcessLauncherTest; | |
92 | |
93 // Hooks that allow test code to call the corresponding methods of |Core|. | |
Wez
2013/03/08 01:45:15
nit: Since these are test specific the convention
alexeypa (please no reviews)
2013/03/08 17:43:20
Done.
| |
94 void OnLaunchSuccessTimeout(); | |
95 void SetKillProcessTimeout(const base::TimeDelta& timeout); | |
96 | |
77 // The actual implementation resides in WorkerProcessLauncher::Core class. | 97 // The actual implementation resides in WorkerProcessLauncher::Core class. |
78 class Core; | 98 class Core; |
79 scoped_refptr<Core> core_; | 99 scoped_refptr<Core> core_; |
80 | 100 |
81 DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncher); | 101 DISALLOW_COPY_AND_ASSIGN(WorkerProcessLauncher); |
82 }; | 102 }; |
83 | 103 |
84 } // namespace remoting | 104 } // namespace remoting |
85 | 105 |
86 #endif // REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_ | 106 #endif // REMOTING_HOST_WIN_WORKER_PROCESS_LAUNCHER_H_ |
OLD | NEW |