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

Side by Side Diff: third_party/WebKit/Source/core/fileapi/FileReaderLoader.cpp

Issue 2804403003: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in core/fileapi (Closed)
Patch Set: rebase Created 3 years, 8 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // Set m_totalBytes and allocate a buffer based on the specified range. 167 // Set m_totalBytes and allocate a buffer based on the specified range.
168 total_bytes_ = 1LL + range_end_ - range_start_; 168 total_bytes_ = 1LL + range_end_ - range_start_;
169 initial_buffer_length = total_bytes_; 169 initial_buffer_length = total_bytes_;
170 } else { 170 } else {
171 // Nothing is known about the size of the resource. Normalize 171 // Nothing is known about the size of the resource. Normalize
172 // m_totalBytes to -1 and initialize the buffer for receiving with the 172 // m_totalBytes to -1 and initialize the buffer for receiving with the
173 // default size. 173 // default size.
174 total_bytes_ = -1; 174 total_bytes_ = -1;
175 } 175 }
176 176
177 ASSERT(!raw_data_); 177 DCHECK(!raw_data_);
178 178
179 if (read_type_ != kReadByClient) { 179 if (read_type_ != kReadByClient) {
180 // Check that we can cast to unsigned since we have to do 180 // Check that we can cast to unsigned since we have to do
181 // so to call ArrayBuffer's create function. 181 // so to call ArrayBuffer's create function.
182 // FIXME: Support reading more than the current size limit of ArrayBuffer. 182 // FIXME: Support reading more than the current size limit of ArrayBuffer.
183 if (initial_buffer_length > std::numeric_limits<unsigned>::max()) { 183 if (initial_buffer_length > std::numeric_limits<unsigned>::max()) {
184 Failed(FileError::kNotReadableErr); 184 Failed(FileError::kNotReadableErr);
185 return; 185 return;
186 } 186 }
187 187
(...skipping 12 matching lines...) Expand all
200 // Total size is known. Set m_rawData to ignore overflowed data. 200 // Total size is known. Set m_rawData to ignore overflowed data.
201 raw_data_->SetVariableCapacity(false); 201 raw_data_->SetVariableCapacity(false);
202 } 202 }
203 } 203 }
204 204
205 if (client_) 205 if (client_)
206 client_->DidStartLoading(); 206 client_->DidStartLoading();
207 } 207 }
208 208
209 void FileReaderLoader::DidReceiveData(const char* data, unsigned data_length) { 209 void FileReaderLoader::DidReceiveData(const char* data, unsigned data_length) {
210 ASSERT(data); 210 DCHECK(data);
211 211
212 // Bail out if we already encountered an error. 212 // Bail out if we already encountered an error.
213 if (error_code_) 213 if (error_code_)
214 return; 214 return;
215 215
216 if (read_type_ == kReadByClient) { 216 if (read_type_ == kReadByClient) {
217 bytes_loaded_ += data_length; 217 bytes_loaded_ += data_length;
218 218
219 if (client_) 219 if (client_)
220 client_->DidReceiveDataForClient(data, data_length); 220 client_->DidReceiveDataForClient(data, data_length);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 case 403: 277 case 403:
278 return FileError::kSecurityErr; 278 return FileError::kSecurityErr;
279 case 404: 279 case 404:
280 return FileError::kNotFoundErr; 280 return FileError::kNotFoundErr;
281 default: 281 default:
282 return FileError::kNotReadableErr; 282 return FileError::kNotReadableErr;
283 } 283 }
284 } 284 }
285 285
286 DOMArrayBuffer* FileReaderLoader::ArrayBufferResult() { 286 DOMArrayBuffer* FileReaderLoader::ArrayBufferResult() {
287 ASSERT(read_type_ == kReadAsArrayBuffer); 287 DCHECK_EQ(read_type_, kReadAsArrayBuffer);
288 288
289 // If the loading is not started or an error occurs, return an empty result. 289 // If the loading is not started or an error occurs, return an empty result.
290 if (!raw_data_ || error_code_) 290 if (!raw_data_ || error_code_)
291 return nullptr; 291 return nullptr;
292 292
293 if (array_buffer_result_) 293 if (array_buffer_result_)
294 return array_buffer_result_; 294 return array_buffer_result_;
295 295
296 DOMArrayBuffer* result = DOMArrayBuffer::Create(raw_data_->ToArrayBuffer()); 296 DOMArrayBuffer* result = DOMArrayBuffer::Create(raw_data_->ToArrayBuffer());
297 if (finished_loading_) { 297 if (finished_loading_) {
298 array_buffer_result_ = result; 298 array_buffer_result_ = result;
299 } 299 }
300 return result; 300 return result;
301 } 301 }
302 302
303 String FileReaderLoader::StringResult() { 303 String FileReaderLoader::StringResult() {
304 ASSERT(read_type_ != kReadAsArrayBuffer && read_type_ != kReadByClient); 304 DCHECK(read_type_ != kReadAsArrayBuffer && read_type_ != kReadByClient);
tkent 2017/04/09 23:00:20 Split this into two. DCHECK_NE(read_type_, kReadAs
Hwanseung Lee 2017/04/10 15:01:32 Done.
305 305
306 // If the loading is not started or an error occurs, return an empty result. 306 // If the loading is not started or an error occurs, return an empty result.
307 if (!raw_data_ || error_code_) 307 if (!raw_data_ || error_code_)
308 return string_result_; 308 return string_result_;
309 309
310 // If already converted from the raw data, return the result now. 310 // If already converted from the raw data, return the result now.
311 if (is_raw_data_converted_) 311 if (is_raw_data_converted_)
312 return string_result_; 312 return string_result_;
313 313
314 switch (read_type_) { 314 switch (read_type_) {
315 case kReadAsArrayBuffer: 315 case kReadAsArrayBuffer:
316 // No conversion is needed. 316 // No conversion is needed.
317 break; 317 break;
318 case kReadAsBinaryString: 318 case kReadAsBinaryString:
319 string_result_ = raw_data_->ToString(); 319 string_result_ = raw_data_->ToString();
320 is_raw_data_converted_ = true; 320 is_raw_data_converted_ = true;
321 break; 321 break;
322 case kReadAsText: 322 case kReadAsText:
323 ConvertToText(); 323 ConvertToText();
324 break; 324 break;
325 case kReadAsDataURL: 325 case kReadAsDataURL:
326 // Partial data is not supported when reading as data URL. 326 // Partial data is not supported when reading as data URL.
327 if (finished_loading_) 327 if (finished_loading_)
328 ConvertToDataURL(); 328 ConvertToDataURL();
329 break; 329 break;
330 default: 330 default:
331 ASSERT_NOT_REACHED(); 331 NOTREACHED();
332 } 332 }
333 333
334 return string_result_; 334 return string_result_;
335 } 335 }
336 336
337 void FileReaderLoader::ConvertToText() { 337 void FileReaderLoader::ConvertToText() {
338 is_raw_data_converted_ = true; 338 is_raw_data_converted_ = true;
339 339
340 if (!bytes_loaded_) { 340 if (!bytes_loaded_) {
341 string_result_ = ""; 341 string_result_ = "";
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 383
384 string_result_ = builder.ToString(); 384 string_result_ = builder.ToString();
385 } 385 }
386 386
387 void FileReaderLoader::SetEncoding(const String& encoding) { 387 void FileReaderLoader::SetEncoding(const String& encoding) {
388 if (!encoding.IsEmpty()) 388 if (!encoding.IsEmpty())
389 encoding_ = WTF::TextEncoding(encoding); 389 encoding_ = WTF::TextEncoding(encoding);
390 } 390 }
391 391
392 } // namespace blink 392 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698