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

Side by Side Diff: src/platform/update_engine/file_writer.h

Issue 1800009: AU: SplitWriter class for parsing our full update files. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: fixes for review Created 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__
7 7
8 #include <sys/types.h> 8 #include <sys/types.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <fcntl.h> 10 #include <fcntl.h>
(...skipping 11 matching lines...) Expand all
22 class FileWriter { 22 class FileWriter {
23 public: 23 public:
24 FileWriter() {} 24 FileWriter() {}
25 virtual ~FileWriter() {} 25 virtual ~FileWriter() {}
26 26
27 // Wrapper around open. Returns 0 on success or -errno on error. 27 // Wrapper around open. Returns 0 on success or -errno on error.
28 virtual int Open(const char* path, int flags, mode_t mode) = 0; 28 virtual int Open(const char* path, int flags, mode_t mode) = 0;
29 29
30 // Wrapper around write. Returns bytes written on success or 30 // Wrapper around write. Returns bytes written on success or
31 // -errno on error. 31 // -errno on error.
32 virtual int Write(const void* bytes, size_t count) = 0; 32 virtual ssize_t Write(const void* bytes, size_t count) = 0;
33 33
34 // Wrapper around close. Returns 0 on success or -errno on error. 34 // Wrapper around close. Returns 0 on success or -errno on error.
35 virtual int Close() = 0; 35 virtual int Close() = 0;
36 36
37 private: 37 private:
38 DISALLOW_COPY_AND_ASSIGN(FileWriter); 38 DISALLOW_COPY_AND_ASSIGN(FileWriter);
39 }; 39 };
40 40
41 // Direct file writer is probably the simplest FileWriter implementation. 41 // Direct file writer is probably the simplest FileWriter implementation.
42 // It calls the system calls directly. 42 // It calls the system calls directly.
43 43
44 class DirectFileWriter : public FileWriter { 44 class DirectFileWriter : public FileWriter {
45 public: 45 public:
46 DirectFileWriter() : fd_(-1) {} 46 DirectFileWriter() : fd_(-1) {}
47 virtual ~DirectFileWriter() {} 47 virtual ~DirectFileWriter() {}
48 48
49 virtual int Open(const char* path, int flags, mode_t mode); 49 virtual int Open(const char* path, int flags, mode_t mode);
50 virtual int Write(const void* bytes, size_t count); 50 virtual ssize_t Write(const void* bytes, size_t count);
51 virtual int Close(); 51 virtual int Close();
52 52
53 int fd() const { return fd_; } 53 int fd() const { return fd_; }
54 54
55 private: 55 private:
56 int fd_; 56 int fd_;
57 57
58 DISALLOW_COPY_AND_ASSIGN(DirectFileWriter); 58 DISALLOW_COPY_AND_ASSIGN(DirectFileWriter);
59 }; 59 };
60 60
61 class ScopedFileWriterCloser { 61 class ScopedFileWriterCloser {
62 public: 62 public:
63 explicit ScopedFileWriterCloser(FileWriter* writer) : writer_(writer) {} 63 explicit ScopedFileWriterCloser(FileWriter* writer) : writer_(writer) {}
64 ~ScopedFileWriterCloser() { 64 ~ScopedFileWriterCloser() {
65 int err = writer_->Close(); 65 int err = writer_->Close();
66 if (err) 66 if (err)
67 LOG(ERROR) << "FileWriter::Close failed: " 67 LOG(ERROR) << "FileWriter::Close failed: "
68 << utils::ErrnoNumberAsString(-err); 68 << utils::ErrnoNumberAsString(-err);
69 } 69 }
70 private: 70 private:
71 FileWriter* writer_; 71 FileWriter* writer_;
72 72
73 DISALLOW_COPY_AND_ASSIGN(ScopedFileWriterCloser); 73 DISALLOW_COPY_AND_ASSIGN(ScopedFileWriterCloser);
74 }; 74 };
75 75
76 } // namespace chromeos_update_engine 76 } // namespace chromeos_update_engine
77 77
78 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__ 78 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FILE_WRITER_H__
OLDNEW
« no previous file with comments | « src/platform/update_engine/delta_performer.cc ('k') | src/platform/update_engine/file_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698