| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 explicit ThrottlingController(ExecutionContext& context) | 127 explicit ThrottlingController(ExecutionContext& context) |
| 128 : Supplement<ExecutionContext>(context), | 128 : Supplement<ExecutionContext>(context), |
| 129 max_running_readers_(kMaxOutstandingRequestsPerThread) {} | 129 max_running_readers_(kMaxOutstandingRequestsPerThread) {} |
| 130 | 130 |
| 131 void PushReader(FileReader* reader) { | 131 void PushReader(FileReader* reader) { |
| 132 if (pending_readers_.IsEmpty() && | 132 if (pending_readers_.IsEmpty() && |
| 133 running_readers_.size() < max_running_readers_) { | 133 running_readers_.size() < max_running_readers_) { |
| 134 reader->ExecutePendingRead(); | 134 reader->ExecutePendingRead(); |
| 135 ASSERT(!running_readers_.Contains(reader)); | 135 DCHECK(!running_readers_.Contains(reader)); |
| 136 running_readers_.insert(reader); | 136 running_readers_.insert(reader); |
| 137 return; | 137 return; |
| 138 } | 138 } |
| 139 pending_readers_.push_back(reader); | 139 pending_readers_.push_back(reader); |
| 140 ExecuteReaders(); | 140 ExecuteReaders(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 FinishReaderType RemoveReader(FileReader* reader) { | 143 FinishReaderType RemoveReader(FileReader* reader) { |
| 144 FileReaderHashSet::const_iterator hash_iter = running_readers_.Find(reader); | 144 FileReaderHashSet::const_iterator hash_iter = running_readers_.Find(reader); |
| 145 if (hash_iter != running_readers_.end()) { | 145 if (hash_iter != running_readers_.end()) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 Terminate(); | 218 Terminate(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 bool FileReader::HasPendingActivity() const { | 221 bool FileReader::HasPendingActivity() const { |
| 222 return state_ == kLoading || still_firing_events_; | 222 return state_ == kLoading || still_firing_events_; |
| 223 } | 223 } |
| 224 | 224 |
| 225 void FileReader::readAsArrayBuffer(Blob* blob, | 225 void FileReader::readAsArrayBuffer(Blob* blob, |
| 226 ExceptionState& exception_state) { | 226 ExceptionState& exception_state) { |
| 227 ASSERT(blob); | 227 DCHECK(blob); |
| 228 DVLOG(1) << "reading as array buffer: " << Utf8BlobUUID(blob).Data() << " " | 228 DVLOG(1) << "reading as array buffer: " << Utf8BlobUUID(blob).Data() << " " |
| 229 << Utf8FilePath(blob).Data(); | 229 << Utf8FilePath(blob).Data(); |
| 230 | 230 |
| 231 ReadInternal(blob, FileReaderLoader::kReadAsArrayBuffer, exception_state); | 231 ReadInternal(blob, FileReaderLoader::kReadAsArrayBuffer, exception_state); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void FileReader::readAsBinaryString(Blob* blob, | 234 void FileReader::readAsBinaryString(Blob* blob, |
| 235 ExceptionState& exception_state) { | 235 ExceptionState& exception_state) { |
| 236 ASSERT(blob); | 236 DCHECK(blob); |
| 237 DVLOG(1) << "reading as binary: " << Utf8BlobUUID(blob).Data() << " " | 237 DVLOG(1) << "reading as binary: " << Utf8BlobUUID(blob).Data() << " " |
| 238 << Utf8FilePath(blob).Data(); | 238 << Utf8FilePath(blob).Data(); |
| 239 | 239 |
| 240 ReadInternal(blob, FileReaderLoader::kReadAsBinaryString, exception_state); | 240 ReadInternal(blob, FileReaderLoader::kReadAsBinaryString, exception_state); |
| 241 } | 241 } |
| 242 | 242 |
| 243 void FileReader::readAsText(Blob* blob, | 243 void FileReader::readAsText(Blob* blob, |
| 244 const String& encoding, | 244 const String& encoding, |
| 245 ExceptionState& exception_state) { | 245 ExceptionState& exception_state) { |
| 246 ASSERT(blob); | 246 DCHECK(blob); |
| 247 DVLOG(1) << "reading as text: " << Utf8BlobUUID(blob).Data() << " " | 247 DVLOG(1) << "reading as text: " << Utf8BlobUUID(blob).Data() << " " |
| 248 << Utf8FilePath(blob).Data(); | 248 << Utf8FilePath(blob).Data(); |
| 249 | 249 |
| 250 encoding_ = encoding; | 250 encoding_ = encoding; |
| 251 ReadInternal(blob, FileReaderLoader::kReadAsText, exception_state); | 251 ReadInternal(blob, FileReaderLoader::kReadAsText, exception_state); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void FileReader::readAsText(Blob* blob, ExceptionState& exception_state) { | 254 void FileReader::readAsText(Blob* blob, ExceptionState& exception_state) { |
| 255 readAsText(blob, String(), exception_state); | 255 readAsText(blob, String(), exception_state); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exception_state) { | 258 void FileReader::readAsDataURL(Blob* blob, ExceptionState& exception_state) { |
| 259 ASSERT(blob); | 259 DCHECK(blob); |
| 260 DVLOG(1) << "reading as data URL: " << Utf8BlobUUID(blob).Data() << " " | 260 DVLOG(1) << "reading as data URL: " << Utf8BlobUUID(blob).Data() << " " |
| 261 << Utf8FilePath(blob).Data(); | 261 << Utf8FilePath(blob).Data(); |
| 262 | 262 |
| 263 ReadInternal(blob, FileReaderLoader::kReadAsDataURL, exception_state); | 263 ReadInternal(blob, FileReaderLoader::kReadAsDataURL, exception_state); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void FileReader::ReadInternal(Blob* blob, | 266 void FileReader::ReadInternal(Blob* blob, |
| 267 FileReaderLoader::ReadType type, | 267 FileReaderLoader::ReadType type, |
| 268 ExceptionState& exception_state) { | 268 ExceptionState& exception_state) { |
| 269 // If multiple concurrent read methods are called on the same FileReader, | 269 // If multiple concurrent read methods are called on the same FileReader, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 299 | 299 |
| 300 // "Snapshot" the Blob data rather than the Blob itself as ongoing | 300 // "Snapshot" the Blob data rather than the Blob itself as ongoing |
| 301 // read operations should not be affected if close() is called on | 301 // read operations should not be affected if close() is called on |
| 302 // the Blob being read. | 302 // the Blob being read. |
| 303 blob_data_handle_ = blob->GetBlobDataHandle(); | 303 blob_data_handle_ = blob->GetBlobDataHandle(); |
| 304 blob_type_ = blob->type(); | 304 blob_type_ = blob->type(); |
| 305 read_type_ = type; | 305 read_type_ = type; |
| 306 state_ = kLoading; | 306 state_ = kLoading; |
| 307 loading_state_ = kLoadingStatePending; | 307 loading_state_ = kLoadingStatePending; |
| 308 error_ = nullptr; | 308 error_ = nullptr; |
| 309 ASSERT(ThrottlingController::From(context)); | 309 DCHECK(ThrottlingController::From(context)); |
| 310 ThrottlingController::PushReader(context, this); | 310 ThrottlingController::PushReader(context, this); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void FileReader::ExecutePendingRead() { | 313 void FileReader::ExecutePendingRead() { |
| 314 ASSERT(loading_state_ == kLoadingStatePending); | 314 DCHECK_EQ(loading_state_, kLoadingStatePending); |
| 315 loading_state_ = kLoadingStateLoading; | 315 loading_state_ = kLoadingStateLoading; |
| 316 | 316 |
| 317 loader_ = FileReaderLoader::Create(read_type_, this); | 317 loader_ = FileReaderLoader::Create(read_type_, this); |
| 318 loader_->SetEncoding(encoding_); | 318 loader_->SetEncoding(encoding_); |
| 319 loader_->SetDataType(blob_type_); | 319 loader_->SetDataType(blob_type_); |
| 320 loader_->Start(GetExecutionContext(), blob_data_handle_); | 320 loader_->Start(GetExecutionContext(), blob_data_handle_); |
| 321 blob_data_handle_ = nullptr; | 321 blob_data_handle_ = nullptr; |
| 322 } | 322 } |
| 323 | 323 |
| 324 void FileReader::abort() { | 324 void FileReader::abort() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 kProgressNotificationIntervalMS) { | 390 kProgressNotificationIntervalMS) { |
| 391 AutoReset<bool> firing_events(&still_firing_events_, true); | 391 AutoReset<bool> firing_events(&still_firing_events_, true); |
| 392 FireEvent(EventTypeNames::progress); | 392 FireEvent(EventTypeNames::progress); |
| 393 last_progress_notification_time_ms_ = now; | 393 last_progress_notification_time_ms_ = now; |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| 397 void FileReader::DidFinishLoading() { | 397 void FileReader::DidFinishLoading() { |
| 398 if (loading_state_ == kLoadingStateAborted) | 398 if (loading_state_ == kLoadingStateAborted) |
| 399 return; | 399 return; |
| 400 ASSERT(loading_state_ == kLoadingStateLoading); | 400 DCHECK_EQ(loading_state_, kLoadingStateLoading); |
| 401 | 401 |
| 402 // TODO(jochen): When we set m_state to DONE below, we still need to fire | 402 // TODO(jochen): When we set m_state to DONE below, we still need to fire |
| 403 // the load and loadend events. To avoid GC to collect this FileReader, we | 403 // the load and loadend events. To avoid GC to collect this FileReader, we |
| 404 // use this separate variable to keep the wrapper of this FileReader alive. | 404 // use this separate variable to keep the wrapper of this FileReader alive. |
| 405 // An alternative would be to keep any ActiveScriptWrappables alive that is on | 405 // An alternative would be to keep any ActiveScriptWrappables alive that is on |
| 406 // the stack. | 406 // the stack. |
| 407 AutoReset<bool> firing_events(&still_firing_events_, true); | 407 AutoReset<bool> firing_events(&still_firing_events_, true); |
| 408 | 408 |
| 409 // It's important that we change m_loadingState before firing any events | 409 // It's important that we change m_loadingState before firing any events |
| 410 // since any of the events could call abort(), which internally checks | 410 // since any of the events could call abort(), which internally checks |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 ProgressEvent::Create(type, false, loader_->BytesLoaded(), 0)); | 467 ProgressEvent::Create(type, false, loader_->BytesLoaded(), 0)); |
| 468 } | 468 } |
| 469 | 469 |
| 470 DEFINE_TRACE(FileReader) { | 470 DEFINE_TRACE(FileReader) { |
| 471 visitor->Trace(error_); | 471 visitor->Trace(error_); |
| 472 EventTargetWithInlineData::Trace(visitor); | 472 EventTargetWithInlineData::Trace(visitor); |
| 473 ContextLifecycleObserver::Trace(visitor); | 473 ContextLifecycleObserver::Trace(visitor); |
| 474 } | 474 } |
| 475 | 475 |
| 476 } // namespace blink | 476 } // namespace blink |
| OLD | NEW |