Roll v8-i18n 181:182.
[chromium-blink-merge.git] / chromeos / process_proxy / process_output_watcher.h
blob2a58f8a6538e53d20b1b93f51b8def4be751a983
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.
5 #ifndef CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
6 #define CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "chromeos/chromeos_export.h"
13 namespace {
15 const int kReadBufferSize = 256;
17 } // namespace
19 namespace chromeos {
21 enum ProcessOutputType {
22 PROCESS_OUTPUT_TYPE_OUT,
23 PROCESS_OUTPUT_TYPE_ERR,
24 PROCESS_OUTPUT_TYPE_EXIT
27 typedef base::Callback<void(ProcessOutputType, const std::string&)>
28 ProcessOutputCallback;
30 // This class should live on its own thread because running class makes
31 // underlying thread block. It deletes itself when watching is stopped.
32 class CHROMEOS_EXPORT ProcessOutputWatcher {
33 public:
34 ProcessOutputWatcher(int out_fd, int stop_fd,
35 const ProcessOutputCallback& callback);
37 // This will block current thread!!!!
38 void Start();
40 private:
41 // The object will destroy itself when it stops watching process output.
42 ~ProcessOutputWatcher();
44 // Listens to output from supplied fds. It guarantees data written to one fd
45 // will be reported in order that it has been written (this is not true across
46 // fds, it would be nicer if it was).
47 void WatchProcessOutput();
49 // Verifies that fds that we got are properly set.
50 void VerifyFileDescriptor(int fd);
52 // Reads data from fd, and when it's done, invokes callback function.
53 void ReadFromFd(ProcessOutputType type, int* fd);
55 // It will just delete this.
56 void OnStop();
58 char read_buffer_[kReadBufferSize];
59 ssize_t read_buffer_size_;
61 int out_fd_;
62 int stop_fd_;
63 int max_fd_;
65 // Callback that will be invoked when some output is detected.
66 ProcessOutputCallback on_read_callback_;
68 DISALLOW_COPY_AND_ASSIGN(ProcessOutputWatcher);
71 } // namespace chromeos
73 #endif // CHROMEOS_PROCESS_PROXY_PROCESS_OUTPUT_WATCHER_H_