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

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

Issue 2151933003: Change WTF::TemporaryChange to be an alias for AutoReset (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: TemporaryChange -> AutoReset Created 4 years, 5 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 24 matching lines...) Expand all
35 #include "core/dom/CrossThreadTask.h" 35 #include "core/dom/CrossThreadTask.h"
36 #include "core/dom/DOMArrayBuffer.h" 36 #include "core/dom/DOMArrayBuffer.h"
37 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
38 #include "core/dom/ExceptionCode.h" 38 #include "core/dom/ExceptionCode.h"
39 #include "core/dom/ExecutionContext.h" 39 #include "core/dom/ExecutionContext.h"
40 #include "core/events/ProgressEvent.h" 40 #include "core/events/ProgressEvent.h"
41 #include "core/fileapi/File.h" 41 #include "core/fileapi/File.h"
42 #include "core/inspector/InspectorInstrumentation.h" 42 #include "core/inspector/InspectorInstrumentation.h"
43 #include "platform/Logging.h" 43 #include "platform/Logging.h"
44 #include "platform/Supplementable.h" 44 #include "platform/Supplementable.h"
45 #include "wtf/AutoReset.h"
45 #include "wtf/CurrentTime.h" 46 #include "wtf/CurrentTime.h"
46 #include "wtf/Deque.h" 47 #include "wtf/Deque.h"
47 #include "wtf/HashSet.h" 48 #include "wtf/HashSet.h"
48 #include "wtf/TemporaryChange.h"
49 #include "wtf/text/CString.h" 49 #include "wtf/text/CString.h"
50 50
51 namespace blink { 51 namespace blink {
52 52
53 namespace { 53 namespace {
54 54
55 const CString utf8BlobUUID(Blob* blob) 55 const CString utf8BlobUUID(Blob* blob)
56 { 56 {
57 return blob->uuid().utf8(); 57 return blob->uuid().utf8();
58 } 58 }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 m_loadingState = LoadingStateAborted; 336 m_loadingState = LoadingStateAborted;
337 337
338 // 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. 338 // 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.
339 getExecutionContext()->postTask( 339 getExecutionContext()->postTask(
340 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, wrapPersistent(this ))); 340 BLINK_FROM_HERE, createSameThreadTask(&delayedAbort, wrapPersistent(this )));
341 } 341 }
342 342
343 void FileReader::doAbort() 343 void FileReader::doAbort()
344 { 344 {
345 ASSERT(m_state != DONE); 345 ASSERT(m_state != DONE);
346 TemporaryChange<bool> firingEvents(m_stillFiringEvents, true); 346 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
347 347
348 terminate(); 348 terminate();
349 349
350 m_error = FileError::create(FileError::ABORT_ERR); 350 m_error = FileError::create(FileError::ABORT_ERR);
351 351
352 // Unregister the reader. 352 // Unregister the reader.
353 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this); 353 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this);
354 354
355 fireEvent(EventTypeNames::error); 355 fireEvent(EventTypeNames::error);
356 fireEvent(EventTypeNames::abort); 356 fireEvent(EventTypeNames::abort);
(...skipping 19 matching lines...) Expand all
376 if (m_loader) { 376 if (m_loader) {
377 m_loader->cancel(); 377 m_loader->cancel();
378 m_loader = nullptr; 378 m_loader = nullptr;
379 } 379 }
380 m_state = DONE; 380 m_state = DONE;
381 m_loadingState = LoadingStateNone; 381 m_loadingState = LoadingStateNone;
382 } 382 }
383 383
384 void FileReader::didStartLoading() 384 void FileReader::didStartLoading()
385 { 385 {
386 TemporaryChange<bool> firingEvents(m_stillFiringEvents, true); 386 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
387 fireEvent(EventTypeNames::loadstart); 387 fireEvent(EventTypeNames::loadstart);
388 } 388 }
389 389
390 void FileReader::didReceiveData() 390 void FileReader::didReceiveData()
391 { 391 {
392 // Fire the progress event at least every 50ms. 392 // Fire the progress event at least every 50ms.
393 double now = currentTimeMS(); 393 double now = currentTimeMS();
394 if (!m_lastProgressNotificationTimeMS) { 394 if (!m_lastProgressNotificationTimeMS) {
395 m_lastProgressNotificationTimeMS = now; 395 m_lastProgressNotificationTimeMS = now;
396 } else if (now - m_lastProgressNotificationTimeMS > progressNotificationInte rvalMS) { 396 } else if (now - m_lastProgressNotificationTimeMS > progressNotificationInte rvalMS) {
397 TemporaryChange<bool> firingEvents(m_stillFiringEvents, true); 397 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
398 fireEvent(EventTypeNames::progress); 398 fireEvent(EventTypeNames::progress);
399 m_lastProgressNotificationTimeMS = now; 399 m_lastProgressNotificationTimeMS = now;
400 } 400 }
401 } 401 }
402 402
403 void FileReader::didFinishLoading() 403 void FileReader::didFinishLoading()
404 { 404 {
405 if (m_loadingState == LoadingStateAborted) 405 if (m_loadingState == LoadingStateAborted)
406 return; 406 return;
407 ASSERT(m_loadingState == LoadingStateLoading); 407 ASSERT(m_loadingState == LoadingStateLoading);
408 408
409 // TODO(jochen): When we set m_state to DONE below, we still need to fire 409 // TODO(jochen): When we set m_state to DONE below, we still need to fire
410 // the load and loadend events. To avoid GC to collect this FileReader, we 410 // the load and loadend events. To avoid GC to collect this FileReader, we
411 // use this separate variable to keep the wrapper of this FileReader alive. 411 // use this separate variable to keep the wrapper of this FileReader alive.
412 // An alternative would be to keep any active DOM object alive that is on 412 // An alternative would be to keep any active DOM object alive that is on
413 // the stack. 413 // the stack.
414 TemporaryChange<bool> firingEvents(m_stillFiringEvents, true); 414 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
415 415
416 // It's important that we change m_loadingState before firing any events 416 // It's important that we change m_loadingState before firing any events
417 // since any of the events could call abort(), which internally checks 417 // since any of the events could call abort(), which internally checks
418 // if we're still loading (therefore we need abort process) or not. 418 // if we're still loading (therefore we need abort process) or not.
419 m_loadingState = LoadingStateNone; 419 m_loadingState = LoadingStateNone;
420 420
421 fireEvent(EventTypeNames::progress); 421 fireEvent(EventTypeNames::progress);
422 422
423 ASSERT(m_state != DONE); 423 ASSERT(m_state != DONE);
424 m_state = DONE; 424 m_state = DONE;
425 425
426 // Unregister the reader. 426 // Unregister the reader.
427 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this); 427 ThrottlingController::FinishReaderType finalStep = ThrottlingController::rem oveReader(getExecutionContext(), this);
428 428
429 fireEvent(EventTypeNames::load); 429 fireEvent(EventTypeNames::load);
430 fireEvent(EventTypeNames::loadend); 430 fireEvent(EventTypeNames::loadend);
431 431
432 // All possible events have fired and we're done, no more pending activity. 432 // All possible events have fired and we're done, no more pending activity.
433 ThrottlingController::finishReader(getExecutionContext(), this, finalStep); 433 ThrottlingController::finishReader(getExecutionContext(), this, finalStep);
434 } 434 }
435 435
436 void FileReader::didFail(FileError::ErrorCode errorCode) 436 void FileReader::didFail(FileError::ErrorCode errorCode)
437 { 437 {
438 if (m_loadingState == LoadingStateAborted) 438 if (m_loadingState == LoadingStateAborted)
439 return; 439 return;
440 440
441 TemporaryChange<bool> firingEvents(m_stillFiringEvents, true); 441 AutoReset<bool> firingEvents(&m_stillFiringEvents, true);
442 442
443 ASSERT(m_loadingState == LoadingStateLoading); 443 ASSERT(m_loadingState == LoadingStateLoading);
444 m_loadingState = LoadingStateNone; 444 m_loadingState = LoadingStateNone;
445 445
446 ASSERT(m_state != DONE); 446 ASSERT(m_state != DONE);
447 m_state = DONE; 447 m_state = DONE;
448 448
449 m_error = FileError::create(static_cast<FileError::ErrorCode>(errorCode)); 449 m_error = FileError::create(static_cast<FileError::ErrorCode>(errorCode));
450 450
451 // Unregister the reader. 451 // Unregister the reader.
(...skipping 21 matching lines...) Expand all
473 } 473 }
474 474
475 DEFINE_TRACE(FileReader) 475 DEFINE_TRACE(FileReader)
476 { 476 {
477 visitor->trace(m_error); 477 visitor->trace(m_error);
478 EventTargetWithInlineData::trace(visitor); 478 EventTargetWithInlineData::trace(visitor);
479 ActiveDOMObject::trace(visitor); 479 ActiveDOMObject::trace(visitor);
480 } 480 }
481 481
482 } // namespace blink 482 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MemoryCache.cpp ('k') | third_party/WebKit/Source/core/frame/FrameView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698