1 // 2 // Copyright (C) 2015 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_BLOB_FILE_WRITER_H_ 18 #define UPDATE_ENGINE_PAYLOAD_GENERATOR_BLOB_FILE_WRITER_H_ 19 20 #include <base/macros.h> 21 22 #include <base/synchronization/lock.h> 23 #include <brillo/secure_blob.h> 24 25 namespace chromeos_update_engine { 26 27 class BlobFileWriter { 28 public: 29 // Create the BlobFileWriter object that will manage the blobs stored to 30 // |blob_fd| in a thread safe way. BlobFileWriter(int blob_fd,off_t * blob_file_size)31 BlobFileWriter(int blob_fd, off_t* blob_file_size) 32 : blob_fd_(blob_fd), blob_file_size_(blob_file_size) {} 33 34 // Store the passed |blob| in the blob file. Returns the offset at which it 35 // was stored, or -1 in case of failure. 36 off_t StoreBlob(const brillo::Blob& blob); 37 38 // Increase |total_blobs| by |increment|. Thread safe. 39 void IncTotalBlobs(size_t increment); 40 41 private: 42 size_t total_blobs_{0}; 43 size_t stored_blobs_{0}; 44 45 // The file and its size are protected with the |blob_mutex_|. 46 int blob_fd_; 47 off_t* blob_file_size_; 48 49 base::Lock blob_mutex_; 50 51 DISALLOW_COPY_AND_ASSIGN(BlobFileWriter); 52 }; 53 54 } // namespace chromeos_update_engine 55 56 #endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_BLOB_FILE_WRITER_H_ 57