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

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

Issue 2804403003: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in core/fileapi (Closed)
Patch Set: fix 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 static String GetContentTypeFromFileName(const String& name, 44 static String GetContentTypeFromFileName(const String& name,
45 File::ContentTypeLookupPolicy policy) { 45 File::ContentTypeLookupPolicy policy) {
46 String type; 46 String type;
47 int index = name.ReverseFind('.'); 47 int index = name.ReverseFind('.');
48 if (index != -1) { 48 if (index != -1) {
49 if (policy == File::kWellKnownContentTypes) { 49 if (policy == File::kWellKnownContentTypes) {
50 type = MIMETypeRegistry::GetWellKnownMIMETypeForExtension( 50 type = MIMETypeRegistry::GetWellKnownMIMETypeForExtension(
51 name.Substring(index + 1)); 51 name.Substring(index + 1));
52 } else { 52 } else {
53 ASSERT(policy == File::kAllContentTypes); 53 DCHECK_EQ(policy, File::kAllContentTypes);
54 type = 54 type =
55 MIMETypeRegistry::GetMIMETypeForExtension(name.Substring(index + 1)); 55 MIMETypeRegistry::GetMIMETypeForExtension(name.Substring(index + 1));
56 } 56 }
57 } 57 }
58 return type; 58 return type;
59 } 59 }
60 60
61 static std::unique_ptr<BlobData> CreateBlobDataForFileWithType( 61 static std::unique_ptr<BlobData> CreateBlobDataForFileWithType(
62 const String& path, 62 const String& path,
63 const String& content_type) { 63 const String& content_type) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 return blob_data; 116 return blob_data;
117 } 117 }
118 118
119 // static 119 // static
120 File* File::Create( 120 File* File::Create(
121 ExecutionContext* context, 121 ExecutionContext* context,
122 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& file_bits, 122 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& file_bits,
123 const String& file_name, 123 const String& file_name,
124 const FilePropertyBag& options, 124 const FilePropertyBag& options,
125 ExceptionState& exception_state) { 125 ExceptionState& exception_state) {
126 ASSERT(options.hasType()); 126 DCHECK(options.hasType());
127 127
128 double last_modified; 128 double last_modified;
129 if (options.hasLastModified()) 129 if (options.hasLastModified())
130 last_modified = static_cast<double>(options.lastModified()); 130 last_modified = static_cast<double>(options.lastModified());
131 else 131 else
132 last_modified = CurrentTimeMS(); 132 last_modified = CurrentTimeMS();
133 ASSERT(options.hasEndings()); 133 DCHECK(options.hasEndings());
134 bool normalize_line_endings_to_native = options.endings() == "native"; 134 bool normalize_line_endings_to_native = options.endings() == "native";
135 if (normalize_line_endings_to_native) 135 if (normalize_line_endings_to_native)
136 UseCounter::Count(context, UseCounter::kFileAPINativeLineEndings); 136 UseCounter::Count(context, UseCounter::kFileAPINativeLineEndings);
137 137
138 std::unique_ptr<BlobData> blob_data = BlobData::Create(); 138 std::unique_ptr<BlobData> blob_data = BlobData::Create();
139 blob_data->SetContentType(NormalizeType(options.type())); 139 blob_data->SetContentType(NormalizeType(options.type()));
140 PopulateBlobData(blob_data.get(), file_bits, 140 PopulateBlobData(blob_data.get(), file_bits,
141 normalize_line_endings_to_native); 141 normalize_line_endings_to_native);
142 142
143 long long file_size = blob_data->length(); 143 long long file_size = blob_data->length();
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 CaptureSnapshot(size, modification_time_ms); 322 CaptureSnapshot(size, modification_time_ms);
323 ClampSliceOffsets(size, start, end); 323 ClampSliceOffsets(size, start, end);
324 324
325 long long length = end - start; 325 long long length = end - start;
326 std::unique_ptr<BlobData> blob_data = BlobData::Create(); 326 std::unique_ptr<BlobData> blob_data = BlobData::Create();
327 blob_data->SetContentType(NormalizeType(content_type)); 327 blob_data->SetContentType(NormalizeType(content_type));
328 if (!file_system_url_.IsEmpty()) { 328 if (!file_system_url_.IsEmpty()) {
329 blob_data->AppendFileSystemURL(file_system_url_, start, length, 329 blob_data->AppendFileSystemURL(file_system_url_, start, length,
330 modification_time_ms / kMsPerSecond); 330 modification_time_ms / kMsPerSecond);
331 } else { 331 } else {
332 ASSERT(!path_.IsEmpty()); 332 DCHECK(!path_.IsEmpty());
333 blob_data->AppendFile(path_, start, length, 333 blob_data->AppendFile(path_, start, length,
334 modification_time_ms / kMsPerSecond); 334 modification_time_ms / kMsPerSecond);
335 } 335 }
336 return Blob::Create(BlobDataHandle::Create(std::move(blob_data), length)); 336 return Blob::Create(BlobDataHandle::Create(std::move(blob_data), length));
337 } 337 }
338 338
339 void File::CaptureSnapshot(long long& snapshot_size, 339 void File::CaptureSnapshot(long long& snapshot_size,
340 double& snapshot_modification_time_ms) const { 340 double& snapshot_modification_time_ms) const {
341 if (HasValidSnapshotMetadata()) { 341 if (HasValidSnapshotMetadata()) {
342 snapshot_size = snapshot_size_; 342 snapshot_size = snapshot_size_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 // FIXME: This involves synchronous file operation. We need to figure out how 386 // FIXME: This involves synchronous file operation. We need to figure out how
387 // to make it asynchronous. 387 // to make it asynchronous.
388 long long size; 388 long long size;
389 double modification_time_ms; 389 double modification_time_ms;
390 CaptureSnapshot(size, modification_time_ms); 390 CaptureSnapshot(size, modification_time_ms);
391 if (!file_system_url_.IsEmpty()) { 391 if (!file_system_url_.IsEmpty()) {
392 blob_data.AppendFileSystemURL(file_system_url_, 0, size, 392 blob_data.AppendFileSystemURL(file_system_url_, 0, size,
393 modification_time_ms / kMsPerSecond); 393 modification_time_ms / kMsPerSecond);
394 return; 394 return;
395 } 395 }
396 ASSERT(!path_.IsEmpty()); 396 DCHECK(!path_.IsEmpty());
397 blob_data.AppendFile(path_, 0, size, modification_time_ms / kMsPerSecond); 397 blob_data.AppendFile(path_, 0, size, modification_time_ms / kMsPerSecond);
398 } 398 }
399 399
400 bool File::HasSameSource(const File& other) const { 400 bool File::HasSameSource(const File& other) const {
401 if (has_backing_file_ != other.has_backing_file_) 401 if (has_backing_file_ != other.has_backing_file_)
402 return false; 402 return false;
403 403
404 if (has_backing_file_) 404 if (has_backing_file_)
405 return path_ == other.path_; 405 return path_ == other.path_;
406 406
407 if (file_system_url_.IsEmpty() != other.file_system_url_.IsEmpty()) 407 if (file_system_url_.IsEmpty() != other.file_system_url_.IsEmpty())
408 return false; 408 return false;
409 409
410 if (!file_system_url_.IsEmpty()) 410 if (!file_system_url_.IsEmpty())
411 return file_system_url_ == other.file_system_url_; 411 return file_system_url_ == other.file_system_url_;
412 412
413 return Uuid() == other.Uuid(); 413 return Uuid() == other.Uuid();
414 } 414 }
415 415
416 } // namespace blink 416 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/File.h ('k') | third_party/WebKit/Source/core/fileapi/FileError.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698