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

Unified Diff: storage/browser/blob/blob_data_builder.cc

Issue 2339933004: [BlobStorage] BlobMemoryController & tests (Closed)
Patch Set: rebase Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: storage/browser/blob/blob_data_builder.cc
diff --git a/storage/browser/blob/blob_data_builder.cc b/storage/browser/blob/blob_data_builder.cc
index 1397cede297e47dbb88f2f52f3fa5f24172c39b9..d6e70b6e6016807c7ede81a5e226e1675ddd50bf 100644
--- a/storage/browser/blob/blob_data_builder.cc
+++ b/storage/browser/blob/blob_data_builder.cc
@@ -12,9 +12,10 @@
#include "base/numerics/safe_conversions.h"
#include "base/numerics/safe_math.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "net/disk_cache/disk_cache.h"
-#include "storage/browser/blob/shareable_file_reference.h"
namespace storage {
@@ -24,8 +25,25 @@ const static int kInvalidDiskCacheSideStreamIndex = -1;
} // namespace
-const char BlobDataBuilder::kAppendFutureFileTemporaryFileName[] =
- "kFakeFilenameToBeChangedByPopulateFutureFile";
+const char BlobDataBuilder::kFutureFileName[] = "_future_name_";
+
+/* static */
+bool BlobDataBuilder::IsFutureFileItem(const DataElement& element) {
+ const std::string prefix(kFutureFileName);
+ const std::string path = element.path().MaybeAsASCII();
+ return path.size() >= prefix.size() &&
+ base::StartsWith(path, prefix, base::CompareCase::SENSITIVE);
+}
+
+/* static */
+uint64_t BlobDataBuilder::GetFutureFileID(const DataElement& element) {
+ DCHECK(IsFutureFileItem(element));
+ uint64_t id = 0;
+ bool success =
+ base::StringToUint64(element.path().BaseName().MaybeAsASCII(), &id);
pwnall 2016/09/21 09:03:35 Won't BaseName be something like "_future_name.42"
dmurph 2016/09/21 23:45:52 Yeah, this was a suggestion that didn't end up wor
+ DCHECK(success) << element.path().Extension();
+ return id;
+}
BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) {
}
@@ -110,11 +128,13 @@ bool BlobDataBuilder::PopulateFutureData(size_t index,
return true;
}
-size_t BlobDataBuilder::AppendFutureFile(uint64_t offset, uint64_t length) {
+size_t BlobDataBuilder::AppendFutureFile(uint64_t offset,
+ uint64_t length,
+ uint64_t file_id) {
CHECK_NE(length, 0ull);
std::unique_ptr<DataElement> element(new DataElement());
- element->SetToFilePathRange(base::FilePath::FromUTF8Unsafe(std::string(
- kAppendFutureFileTemporaryFileName)),
+ element->SetToFilePathRange(base::FilePath::FromUTF8Unsafe(kFutureFileName)
pwnall 2016/09/21 09:03:35 How about pulling out base::FilePath::FromUTF8Unsa
dmurph 2016/09/21 23:45:52 Done.
+ .AddExtension(base::Uint64ToString(file_id)),
offset, length, base::Time());
items_.push_back(new BlobDataItem(std::move(element)));
return items_.size() - 1;
@@ -125,22 +145,20 @@ bool BlobDataBuilder::PopulateFutureFile(
const scoped_refptr<ShareableFileReference>& file_reference,
const base::Time& expected_modification_time) {
DCHECK_LT(index, items_.size());
- DataElement* old_element = items_.at(index)->data_element_ptr();
+ DataElement* element = items_.at(index)->data_element_ptr();
- if (old_element->type() != DataElement::TYPE_FILE) {
+ if (element->type() != DataElement::TYPE_FILE) {
DVLOG(1) << "Invalid item type.";
return false;
- } else if (old_element->path().AsUTF8Unsafe() !=
- std::string(kAppendFutureFileTemporaryFileName)) {
+ } else if (!IsFutureFileItem(*element)) {
DVLOG(1) << "Item not created by AppendFutureFile";
return false;
}
- uint64_t length = old_element->length();
- uint64_t offset = old_element->offset();
- std::unique_ptr<DataElement> element(new DataElement());
+ uint64_t length = element->length();
+ uint64_t offset = element->offset();
+ items_.at(index)->data_handle_ = std::move(file_reference);
pwnall 2016/09/21 09:03:35 I think you can use [] instead of at(), because yo
dmurph 2016/09/21 23:45:52 Done.
element->SetToFilePathRange(file_reference->path(), offset, length,
expected_modification_time);
- items_[index] = new BlobDataItem(std::move(element), file_reference);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698