Move storage/ to use new base::Pickle functionality
This moves to using the new base::Pickle creation factories, opting for a safer internalized memory. Bug: 330028190 Change-Id: I512ee7441c1914a8b032acfbd5e819667c5cffed Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5378392 Auto-Submit: Avi Drissman <avi@chromium.org> Reviewed-by: Ayu Ishii <ayui@chromium.org> Commit-Queue: Ayu Ishii <ayui@chromium.org> Cr-Commit-Position: refs/heads/main@{#1277003}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
cb579777f9
commit
e0ea4f5f80
storage/browser/file_system
@ -182,18 +182,20 @@ bool FileSystemUsageCache::Read(const base::FilePath& usage_file_path,
|
||||
DCHECK(is_valid);
|
||||
DCHECK(dirty_out);
|
||||
DCHECK(usage_out);
|
||||
|
||||
uint8_t buffer[kUsageFileSize];
|
||||
const char* header;
|
||||
if (usage_file_path.empty() ||
|
||||
!ReadBytes(usage_file_path, base::make_span<kUsageFileSize>(buffer))) {
|
||||
base::span<uint8_t> buffer_span = base::make_span<kUsageFileSize>(buffer);
|
||||
if (usage_file_path.empty() || !ReadBytes(usage_file_path, buffer_span)) {
|
||||
return false;
|
||||
}
|
||||
base::Pickle read_pickle(buffer);
|
||||
base::Pickle read_pickle = base::Pickle::WithData(buffer_span);
|
||||
base::PickleIterator iter(read_pickle);
|
||||
uint32_t dirty = 0;
|
||||
int64_t usage = 0;
|
||||
|
||||
// TODO(crbug.com/1490484): Use base::span here once base::Pickle supports it.
|
||||
// TODO(https://crbug.com/40284755): Use base::span here once base::Pickle
|
||||
// supports it.
|
||||
const char* header;
|
||||
if (!iter.ReadBytes(&header, kUsageFileHeaderSize) ||
|
||||
!iter.ReadBool(is_valid) || !iter.ReadUInt32(&dirty) ||
|
||||
!iter.ReadInt64(&usage)) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <set>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/span.h"
|
||||
#include "base/containers/stack.h"
|
||||
#include "base/files/file_enumerator.h"
|
||||
#include "base/files/file_util.h"
|
||||
@ -219,9 +220,10 @@ bool DatabaseCheckHelper::ScanDatabase() {
|
||||
// value: "<pickled FileInfo>"
|
||||
FileInfo file_info;
|
||||
if (!FileInfoFromPickle(
|
||||
base::Pickle(itr->value().data(), itr->value().size()),
|
||||
&file_info))
|
||||
base::Pickle::WithData(base::as_byte_span(itr->value())),
|
||||
&file_info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FileId file_id = -1;
|
||||
if (!base::StringToInt64(key, &file_id) || file_id < 0)
|
||||
@ -477,7 +479,7 @@ bool SandboxDirectoryDatabase::GetFileInfo(FileId file_id, FileInfo* info) {
|
||||
db_->Get(leveldb::ReadOptions(), file_key, &file_data_string);
|
||||
if (status.ok()) {
|
||||
bool success = FileInfoFromPickle(
|
||||
base::Pickle(file_data_string.data(), file_data_string.length()), info);
|
||||
base::Pickle::WithData(base::as_byte_span(file_data_string)), info);
|
||||
if (!success)
|
||||
return false;
|
||||
if (!VerifyDataPath(info->data_path)) {
|
||||
|
Reference in New Issue
Block a user