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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 | 80 |
| 81 void FileWriter::stop() | 81 void FileWriter::stop() |
| 82 { | 82 { |
| 83 // Make sure we've actually got something to stop, and haven't already calle d abort(). | 83 // Make sure we've actually got something to stop, and haven't already calle d abort(). |
| 84 if (!writer() || m_readyState != WRITING) | 84 if (!writer() || m_readyState != WRITING) |
| 85 return; | 85 return; |
| 86 doOperation(OperationAbort); | 86 doOperation(OperationAbort); |
| 87 m_readyState = DONE; | 87 m_readyState = DONE; |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool FileWriter::hasPendingActivity() const | |
| 91 { | |
| 92 return m_operationInProgress != OperationNone || m_queuedOperation != Operat ionNone || m_readyState != DONE; | |
|
tzik
2014/07/11 06:55:47
s/m_readyState != DONE/m_readyState == WRITING/?
kouhei (in TOK)
2014/07/11 07:01:51
Done.
| |
| 93 } | |
| 94 | |
| 90 void FileWriter::write(Blob* data, ExceptionState& exceptionState) | 95 void FileWriter::write(Blob* data, ExceptionState& exceptionState) |
| 91 { | 96 { |
| 92 ASSERT(writer()); | 97 ASSERT(writer()); |
| 93 ASSERT(data); | 98 ASSERT(data); |
| 94 ASSERT(m_truncateLength == -1); | 99 ASSERT(m_truncateLength == -1); |
| 95 if (m_readyState == WRITING) { | 100 if (m_readyState == WRITING) { |
| 96 setError(FileError::INVALID_STATE_ERR, exceptionState); | 101 setError(FileError::INVALID_STATE_ERR, exceptionState); |
| 97 return; | 102 return; |
| 98 } | 103 } |
| 99 if (!data) { | 104 if (!data) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 // already handled the cleanup and signalCompletion call. | 202 // already handled the cleanup and signalCompletion call. |
| 198 double now = currentTimeMS(); | 203 double now = currentTimeMS(); |
| 199 if (complete || !m_lastProgressNotificationTimeMS || (now - m_lastProgressNo tificationTimeMS > progressNotificationIntervalMS)) { | 204 if (complete || !m_lastProgressNotificationTimeMS || (now - m_lastProgressNo tificationTimeMS > progressNotificationIntervalMS)) { |
| 200 m_lastProgressNotificationTimeMS = now; | 205 m_lastProgressNotificationTimeMS = now; |
| 201 fireEvent(EventTypeNames::progress); | 206 fireEvent(EventTypeNames::progress); |
| 202 } | 207 } |
| 203 | 208 |
| 204 if (complete) { | 209 if (complete) { |
| 205 if (numAborts == m_numAborts) | 210 if (numAborts == m_numAborts) |
| 206 signalCompletion(FileError::OK); | 211 signalCompletion(FileError::OK); |
| 207 unsetPendingActivity(this); | |
| 208 } | 212 } |
| 209 } | 213 } |
| 210 | 214 |
| 211 void FileWriter::didTruncate() | 215 void FileWriter::didTruncate() |
| 212 { | 216 { |
| 213 if (m_operationInProgress == OperationAbort) { | 217 if (m_operationInProgress == OperationAbort) { |
| 214 completeAbort(); | 218 completeAbort(); |
| 215 return; | 219 return; |
| 216 } | 220 } |
| 217 ASSERT(m_operationInProgress == OperationTruncate); | 221 ASSERT(m_operationInProgress == OperationTruncate); |
| 218 ASSERT(m_truncateLength >= 0); | 222 ASSERT(m_truncateLength >= 0); |
| 219 setLength(m_truncateLength); | 223 setLength(m_truncateLength); |
| 220 if (position() > length()) | 224 if (position() > length()) |
| 221 setPosition(length()); | 225 setPosition(length()); |
| 222 m_operationInProgress = OperationNone; | 226 m_operationInProgress = OperationNone; |
| 223 signalCompletion(FileError::OK); | 227 signalCompletion(FileError::OK); |
| 224 unsetPendingActivity(this); | |
| 225 } | 228 } |
| 226 | 229 |
| 227 void FileWriter::didFail(blink::WebFileError code) | 230 void FileWriter::didFail(blink::WebFileError code) |
| 228 { | 231 { |
| 229 ASSERT(m_operationInProgress != OperationNone); | 232 ASSERT(m_operationInProgress != OperationNone); |
| 230 ASSERT(static_cast<FileError::ErrorCode>(code) != FileError::OK); | 233 ASSERT(static_cast<FileError::ErrorCode>(code) != FileError::OK); |
| 231 if (m_operationInProgress == OperationAbort) { | 234 if (m_operationInProgress == OperationAbort) { |
| 232 completeAbort(); | 235 completeAbort(); |
| 233 return; | 236 return; |
| 234 } | 237 } |
| 235 ASSERT(m_queuedOperation == OperationNone); | 238 ASSERT(m_queuedOperation == OperationNone); |
| 236 ASSERT(m_readyState == WRITING); | 239 ASSERT(m_readyState == WRITING); |
| 237 m_blobBeingWritten.clear(); | 240 m_blobBeingWritten.clear(); |
| 238 m_operationInProgress = OperationNone; | 241 m_operationInProgress = OperationNone; |
| 239 signalCompletion(static_cast<FileError::ErrorCode>(code)); | 242 signalCompletion(static_cast<FileError::ErrorCode>(code)); |
| 240 unsetPendingActivity(this); | |
| 241 } | 243 } |
| 242 | 244 |
| 243 void FileWriter::completeAbort() | 245 void FileWriter::completeAbort() |
| 244 { | 246 { |
| 245 ASSERT(m_operationInProgress == OperationAbort); | 247 ASSERT(m_operationInProgress == OperationAbort); |
| 246 m_operationInProgress = OperationNone; | 248 m_operationInProgress = OperationNone; |
| 247 Operation operation = m_queuedOperation; | 249 Operation operation = m_queuedOperation; |
| 248 m_queuedOperation = OperationNone; | 250 m_queuedOperation = OperationNone; |
| 249 doOperation(operation); | 251 doOperation(operation); |
| 250 unsetPendingActivity(this); | |
| 251 } | 252 } |
| 252 | 253 |
| 253 void FileWriter::doOperation(Operation operation) | 254 void FileWriter::doOperation(Operation operation) |
| 254 { | 255 { |
| 255 switch (operation) { | 256 switch (operation) { |
| 256 case OperationWrite: | 257 case OperationWrite: |
| 257 ASSERT(m_operationInProgress == OperationNone); | 258 ASSERT(m_operationInProgress == OperationNone); |
| 258 ASSERT(m_truncateLength == -1); | 259 ASSERT(m_truncateLength == -1); |
| 259 ASSERT(m_blobBeingWritten.get()); | 260 ASSERT(m_blobBeingWritten.get()); |
| 260 ASSERT(m_readyState == WRITING); | 261 ASSERT(m_readyState == WRITING); |
| 261 setPendingActivity(this); | |
| 262 writer()->write(position(), m_blobBeingWritten->uuid()); | 262 writer()->write(position(), m_blobBeingWritten->uuid()); |
| 263 break; | 263 break; |
| 264 case OperationTruncate: | 264 case OperationTruncate: |
| 265 ASSERT(m_operationInProgress == OperationNone); | 265 ASSERT(m_operationInProgress == OperationNone); |
| 266 ASSERT(m_truncateLength >= 0); | 266 ASSERT(m_truncateLength >= 0); |
| 267 ASSERT(m_readyState == WRITING); | 267 ASSERT(m_readyState == WRITING); |
| 268 setPendingActivity(this); | |
| 269 writer()->truncate(m_truncateLength); | 268 writer()->truncate(m_truncateLength); |
| 270 break; | 269 break; |
| 271 case OperationNone: | 270 case OperationNone: |
| 272 ASSERT(m_operationInProgress == OperationNone); | 271 ASSERT(m_operationInProgress == OperationNone); |
| 273 ASSERT(m_truncateLength == -1); | 272 ASSERT(m_truncateLength == -1); |
| 274 ASSERT(!m_blobBeingWritten.get()); | 273 ASSERT(!m_blobBeingWritten.get()); |
| 275 ASSERT(m_readyState == DONE); | 274 ASSERT(m_readyState == DONE); |
| 276 break; | 275 break; |
| 277 case OperationAbort: | 276 case OperationAbort: |
| 278 if (m_operationInProgress == OperationWrite || m_operationInProgress == OperationTruncate) | 277 if (m_operationInProgress == OperationWrite || m_operationInProgress == OperationTruncate) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 | 319 |
| 321 void FileWriter::trace(Visitor* visitor) | 320 void FileWriter::trace(Visitor* visitor) |
| 322 { | 321 { |
| 323 visitor->trace(m_error); | 322 visitor->trace(m_error); |
| 324 visitor->trace(m_blobBeingWritten); | 323 visitor->trace(m_blobBeingWritten); |
| 325 FileWriterBase::trace(visitor); | 324 FileWriterBase::trace(visitor); |
| 326 EventTargetWithInlineData::trace(visitor); | 325 EventTargetWithInlineData::trace(visitor); |
| 327 } | 326 } |
| 328 | 327 |
| 329 } // namespace WebCore | 328 } // namespace WebCore |
| OLD | NEW |