Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/common/blob/blob_data.h" | 5 #include "webkit/common/blob/blob_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 | 11 |
| 12 namespace webkit_blob { | 12 namespace webkit_blob { |
| 13 | 13 |
| 14 BlobData::BlobData() {} | 14 BlobData::BlobData() {} |
| 15 BlobData::BlobData(const std::string& uuid) | 15 BlobData::BlobData(const std::string& uuid) |
| 16 : uuid_(uuid) { | 16 : uuid_(uuid) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 BlobData::~BlobData() {} | 19 BlobData::~BlobData() {} |
| 20 | 20 |
| 21 void BlobData::AppendData(const char* data, size_t length) { | 21 void BlobData::AppendData(const char* data, size_t length) { |
| 22 DCHECK(length > 0); | 22 DCHECK(length > 0); |
| 23 items_.push_back(Item()); | 23 items_.push_back(Item()); |
| 24 items_.back().SetToBytes(data, length); | 24 items_.back().SetToBytes(data, length); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void BlobData::AppendFile(const base::FilePath& file_path, | 27 void BlobData::AppendFile(const base::FilePath& file_path, |
| 28 uint64 offset, uint64 length, | 28 uint64 offset, uint64 length, |
| 29 const base::Time& expected_modification_time) { | 29 const base::Time& expected_modification_time) { |
| 30 DCHECK(length > 0); | |
| 31 items_.push_back(Item()); | 30 items_.push_back(Item()); |
| 32 items_.back().SetToFilePathRange(file_path, offset, length, | 31 items_.back().SetToFilePathRange(file_path, offset, length, |
| 33 expected_modification_time); | 32 expected_modification_time); |
| 34 } | 33 } |
| 35 | 34 |
| 36 void BlobData::AppendBlob(const std::string& uuid, | 35 void BlobData::AppendBlob(const std::string& uuid, |
| 37 uint64 offset, uint64 length) { | 36 uint64 offset, uint64 length) { |
| 38 DCHECK_GT(length, 0ul); | 37 DCHECK_GT(length, 0ul); |
|
cmumford
2014/07/31 18:44:43
If's OK to support empty files (which makes sense)
pwnall-personal
2014/07/31 19:34:47
I was not able to trigger this DCHECK... and I tri
| |
| 39 items_.push_back(Item()); | 38 items_.push_back(Item()); |
| 40 items_.back().SetToBlobRange(uuid, offset, length); | 39 items_.back().SetToBlobRange(uuid, offset, length); |
| 41 } | 40 } |
| 42 | 41 |
| 43 void BlobData::AppendFileSystemFile( | 42 void BlobData::AppendFileSystemFile( |
| 44 const GURL& url, uint64 offset, | 43 const GURL& url, uint64 offset, |
| 45 uint64 length, | 44 uint64 length, |
| 46 const base::Time& expected_modification_time) { | 45 const base::Time& expected_modification_time) { |
| 47 DCHECK(length > 0); | |
| 48 items_.push_back(Item()); | 46 items_.push_back(Item()); |
| 49 items_.back().SetToFileSystemUrlRange(url, offset, length, | 47 items_.back().SetToFileSystemUrlRange(url, offset, length, |
| 50 expected_modification_time); | 48 expected_modification_time); |
| 51 } | 49 } |
| 52 | 50 |
| 53 int64 BlobData::GetMemoryUsage() const { | 51 int64 BlobData::GetMemoryUsage() const { |
| 54 int64 memory = 0; | 52 int64 memory = 0; |
| 55 for (std::vector<Item>::const_iterator iter = items_.begin(); | 53 for (std::vector<Item>::const_iterator iter = items_.begin(); |
| 56 iter != items_.end(); ++iter) { | 54 iter != items_.end(); ++iter) { |
| 57 if (iter->type() == Item::TYPE_BYTES) | 55 if (iter->type() == Item::TYPE_BYTES) |
| 58 memory += iter->length(); | 56 memory += iter->length(); |
| 59 } | 57 } |
| 60 return memory; | 58 return memory; |
| 61 } | 59 } |
| 62 | 60 |
| 63 } // namespace webkit_blob | 61 } // namespace webkit_blob |
| OLD | NEW |