void FileWriter::didWrite(long long bytes, bool complete) { if (m_operationInProgress == OperationAbort) { completeAbort(); return; } ASSERT(m_readyState == WRITING); ASSERT(m_truncateLength == -1); ASSERT(m_operationInProgress == OperationWrite); ASSERT(bytes + m_bytesWritten > 0); ASSERT(bytes + m_bytesWritten <= m_bytesToWrite); m_bytesWritten += bytes; ASSERT((m_bytesWritten == m_bytesToWrite) || !complete); setPosition(position() + bytes); if (position() > length()) setLength(position()); if (complete) { m_blobBeingWritten.clear(); m_operationInProgress = OperationNone; } // TODO: Throttle to no more frequently than every 50ms. int numAborts = m_numAborts; fireEvent(eventNames().progressEvent); // We could get an abort in the handler for this event. If we do, it's // already handled the cleanup and signalCompletion call. if (complete) { if (numAborts == m_numAborts) signalCompletion(FileError::OK); unsetPendingActivity(this); } }
void FileWriter::didWrite(long long bytes, bool complete) { if (m_operationInProgress == OperationAbort) { completeAbort(); return; } ASSERT(m_readyState == WRITING); ASSERT(m_truncateLength == -1); ASSERT(m_operationInProgress == OperationWrite); ASSERT(!m_bytesToWrite || bytes + m_bytesWritten > 0); ASSERT(bytes + m_bytesWritten <= m_bytesToWrite); m_bytesWritten += bytes; ASSERT((m_bytesWritten == m_bytesToWrite) || !complete); setPosition(position() + bytes); if (position() > length()) setLength(position()); if (complete) { m_blobBeingWritten.clear(); m_operationInProgress = OperationNone; } int numAborts = m_numAborts; // We could get an abort in the handler for this event. If we do, it's // already handled the cleanup and signalCompletion call. double now = currentTimeMS(); if (complete || !m_lastProgressNotificationTimeMS || (now - m_lastProgressNotificationTimeMS > progressNotificationIntervalMS)) { m_lastProgressNotificationTimeMS = now; fireEvent(EventTypeNames::progress); } if (complete) { if (numAborts == m_numAborts) signalCompletion(FileError::OK); } }
void FileWriter::didFail(WebFileError code) { ASSERT(m_operationInProgress != OperationNone); ASSERT(static_cast<FileError::ErrorCode>(code) != FileError::OK); if (m_operationInProgress == OperationAbort) { completeAbort(); return; } ASSERT(m_queuedOperation == OperationNone); ASSERT(m_readyState == WRITING); m_blobBeingWritten.clear(); m_operationInProgress = OperationNone; signalCompletion(static_cast<FileError::ErrorCode>(code)); }
void FileWriter::didTruncate() { if (m_operationInProgress == OperationAbort) { completeAbort(); return; } ASSERT(m_operationInProgress == OperationTruncate); ASSERT(m_truncateLength >= 0); setLength(m_truncateLength); if (position() > length()) setPosition(length()); m_operationInProgress = OperationNone; signalCompletion(FileError::OK); }
void FileWriter::didFail(FileError::ErrorCode code) { ASSERT(m_operationInProgress != OperationNone); ASSERT(code != FileError::OK); if (m_operationInProgress == OperationAbort) { completeAbort(); return; } ASSERT(code != FileError::ABORT_ERR); ASSERT(m_queuedOperation == OperationNone); ASSERT(m_readyState == WRITING); m_blobBeingWritten.clear(); m_operationInProgress = OperationNone; signalCompletion(code); unsetPendingActivity(this); }