Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 #include "platform/Supplementable.h" | 44 #include "platform/Supplementable.h" |
| 45 #include "wtf/CurrentTime.h" | 45 #include "wtf/CurrentTime.h" |
| 46 #include "wtf/Deque.h" | 46 #include "wtf/Deque.h" |
| 47 #include "wtf/HashSet.h" | 47 #include "wtf/HashSet.h" |
| 48 #include "wtf/text/CString.h" | 48 #include "wtf/text/CString.h" |
| 49 | 49 |
| 50 namespace blink { | 50 namespace blink { |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 #if !LOG_DISABLED | |
| 55 const CString utf8BlobUUID(Blob* blob) | 54 const CString utf8BlobUUID(Blob* blob) |
|
jianli
2016/04/06 20:06:07
Will these 2 functions be included in release buil
| |
| 56 { | 55 { |
| 57 return blob->uuid().utf8(); | 56 return blob->uuid().utf8(); |
| 58 } | 57 } |
| 59 | 58 |
| 60 const CString utf8FilePath(Blob* blob) | 59 const CString utf8FilePath(Blob* blob) |
| 61 { | 60 { |
| 62 return blob->hasBackingFile() ? toFile(blob)->path().utf8() : ""; | 61 return blob->hasBackingFile() ? toFile(blob)->path().utf8() : ""; |
| 63 } | 62 } |
| 64 #endif | |
| 65 | 63 |
| 66 } // namespace | 64 } // namespace |
| 67 | 65 |
| 68 // Embedders like chromium limit the number of simultaneous requests to avoid | 66 // Embedders like chromium limit the number of simultaneous requests to avoid |
| 69 // excessive IPC congestion. We limit this to 100 per thread to throttle the | 67 // excessive IPC congestion. We limit this to 100 per thread to throttle the |
| 70 // requests (the value is arbitrarily chosen). | 68 // requests (the value is arbitrarily chosen). |
| 71 static const size_t kMaxOutstandingRequestsPerThread = 100; | 69 static const size_t kMaxOutstandingRequestsPerThread = 100; |
| 72 static const double progressNotificationIntervalMS = 50; | 70 static const double progressNotificationIntervalMS = 50; |
| 73 | 71 |
| 74 class FileReader::ThrottlingController final : public GarbageCollectedFinalized< FileReader::ThrottlingController>, public Supplement<ExecutionContext> { | 72 class FileReader::ThrottlingController final : public GarbageCollectedFinalized< FileReader::ThrottlingController>, public Supplement<ExecutionContext> { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 } | 230 } |
| 233 | 231 |
| 234 bool FileReader::hasPendingActivity() const | 232 bool FileReader::hasPendingActivity() const |
| 235 { | 233 { |
| 236 return m_state == LOADING; | 234 return m_state == LOADING; |
| 237 } | 235 } |
| 238 | 236 |
| 239 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) | 237 void FileReader::readAsArrayBuffer(Blob* blob, ExceptionState& exceptionState) |
| 240 { | 238 { |
| 241 ASSERT(blob); | 239 ASSERT(blob); |
| 242 WTF_LOG(FileAPI, "FileReader: reading as array buffer: %s %s\n", utf8BlobUUI D(blob).data(), utf8FilePath(blob).data()); | 240 DVLOG(1) << "reading as array buffer: " << utf8BlobUUID(blob).data() << " " << utf8FilePath(blob).data(); |
| 243 | 241 |
| 244 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, exceptionState); | 242 readInternal(blob, FileReaderLoader::ReadAsArrayBuffer, exceptionState); |
| 245 } | 243 } |
| 246 | 244 |
| 247 void FileReader::readAsBinaryString(Blob* blob, ExceptionState& exceptionState) | 245 void FileReader::readAsBinaryString(Blob* blob, ExceptionState& exceptionState) |
| 248 { | 246 { |
| 249 ASSERT(blob); | 247 ASSERT(blob); |
| 250 WTF_LOG(FileAPI, "FileReader: reading as binary: %s %s\n", utf8BlobUUID(blob ).data(), utf8FilePath(blob).data()); | 248 DVLOG(1) << "reading as binary: " << utf8BlobUUID(blob).data() << " " << utf 8FilePath(blob).data(); |
| 251 | 249 |
| 252 readInternal(blob, FileReaderLoader::ReadAsBinaryString, exceptionState); | 250 readInternal(blob, FileReaderLoader::ReadAsBinaryString, exceptionState); |
| 253 } | 251 } |
| 254 | 252 |
| 255 void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState& exceptionState) | 253 void FileReader::readAsText(Blob* blob, const String& encoding, ExceptionState& exceptionState) |
| 256 { | 254 { |
| 257 ASSERT(blob); | 255 ASSERT(blob); |
| 258 WTF_LOG(FileAPI, "FileReader: reading as text: %s %s\n", utf8BlobUUID(blob). data(), utf8FilePath(blob).data()); | 256 DVLOG(1) << "reading as text: " << utf8BlobUUID(blob).data() << " " << utf8F ilePath(blob).data(); |
| 259 | 257 |
| 260 m_encoding = encoding; | 258 m_encoding = encoding; |
| 261 readInternal(blob, FileReaderLoader::ReadAsText, exceptionState); | 259 readInternal(blob, FileReaderLoader::ReadAsText, exceptionState); |
| 262 } | 260 } |
| 263 | 261 |
| 264 void FileReader::readAsText(Blob* blob, ExceptionState& exceptionState) | 262 void FileReader::readAsText(Blob* blob, ExceptionState& exceptionState) |
| 265 { | 263 { |
| 266 readAsText(blob, String(), exceptionState); | 264 readAsText(blob, String(), exceptionState); |
| 267 } | 265 } |
| 268 | 266 |
| 269 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState) | 267 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exceptionState) |
| 270 { | 268 { |
| 271 ASSERT(blob); | 269 ASSERT(blob); |
| 272 WTF_LOG(FileAPI, "FileReader: reading as data URL: %s %s\n", utf8BlobUUID(bl ob).data(), utf8FilePath(blob).data()); | 270 DVLOG(1) << "reading as data URL: " << utf8BlobUUID(blob).data() << " " << u tf8FilePath(blob).data(); |
| 273 | 271 |
| 274 readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState); | 272 readInternal(blob, FileReaderLoader::ReadAsDataURL, exceptionState); |
| 275 } | 273 } |
| 276 | 274 |
| 277 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep tionState& exceptionState) | 275 void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, Excep tionState& exceptionState) |
| 278 { | 276 { |
| 279 // If multiple concurrent read methods are called on the same FileReader, In validStateError should be thrown when the state is LOADING. | 277 // If multiple concurrent read methods are called on the same FileReader, In validStateError should be thrown when the state is LOADING. |
| 280 if (m_state == LOADING) { | 278 if (m_state == LOADING) { |
| 281 exceptionState.throwDOMException(InvalidStateError, "The object is alrea dy busy reading Blobs."); | 279 exceptionState.throwDOMException(InvalidStateError, "The object is alrea dy busy reading Blobs."); |
| 282 return; | 280 return; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 m_blobDataHandle = nullptr; | 322 m_blobDataHandle = nullptr; |
| 325 } | 323 } |
| 326 | 324 |
| 327 static void delayedAbort(FileReader* reader) | 325 static void delayedAbort(FileReader* reader) |
| 328 { | 326 { |
| 329 reader->doAbort(); | 327 reader->doAbort(); |
| 330 } | 328 } |
| 331 | 329 |
| 332 void FileReader::abort() | 330 void FileReader::abort() |
| 333 { | 331 { |
| 334 WTF_LOG(FileAPI, "FileReader: aborting\n"); | 332 DVLOG(1) << "aborting"; |
| 335 | 333 |
| 336 if (m_loadingState != LoadingStateLoading | 334 if (m_loadingState != LoadingStateLoading |
| 337 && m_loadingState != LoadingStatePending) { | 335 && m_loadingState != LoadingStatePending) { |
| 338 return; | 336 return; |
| 339 } | 337 } |
| 340 m_loadingState = LoadingStateAborted; | 338 m_loadingState = LoadingStateAborted; |
| 341 | 339 |
| 342 // Schedule to have the abort done later since abort() might be called from the event handler and we do not want the resource loading code to be in the stac k. | 340 // Schedule to have the abort done later since abort() might be called from the event handler and we do not want the resource loading code to be in the stac k. |
| 343 getExecutionContext()->postTask( | 341 getExecutionContext()->postTask( |
| 344 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, this)); | 342 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, this)); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 } | 465 } |
| 468 | 466 |
| 469 DEFINE_TRACE(FileReader) | 467 DEFINE_TRACE(FileReader) |
| 470 { | 468 { |
| 471 visitor->trace(m_error); | 469 visitor->trace(m_error); |
| 472 RefCountedGarbageCollectedEventTargetWithInlineData<FileReader>::trace(visit or); | 470 RefCountedGarbageCollectedEventTargetWithInlineData<FileReader>::trace(visit or); |
| 473 ActiveDOMObject::trace(visitor); | 471 ActiveDOMObject::trace(visitor); |
| 474 } | 472 } |
| 475 | 473 |
| 476 } // namespace blink | 474 } // namespace blink |
| OLD | NEW |