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

Side by Side Diff: third_party/WebKit/Source/platform/blob/BlobData.cpp

Issue 2615813003: Migrate WTF::Vector::append() to ::push_back() [part 14 of N] (Closed)
Patch Set: rebase, small fix in FontSettings.h Created 3 years, 11 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 std::unique_ptr<BlobData> BlobData::create() { 76 std::unique_ptr<BlobData> BlobData::create() {
77 return WTF::wrapUnique( 77 return WTF::wrapUnique(
78 new BlobData(FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)); 78 new BlobData(FileCompositionStatus::NO_UNKNOWN_SIZE_FILES));
79 } 79 }
80 80
81 std::unique_ptr<BlobData> BlobData::createForFileWithUnknownSize( 81 std::unique_ptr<BlobData> BlobData::createForFileWithUnknownSize(
82 const String& path) { 82 const String& path) {
83 std::unique_ptr<BlobData> data = WTF::wrapUnique( 83 std::unique_ptr<BlobData> data = WTF::wrapUnique(
84 new BlobData(FileCompositionStatus::SINGLE_UNKNOWN_SIZE_FILE)); 84 new BlobData(FileCompositionStatus::SINGLE_UNKNOWN_SIZE_FILE));
85 data->m_items.append(BlobDataItem(path)); 85 data->m_items.push_back(BlobDataItem(path));
86 return data; 86 return data;
87 } 87 }
88 88
89 void BlobData::detachFromCurrentThread() { 89 void BlobData::detachFromCurrentThread() {
90 m_contentType = m_contentType.isolatedCopy(); 90 m_contentType = m_contentType.isolatedCopy();
91 for (size_t i = 0; i < m_items.size(); ++i) 91 for (size_t i = 0; i < m_items.size(); ++i)
92 m_items.at(i).detachFromCurrentThread(); 92 m_items.at(i).detachFromCurrentThread();
93 } 93 }
94 94
95 void BlobData::setContentType(const String& contentType) { 95 void BlobData::setContentType(const String& contentType) {
96 if (isValidBlobType(contentType)) 96 if (isValidBlobType(contentType))
97 m_contentType = contentType; 97 m_contentType = contentType;
98 else 98 else
99 m_contentType = ""; 99 m_contentType = "";
100 } 100 }
101 101
102 void BlobData::appendData(PassRefPtr<RawData> data, 102 void BlobData::appendData(PassRefPtr<RawData> data,
103 long long offset, 103 long long offset,
104 long long length) { 104 long long length) {
105 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 105 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
106 << "Blobs with a unknown-size file cannot have other items."; 106 << "Blobs with a unknown-size file cannot have other items.";
107 m_items.append(BlobDataItem(std::move(data), offset, length)); 107 m_items.push_back(BlobDataItem(std::move(data), offset, length));
108 } 108 }
109 109
110 void BlobData::appendFile(const String& path, 110 void BlobData::appendFile(const String& path,
111 long long offset, 111 long long offset,
112 long long length, 112 long long length,
113 double expectedModificationTime) { 113 double expectedModificationTime) {
114 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 114 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
115 << "Blobs with a unknown-size file cannot have other items."; 115 << "Blobs with a unknown-size file cannot have other items.";
116 m_items.append(BlobDataItem(path, offset, length, expectedModificationTime)); 116 m_items.push_back(
117 BlobDataItem(path, offset, length, expectedModificationTime));
117 } 118 }
118 119
119 void BlobData::appendBlob(PassRefPtr<BlobDataHandle> dataHandle, 120 void BlobData::appendBlob(PassRefPtr<BlobDataHandle> dataHandle,
120 long long offset, 121 long long offset,
121 long long length) { 122 long long length) {
122 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 123 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
123 << "Blobs with a unknown-size file cannot have other items."; 124 << "Blobs with a unknown-size file cannot have other items.";
124 m_items.append(BlobDataItem(std::move(dataHandle), offset, length)); 125 m_items.push_back(BlobDataItem(std::move(dataHandle), offset, length));
125 } 126 }
126 127
127 void BlobData::appendFileSystemURL(const KURL& url, 128 void BlobData::appendFileSystemURL(const KURL& url,
128 long long offset, 129 long long offset,
129 long long length, 130 long long length,
130 double expectedModificationTime) { 131 double expectedModificationTime) {
131 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 132 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
132 << "Blobs with a unknown-size file cannot have other items."; 133 << "Blobs with a unknown-size file cannot have other items.";
133 m_items.append(BlobDataItem(url, offset, length, expectedModificationTime)); 134 m_items.push_back(
135 BlobDataItem(url, offset, length, expectedModificationTime));
134 } 136 }
135 137
136 void BlobData::appendText(const String& text, 138 void BlobData::appendText(const String& text,
137 bool doNormalizeLineEndingsToNative) { 139 bool doNormalizeLineEndingsToNative) {
138 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 140 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
139 << "Blobs with a unknown-size file cannot have other items."; 141 << "Blobs with a unknown-size file cannot have other items.";
140 CString utf8Text = UTF8Encoding().encode(text, WTF::EntitiesForUnencodables); 142 CString utf8Text = UTF8Encoding().encode(text, WTF::EntitiesForUnencodables);
141 RefPtr<RawData> data = nullptr; 143 RefPtr<RawData> data = nullptr;
142 Vector<char>* buffer; 144 Vector<char>* buffer;
143 if (canConsolidateData(text.length())) { 145 if (canConsolidateData(text.length())) {
144 buffer = m_items.back().data->mutableData(); 146 buffer = m_items.back().data->mutableData();
145 } else { 147 } else {
146 data = RawData::create(); 148 data = RawData::create();
147 buffer = data->mutableData(); 149 buffer = data->mutableData();
148 } 150 }
149 151
150 if (doNormalizeLineEndingsToNative) { 152 if (doNormalizeLineEndingsToNative) {
151 normalizeLineEndingsToNative(utf8Text, *buffer); 153 normalizeLineEndingsToNative(utf8Text, *buffer);
152 } else { 154 } else {
153 buffer->append(utf8Text.data(), utf8Text.length()); 155 buffer->append(utf8Text.data(), utf8Text.length());
154 } 156 }
155 157
156 if (data) 158 if (data)
157 m_items.append(BlobDataItem(data.release())); 159 m_items.push_back(BlobDataItem(data.release()));
158 } 160 }
159 161
160 void BlobData::appendBytes(const void* bytes, size_t length) { 162 void BlobData::appendBytes(const void* bytes, size_t length) {
161 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 163 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
162 << "Blobs with a unknown-size file cannot have other items."; 164 << "Blobs with a unknown-size file cannot have other items.";
163 if (canConsolidateData(length)) { 165 if (canConsolidateData(length)) {
164 m_items.back().data->mutableData()->append(static_cast<const char*>(bytes), 166 m_items.back().data->mutableData()->append(static_cast<const char*>(bytes),
165 length); 167 length);
166 return; 168 return;
167 } 169 }
168 RefPtr<RawData> data = RawData::create(); 170 RefPtr<RawData> data = RawData::create();
169 Vector<char>* buffer = data->mutableData(); 171 Vector<char>* buffer = data->mutableData();
170 buffer->append(static_cast<const char*>(bytes), length); 172 buffer->append(static_cast<const char*>(bytes), length);
171 m_items.append(BlobDataItem(data.release())); 173 m_items.push_back(BlobDataItem(data.release()));
172 } 174 }
173 175
174 long long BlobData::length() const { 176 long long BlobData::length() const {
175 long long length = 0; 177 long long length = 0;
176 178
177 for (Vector<BlobDataItem>::const_iterator it = m_items.begin(); 179 for (Vector<BlobDataItem>::const_iterator it = m_items.begin();
178 it != m_items.end(); ++it) { 180 it != m_items.end(); ++it) {
179 const BlobDataItem& item = *it; 181 const BlobDataItem& item = *it;
180 if (item.length != BlobDataItem::toEndOfFile) { 182 if (item.length != BlobDataItem::toEndOfFile) {
181 ASSERT(item.length >= 0); 183 ASSERT(item.length >= 0);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 m_type(isValidBlobType(type) ? type.isolatedCopy() : ""), 228 m_type(isValidBlobType(type) ? type.isolatedCopy() : ""),
227 m_size(size) { 229 m_size(size) {
228 BlobRegistry::addBlobDataRef(m_uuid); 230 BlobRegistry::addBlobDataRef(m_uuid);
229 } 231 }
230 232
231 BlobDataHandle::~BlobDataHandle() { 233 BlobDataHandle::~BlobDataHandle() {
232 BlobRegistry::removeBlobDataRef(m_uuid); 234 BlobRegistry::removeBlobDataRef(m_uuid);
233 } 235 }
234 236
235 } // namespace blink 237 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/audio/ReverbConvolver.cpp ('k') | third_party/WebKit/Source/platform/exported/WebImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698