| 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 CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <cstdio> | 9 #include <cstdio> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| 11 #include <signal.h> | 11 #include <signal.h> |
| 12 | 12 |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "chrome/browser/chromeos/process_proxy/process_output_watcher.h" | 14 #include "chrome/browser/chromeos/process_proxy/process_output_watcher.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class Thread; | 17 class Thread; |
| 18 } // namespace base | 18 } // namespace base |
| 19 | 19 |
| 20 | 20 |
| 21 // Proxy to a single ChromeOS process. | 21 // Proxy to a single ChromeOS process. |
| 22 // This is refcounted. Note that output watcher, when it gets triggered owns a | 22 // This is refcounted. Note that output watcher, when it gets triggered owns a |
| 23 // a callback with ref to this, so in order for this to be freed, the watcher | 23 // a callback with ref to this, so in order for this to be freed, the watcher |
| 24 // must be destroyed. This is done in Close. | 24 // must be destroyed. This is done in Close. |
| 25 class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> { | 25 class ProcessProxy : public base::RefCountedThreadSafe<ProcessProxy> { |
| 26 public: | 26 public: |
| 27 ProcessProxy(); | 27 ProcessProxy(); |
| 28 | 28 |
| 29 // Open a process using command |command|. |pid| is set to new process' pid. | 29 // Opens a process using command |command|. |pid| is set to new process' pid. |
| 30 bool Open(const std::string& command, pid_t* pid); | 30 bool Open(const std::string& command, pid_t* pid); |
| 31 | 31 |
| 32 // Triggers watcher object on |watch_thread|. |watch_thread| gets blocked, so | 32 // Triggers watcher object on |watch_thread|. |watch_thread| gets blocked, so |
| 33 // it should not be one of commonly used threads. It should be thread created | 33 // it should not be one of commonly used threads. It should be thread created |
| 34 // specifically for running process output watcher. | 34 // specifically for running process output watcher. |
| 35 bool StartWatchingOnThread(base::Thread* watch_thread, | 35 bool StartWatchingOnThread(base::Thread* watch_thread, |
| 36 const ProcessOutputCallback& callback); | 36 const ProcessOutputCallback& callback); |
| 37 | 37 |
| 38 // Send some data to the process. | 38 // Sends some data to the process. |
| 39 bool Write(const std::string& text); | 39 bool Write(const std::string& text); |
| 40 | 40 |
| 41 // Close. Must be called if we want this to be eventually deleted. | 41 // Closes the process. |
| 42 // Must be called if we want this to be eventually deleted. |
| 42 void Close(); | 43 void Close(); |
| 43 | 44 |
| 45 // Notifies underlaying process of terminal size change. |
| 46 bool OnTerminalResize(int width, int height); |
| 47 |
| 44 private: | 48 private: |
| 45 friend class base::RefCountedThreadSafe<ProcessProxy>; | 49 friend class base::RefCountedThreadSafe<ProcessProxy>; |
| 46 // We want this be used as ref counted object only. | 50 // We want this be used as ref counted object only. |
| 47 ~ProcessProxy(); | 51 ~ProcessProxy(); |
| 48 | 52 |
| 49 // Create master and slave end of pseudo terminal that will be used to | 53 // Create master and slave end of pseudo terminal that will be used to |
| 50 // communicate with process. | 54 // communicate with process. |
| 51 // pt_pair[0] -> master, pt_pair[1] -> slave. | 55 // pt_pair[0] -> master, pt_pair[1] -> slave. |
| 52 // pt_pair must be allocated (to size at least 2). | 56 // pt_pair must be allocated (to size at least 2). |
| 53 bool CreatePseudoTerminalPair(int *pt_pair); | 57 bool CreatePseudoTerminalPair(int *pt_pair); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 78 | 82 |
| 79 bool watcher_started_; | 83 bool watcher_started_; |
| 80 | 84 |
| 81 int pt_pair_[2]; | 85 int pt_pair_[2]; |
| 82 int shutdown_pipe_[2]; | 86 int shutdown_pipe_[2]; |
| 83 | 87 |
| 84 DISALLOW_COPY_AND_ASSIGN(ProcessProxy); | 88 DISALLOW_COPY_AND_ASSIGN(ProcessProxy); |
| 85 }; | 89 }; |
| 86 | 90 |
| 87 #endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ | 91 #endif // CHROME_BROWSER_CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_H_ |
| OLD | NEW |