This source file includes following definitions.
- error_callback
- error_occurred_
- set_error_occurred
- AddBytesWritten
- IsSnapshotFileWriteComplete
- BytesToRead
#include "chrome/browser/media_galleries/linux/snapshot_file_details.h"
#include "base/numerics/safe_conversions.h"
SnapshotRequestInfo::SnapshotRequestInfo(
const std::string& device_file_path,
const base::FilePath& snapshot_file_path,
const MTPDeviceAsyncDelegate::CreateSnapshotFileSuccessCallback&
success_callback,
const MTPDeviceAsyncDelegate::ErrorCallback& error_callback)
: device_file_path(device_file_path),
snapshot_file_path(snapshot_file_path),
success_callback(success_callback),
error_callback(error_callback) {
}
SnapshotRequestInfo::~SnapshotRequestInfo() {
}
SnapshotFileDetails::SnapshotFileDetails(
const SnapshotRequestInfo& request_info,
const base::File::Info& file_info)
: request_info_(request_info),
file_info_(file_info),
bytes_written_(0),
error_occurred_(false) {
}
SnapshotFileDetails::~SnapshotFileDetails() {
}
void SnapshotFileDetails::set_error_occurred(bool error) {
error_occurred_ = error;
}
bool SnapshotFileDetails::AddBytesWritten(uint32 bytes_written) {
if ((bytes_written == 0) ||
(bytes_written_ > kuint32max - bytes_written) ||
(bytes_written_ + bytes_written > file_info_.size))
return false;
bytes_written_ += bytes_written;
return true;
}
bool SnapshotFileDetails::IsSnapshotFileWriteComplete() const {
return !error_occurred_ && (bytes_written_ == file_info_.size);
}
uint32 SnapshotFileDetails::BytesToRead() const {
static const uint32 kReadChunkSize = 1024 * 1024;
return std::min(
kReadChunkSize,
base::checked_cast<uint32>(file_info_.size) - bytes_written_);
}