Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Unified Diff: chromeos/process_proxy/process_output_watcher.h

Issue 261743002: Improve process output watcher's handling of multi-byte UTF8 characters (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chromeos/process_proxy/process_output_watcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/process_proxy/process_output_watcher.h
diff --git a/chromeos/process_proxy/process_output_watcher.h b/chromeos/process_proxy/process_output_watcher.h
index 2a58f8a6538e53d20b1b93f51b8def4be751a983..598fd5fa1e3c72a0f96b2cbe4cdbbc2b32c66041 100644
--- a/chromeos/process_proxy/process_output_watcher.h
+++ b/chromeos/process_proxy/process_output_watcher.h
@@ -10,12 +10,6 @@
#include "base/callback.h"
#include "chromeos/chromeos_export.h"
-namespace {
-
-const int kReadBufferSize = 256;
-
-} // namespace
-
namespace chromeos {
enum ProcessOutputType {
@@ -27,6 +21,9 @@ enum ProcessOutputType {
typedef base::Callback<void(ProcessOutputType, const std::string&)>
ProcessOutputCallback;
+// Observes output on |out_fd| and invokes |callback| when some output is
+// detected. It assumes UTF8 output.
+// If output is detected in |stop_fd|, the watcher is stopped.
// This class should live on its own thread because running class makes
// underlying thread block. It deletes itself when watching is stopped.
class CHROMEOS_EXPORT ProcessOutputWatcher {
@@ -52,11 +49,22 @@ class CHROMEOS_EXPORT ProcessOutputWatcher {
// Reads data from fd, and when it's done, invokes callback function.
void ReadFromFd(ProcessOutputType type, int* fd);
+ // Checks if the read buffer has any trailing incomplete UTF8 characters and
+ // returns the read buffer size without them.
+ size_t OutputSizeWithoutIncompleteUTF8();
+
+ // Processes new |read_buffer_| state and notifies observer about new process
+ // output.
+ void ReportOutput(ProcessOutputType type, size_t new_bytes_count);
+
// It will just delete this.
void OnStop();
- char read_buffer_[kReadBufferSize];
- ssize_t read_buffer_size_;
+ char read_buffer_[256];
+ // Maximum read buffer content size.
+ size_t read_buffer_capacity_;
+ // Current read bufferi content size.
+ size_t read_buffer_size_;
int out_fd_;
int stop_fd_;
« no previous file with comments | « no previous file | chromeos/process_proxy/process_output_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698