OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS 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. |
| 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_BUFFERED_FILE_WRITER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_BUFFERED_FILE_WRITER_H__ |
| 7 |
| 8 #include <base/scoped_ptr.h> |
| 9 #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 10 |
| 11 #include "update_engine/file_writer.h" |
| 12 |
| 13 // BufferedFileWriter is an implementation of FileWriter that buffers all data |
| 14 // before passing it onto another FileWriter. |
| 15 |
| 16 namespace chromeos_update_engine { |
| 17 |
| 18 class BufferedFileWriter : public FileWriter { |
| 19 public: |
| 20 BufferedFileWriter(FileWriter* next, size_t buffer_size); |
| 21 virtual ~BufferedFileWriter(); |
| 22 |
| 23 virtual int Open(const char* path, int flags, mode_t mode); |
| 24 virtual ssize_t Write(const void* bytes, size_t count); |
| 25 virtual int Close(); |
| 26 |
| 27 private: |
| 28 FRIEND_TEST(BufferedFileWriterTest, CloseErrorTest); |
| 29 FRIEND_TEST(BufferedFileWriterTest, CloseNoDataTest); |
| 30 FRIEND_TEST(BufferedFileWriterTest, CloseWriteErrorTest); |
| 31 FRIEND_TEST(BufferedFileWriterTest, ConstructorTest); |
| 32 FRIEND_TEST(BufferedFileWriterTest, WriteBufferNoDataTest); |
| 33 FRIEND_TEST(BufferedFileWriterTest, WriteBufferTest); |
| 34 FRIEND_TEST(BufferedFileWriterTest, WriteErrorTest); |
| 35 FRIEND_TEST(BufferedFileWriterTest, WriteTest); |
| 36 FRIEND_TEST(BufferedFileWriterTest, WriteWrapBufferTest); |
| 37 |
| 38 // If non-empty, sends the buffer to the next FileWriter. |
| 39 ssize_t WriteBuffer(); |
| 40 |
| 41 // The FileWriter that we write all buffered data to. |
| 42 FileWriter* const next_; |
| 43 |
| 44 scoped_array<char> buffer_; |
| 45 size_t buffer_size_; |
| 46 size_t buffered_bytes_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(BufferedFileWriter); |
| 49 }; |
| 50 |
| 51 } // namespace chromeos_update_engine |
| 52 |
| 53 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_BUFFERED_FILE_WRITER_H__ |
OLD | NEW |