| 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/blob/blob_data.h" | 5 #include "webkit/blob/blob_data.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 AppendFile( | 64 AppendFile( |
| 65 WebStringToFilePath(item.filePath), | 65 WebStringToFilePath(item.filePath), |
| 66 static_cast<uint64>(item.offset), | 66 static_cast<uint64>(item.offset), |
| 67 static_cast<uint64>(item.length), | 67 static_cast<uint64>(item.length), |
| 68 base::Time::FromDoubleT(item.expectedModificationTime)); | 68 base::Time::FromDoubleT(item.expectedModificationTime)); |
| 69 } | 69 } |
| 70 break; | 70 break; |
| 71 case WebBlobData::Item::TypeBlob: | 71 case WebBlobData::Item::TypeBlob: |
| 72 if (item.length) { | 72 if (item.length) { |
| 73 AppendBlob( | 73 AppendBlob( |
| 74 item.blobURL, | 74 item.url, |
| 75 static_cast<uint64>(item.offset), | 75 static_cast<uint64>(item.offset), |
| 76 static_cast<uint64>(item.length)); | 76 static_cast<uint64>(item.length)); |
| 77 } | 77 } |
| 78 break; | 78 break; |
| 79 case WebBlobData::Item::TypeURL: |
| 80 if (item.length) { |
| 81 // We only support filesystem URL as of now. |
| 82 DCHECK(GURL(item.url).SchemeIsFileSystem()); |
| 83 AppendFileSystemFile( |
| 84 item.url, |
| 85 static_cast<uint64>(item.offset), |
| 86 static_cast<uint64>(item.length), |
| 87 base::Time::FromDoubleT(item.expectedModificationTime)); |
| 88 } |
| 89 break; |
| 79 default: | 90 default: |
| 80 NOTREACHED(); | 91 NOTREACHED(); |
| 81 } | 92 } |
| 82 } | 93 } |
| 83 content_type_= data.contentType().utf8().data(); | 94 content_type_= data.contentType().utf8().data(); |
| 84 content_disposition_ = data.contentDisposition().utf8().data(); | 95 content_disposition_ = data.contentDisposition().utf8().data(); |
| 85 } | 96 } |
| 86 | 97 |
| 87 BlobData::~BlobData() {} | 98 BlobData::~BlobData() {} |
| 88 | 99 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 100 items_.back().SetToFile(file_path, offset, length, | 111 items_.back().SetToFile(file_path, offset, length, |
| 101 expected_modification_time); | 112 expected_modification_time); |
| 102 } | 113 } |
| 103 | 114 |
| 104 void BlobData::AppendBlob(const GURL& blob_url, uint64 offset, uint64 length) { | 115 void BlobData::AppendBlob(const GURL& blob_url, uint64 offset, uint64 length) { |
| 105 DCHECK(length > 0); | 116 DCHECK(length > 0); |
| 106 items_.push_back(Item()); | 117 items_.push_back(Item()); |
| 107 items_.back().SetToBlob(blob_url, offset, length); | 118 items_.back().SetToBlob(blob_url, offset, length); |
| 108 } | 119 } |
| 109 | 120 |
| 121 void BlobData::AppendFileSystemFile( |
| 122 const GURL& url, uint64 offset, |
| 123 uint64 length, |
| 124 const base::Time& expected_modification_time) { |
| 125 DCHECK(length > 0); |
| 126 items_.push_back(Item()); |
| 127 items_.back().SetToFileSystemFile(url, offset, length, |
| 128 expected_modification_time); |
| 129 } |
| 130 |
| 110 int64 BlobData::GetMemoryUsage() const { | 131 int64 BlobData::GetMemoryUsage() const { |
| 111 int64 memory = 0; | 132 int64 memory = 0; |
| 112 for (std::vector<Item>::const_iterator iter = items_.begin(); | 133 for (std::vector<Item>::const_iterator iter = items_.begin(); |
| 113 iter != items_.end(); ++iter) { | 134 iter != items_.end(); ++iter) { |
| 114 if (iter->type == TYPE_DATA) | 135 if (iter->type == TYPE_DATA) |
| 115 memory += iter->data.size(); | 136 memory += iter->data.size(); |
| 116 } | 137 } |
| 117 return memory; | 138 return memory; |
| 118 } | 139 } |
| 119 | 140 |
| 120 } // namespace webkit_blob | 141 } // namespace webkit_blob |
| OLD | NEW |