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 CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ | 5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ | 6 #define CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ |
7 | 7 |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 | 10 |
11 #include <cstdio> | 11 #include <cstdio> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "chrome/browser/chromeos/process_proxy/process_output_watcher.h" | 15 #include "chromeos/process_proxy/process_output_watcher.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
| 18 class TaskRunner; |
18 class Thread; | 19 class Thread; |
19 } // namespace base | 20 } // namespace base |
20 | 21 |
| 22 namespace chromeos { |
21 | 23 |
22 // Proxy to a single ChromeOS process. | 24 // Proxy to a single ChromeOS process. |
23 // This is refcounted. Note that output watcher, when it gets triggered owns a | 25 // This is refcounted. Note that output watcher, when it gets triggered owns a |
24 // a callback with ref to this, so in order for this to be freed, the watcher | 26 // a callback with ref to this, so in order for this to be freed, the watcher |
25 // must be destroyed. This is done in Close. | 27 // must be destroyed. This is done in Close. |
26 class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> { | 28 class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> { |
27 public: | 29 public: |
28 ProcessProxy(); | 30 ProcessProxy(); |
29 | 31 |
30 // Opens a process using command |command|. |pid| is set to new process' pid. | 32 // Opens a process using command |command|. |pid| is set to new process' pid. |
(...skipping 24 matching lines...) Expand all Loading... |
55 // communicate with process. | 57 // communicate with process. |
56 // pt_pair[0] -> master, pt_pair[1] -> slave. | 58 // pt_pair[0] -> master, pt_pair[1] -> slave. |
57 // pt_pair must be allocated (to size at least 2). | 59 // pt_pair must be allocated (to size at least 2). |
58 bool CreatePseudoTerminalPair(int *pt_pair); | 60 bool CreatePseudoTerminalPair(int *pt_pair); |
59 | 61 |
60 bool LaunchProcess(const std::string& command, int slave_fd, pid_t* pid); | 62 bool LaunchProcess(const std::string& command, int slave_fd, pid_t* pid); |
61 | 63 |
62 // Gets called by output watcher when the process writes something to its | 64 // Gets called by output watcher when the process writes something to its |
63 // output streams. | 65 // output streams. |
64 void OnProcessOutput(ProcessOutputType type, const std::string& output); | 66 void OnProcessOutput(ProcessOutputType type, const std::string& output); |
| 67 void CallOnProcessOutputCallback(ProcessOutputType type, |
| 68 const std::string& output); |
65 | 69 |
66 bool StopWatching(); | 70 bool StopWatching(); |
67 | 71 |
68 // Methods for cleaning up pipes. | 72 // Methods for cleaning up pipes. |
69 void CloseAllFdPairs(); | 73 void CloseAllFdPairs(); |
70 // Expects array of 2 file descripters. | 74 // Expects array of 2 file descripters. |
71 void CloseFdPair(int* pipe); | 75 void CloseFdPair(int* pipe); |
72 // Expects pointer to single file descriptor. | 76 // Expects pointer to single file descriptor. |
73 void CloseFd(int* fd); | 77 void CloseFd(int* fd); |
74 void ClearAllFdPairs(); | 78 void ClearAllFdPairs(); |
75 // Expects array of 2 file descripters. | 79 // Expects array of 2 file descripters. |
76 void ClearFdPair(int* pipe); | 80 void ClearFdPair(int* pipe); |
77 | 81 |
78 bool process_launched_; | 82 bool process_launched_; |
79 pid_t pid_; | 83 pid_t pid_; |
80 | 84 |
81 bool callback_set_; | 85 bool callback_set_; |
82 ProcessOutputCallback callback_; | 86 ProcessOutputCallback callback_; |
| 87 scoped_refptr<base::TaskRunner> callback_runner_; |
83 | 88 |
84 bool watcher_started_; | 89 bool watcher_started_; |
85 | 90 |
86 int pt_pair_[2]; | 91 int pt_pair_[2]; |
87 int shutdown_pipe_[2]; | 92 int shutdown_pipe_[2]; |
88 | 93 |
89 DISALLOW_COPY_AND_ASSIGN(ProcessProxy); | 94 DISALLOW_COPY_AND_ASSIGN(ProcessProxy); |
90 }; | 95 }; |
91 | 96 |
92 #endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ | 97 } // namespace chromeos |
| 98 |
| 99 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ |
OLD | NEW |