From 30c270b33ba747bbba6c6611b4e7fea7235501b2 Mon Sep 17 00:00:00 2001 From: "ericu@google.com" Date: Wed, 23 May 2012 20:32:32 +0000 Subject: Revert 138554 - Prevent zero-length items from being appended to a blob. BUG=128266 TEST=as in the bug Review URL: https://chromiumcodereview.appspot.com/10386183 TBR=ericu@chromium.org Review URL: https://chromiumcodereview.appspot.com/10428003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138584 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/blob/blob_data.cc | 33 +--------------------- webkit/blob/blob_data.h | 30 ++++++++++++++++---- webkit/blob/blob_storage_controller.cc | 1 - .../file_system_operation_write_unittest.cc | 1 + 4 files changed, 27 insertions(+), 38 deletions(-) (limited to 'webkit') diff --git a/webkit/blob/blob_data.cc b/webkit/blob/blob_data.cc index fb20ad9..33090e7 100644 --- a/webkit/blob/blob_data.cc +++ b/webkit/blob/blob_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -84,35 +84,4 @@ BlobData::BlobData(const WebBlobData& data) { BlobData::~BlobData() {} -void BlobData::AppendData(const char* data, size_t length) { - DCHECK(length > 0); - items_.push_back(Item()); - items_.back().SetToData(data, length); -} - -void BlobData::AppendFile(const FilePath& file_path, uint64 offset, - uint64 length, - const base::Time& expected_modification_time) { - DCHECK(length > 0); - items_.push_back(Item()); - items_.back().SetToFile(file_path, offset, length, - expected_modification_time); -} - -void BlobData::AppendBlob(const GURL& blob_url, uint64 offset, uint64 length) { - DCHECK(length > 0); - items_.push_back(Item()); - items_.back().SetToBlob(blob_url, offset, length); -} - -int64 BlobData::GetMemoryUsage() const { - int64 memory = 0; - for (std::vector::const_iterator iter = items_.begin(); - iter != items_.end(); ++iter) { - if (iter->type == TYPE_DATA) - memory += iter->data.size(); - } - return memory; -} - } // namespace webkit_blob diff --git a/webkit/blob/blob_data.h b/webkit/blob/blob_data.h index 3d276f0..c1296a3 100644 --- a/webkit/blob/blob_data.h +++ b/webkit/blob/blob_data.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -85,12 +85,24 @@ class BLOB_EXPORT BlobData : public base::RefCounted { AppendData(data.c_str(), data.size()); } - void AppendData(const char* data, size_t length); + void AppendData(const char* data, size_t length) { + if (length > 0) { + items_.push_back(Item()); + items_.back().SetToData(data, length); + } + } void AppendFile(const FilePath& file_path, uint64 offset, uint64 length, - const base::Time& expected_modification_time); + const base::Time& expected_modification_time) { + items_.push_back(Item()); + items_.back().SetToFile(file_path, offset, length, + expected_modification_time); + } - void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length); + void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length) { + items_.push_back(Item()); + items_.back().SetToBlob(blob_url, offset, length); + } void AttachShareableFileReference(ShareableFileReference* reference) { shareable_files_.push_back(reference); @@ -110,7 +122,15 @@ class BLOB_EXPORT BlobData : public base::RefCounted { content_disposition_ = content_disposition; } - int64 GetMemoryUsage() const; + int64 GetMemoryUsage() const { + int64 memory = 0; + for (std::vector::const_iterator iter = items_.begin(); + iter != items_.end(); ++iter) { + if (iter->type == TYPE_DATA) + memory += iter->data.size(); + } + return memory; + } private: friend class base::RefCounted; diff --git a/webkit/blob/blob_storage_controller.cc b/webkit/blob/blob_storage_controller.cc index 9dcbc33..ed617e6 100644 --- a/webkit/blob/blob_storage_controller.cc +++ b/webkit/blob/blob_storage_controller.cc @@ -68,7 +68,6 @@ void BlobStorageController::AppendBlobDataItem( // All the Blob items in the passing blob data are resolved and expanded into // a set of Data and File items. - DCHECK(item.length > 0); switch (item.type) { case BlobData::TYPE_DATA: // WebBlobData does not allow partial data. diff --git a/webkit/fileapi/file_system_operation_write_unittest.cc b/webkit/fileapi/file_system_operation_write_unittest.cc index 2288c82..2b3fec8 100644 --- a/webkit/fileapi/file_system_operation_write_unittest.cc +++ b/webkit/fileapi/file_system_operation_write_unittest.cc @@ -234,6 +234,7 @@ TEST_F(FileSystemOperationWriteTest, TestWriteSuccess) { TEST_F(FileSystemOperationWriteTest, TestWriteZero) { GURL blob_url("blob:zero"); scoped_refptr blob_data(new webkit_blob::BlobData()); + blob_data->AppendData(""); TestURLRequestContext url_request_context; url_request_context.blob_storage_controller()->AddFinishedBlob( -- cgit v1.1