| Index: chromeos/dbus/pipe_string_writer.h
|
| diff --git a/chromeos/dbus/pipe_string_writer.h b/chromeos/dbus/pipe_string_writer.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1232f45eda6fe1a290930ba8abaf133ea96ea136
|
| --- /dev/null
|
| +++ b/chromeos/dbus/pipe_string_writer.h
|
| @@ -0,0 +1,69 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CHROMEOS_DBUS_PIPE_STRING_WRITER_H_
|
| +#define CHROMEOS_DBUS_PIPE_STRING_WRITER_H_
|
| +
|
| +#include <memory>
|
| +#include <string>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/files/scoped_file.h"
|
| +#include "base/macros.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "chromeos/chromeos_export.h"
|
| +
|
| +namespace base {
|
| +class TaskRunner;
|
| +}
|
| +
|
| +namespace net {
|
| +class FileStream;
|
| +class DrainableIOBuffer;
|
| +class StringIOBuffer;
|
| +}
|
| +
|
| +namespace chromeos {
|
| +
|
| +// Simple class to encapsulate sending data to a pipe from a
|
| +// string. To use:
|
| +// - Instantiate the PipeStringWriter with data string.
|
| +// - Call StartIO() which will create the appropriate FDs.
|
| +// - As consumer will be ready to read the data, the PipeStringWriter will
|
| +// write the data into the pipe.
|
| +// - When all the data was sent, the PipeStringWriter calls
|
| +// |callback|.
|
| +class CHROMEOS_EXPORT PipeStringWriter {
|
| + public:
|
| + typedef base::Callback<void(int error_code)> IOCompleteCallback;
|
| +
|
| + PipeStringWriter(const std::string& data,
|
| + const scoped_refptr<base::TaskRunner>& task_runner,
|
| + const IOCompleteCallback& callback);
|
| + virtual ~PipeStringWriter();
|
| +
|
| + // Starts data collection.
|
| + // Returns the read end of the pipe if stream was setup correctly.
|
| + base::ScopedFD StartIO();
|
| +
|
| + private:
|
| + void OnDataWritten(int byte_count);
|
| +
|
| + std::unique_ptr<net::FileStream> data_stream_;
|
| + scoped_refptr<net::StringIOBuffer> string_io_buffer_;
|
| + scoped_refptr<net::DrainableIOBuffer> drainable_io_buffer_;
|
| + scoped_refptr<base::TaskRunner> task_runner_;
|
| + IOCompleteCallback callback_;
|
| +
|
| + // Note: This should remain the last member so it'll be destroyed and
|
| + // invalidate its weak pointers before any other members are destroyed.
|
| + base::WeakPtrFactory<PipeStringWriter> weak_ptr_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PipeStringWriter);
|
| +};
|
| +
|
| +} // namespace chromeos
|
| +
|
| +#endif // CHROMEOS_DBUS_PIPE_STRING_WRITER_H_
|
|
|