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 16 matching lines...) Expand all Loading... | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "modules/filesystem/FileWriter.h" | 31 #include "modules/filesystem/FileWriter.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
| 34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
| 35 #include "core/events/ProgressEvent.h" | 35 #include "core/events/ProgressEvent.h" |
| 36 #include "core/fileapi/Blob.h" | 36 #include "core/fileapi/Blob.h" |
| 37 #include "core/inspector/InspectorInstrumentation.h" | |
| 38 #include "public/platform/WebFileWriter.h" | 37 #include "public/platform/WebFileWriter.h" |
| 39 #include "public/platform/WebURL.h" | 38 #include "public/platform/WebURL.h" |
| 40 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
| 41 | 40 |
| 42 namespace blink { | 41 namespace blink { |
| 43 | 42 |
| 44 static const int kMaxRecursionDepth = 3; | 43 static const int kMaxRecursionDepth = 3; |
| 45 static const double progressNotificationIntervalMS = 50; | 44 static const double progressNotificationIntervalMS = 50; |
| 46 | 45 |
| 47 FileWriter* FileWriter::create(ExecutionContext* context) | 46 FileWriter* FileWriter::create(ExecutionContext* context) |
| 48 { | 47 { |
| 49 FileWriter* fileWriter = new FileWriter(context); | 48 FileWriter* fileWriter = new FileWriter(context); |
| 50 fileWriter->suspendIfNeeded(); | 49 fileWriter->suspendIfNeeded(); |
| 51 return fileWriter; | 50 return fileWriter; |
| 52 } | 51 } |
| 53 | 52 |
| 54 FileWriter::FileWriter(ExecutionContext* context) | 53 FileWriter::FileWriter(ExecutionContext* context) |
| 55 : ActiveScriptWrappable(this) | 54 : ActiveScriptWrappable(this) |
| 56 , ActiveDOMObject(context) | 55 , ActiveDOMObject(context) |
| 57 , m_readyState(INIT) | 56 , m_readyState(INIT) |
| 58 , m_operationInProgress(OperationNone) | 57 , m_operationInProgress(OperationNone) |
| 59 , m_queuedOperation(OperationNone) | 58 , m_queuedOperation(OperationNone) |
| 60 , m_bytesWritten(0) | 59 , m_bytesWritten(0) |
| 61 , m_bytesToWrite(0) | 60 , m_bytesToWrite(0) |
| 62 , m_truncateLength(-1) | 61 , m_truncateLength(-1) |
| 63 , m_numAborts(0) | 62 , m_numAborts(0) |
| 64 , m_recursionDepth(0) | 63 , m_recursionDepth(0) |
| 65 , m_lastProgressNotificationTimeMS(0) | 64 , m_lastProgressNotificationTimeMS(0) |
| 66 , m_asyncOperationId(0) | |
| 67 { | 65 { |
| 68 } | 66 } |
| 69 | 67 |
| 70 FileWriter::~FileWriter() | 68 FileWriter::~FileWriter() |
| 71 { | 69 { |
| 72 ASSERT(!m_recursionDepth); | 70 ASSERT(!m_recursionDepth); |
| 73 if (m_readyState == WRITING) | 71 if (m_readyState == WRITING) |
| 74 stop(); | 72 stop(); |
| 75 } | 73 } |
| 76 | 74 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 { | 241 { |
| 244 ASSERT(m_operationInProgress == OperationAbort); | 242 ASSERT(m_operationInProgress == OperationAbort); |
| 245 m_operationInProgress = OperationNone; | 243 m_operationInProgress = OperationNone; |
| 246 Operation operation = m_queuedOperation; | 244 Operation operation = m_queuedOperation; |
| 247 m_queuedOperation = OperationNone; | 245 m_queuedOperation = OperationNone; |
| 248 doOperation(operation); | 246 doOperation(operation); |
| 249 } | 247 } |
| 250 | 248 |
| 251 void FileWriter::doOperation(Operation operation) | 249 void FileWriter::doOperation(Operation operation) |
| 252 { | 250 { |
| 253 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarting(g etExecutionContext(), "FileWriter", m_asyncOperationId); | |
|
dgozman
2016/04/06 02:31:08
Bring it back!
| |
| 254 switch (operation) { | 251 switch (operation) { |
| 255 case OperationWrite: | 252 case OperationWrite: |
| 256 ASSERT(m_operationInProgress == OperationNone); | 253 ASSERT(m_operationInProgress == OperationNone); |
| 257 ASSERT(m_truncateLength == -1); | 254 ASSERT(m_truncateLength == -1); |
| 258 ASSERT(m_blobBeingWritten.get()); | 255 ASSERT(m_blobBeingWritten.get()); |
| 259 ASSERT(m_readyState == WRITING); | 256 ASSERT(m_readyState == WRITING); |
| 260 writer()->write(position(), m_blobBeingWritten->uuid()); | 257 writer()->write(position(), m_blobBeingWritten->uuid()); |
| 261 break; | 258 break; |
| 262 case OperationTruncate: | 259 case OperationTruncate: |
| 263 ASSERT(m_operationInProgress == OperationNone); | 260 ASSERT(m_operationInProgress == OperationNone); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 291 m_truncateLength = -1; | 288 m_truncateLength = -1; |
| 292 if (FileError::OK != code) { | 289 if (FileError::OK != code) { |
| 293 m_error = FileError::create(code); | 290 m_error = FileError::create(code); |
| 294 if (FileError::ABORT_ERR == code) | 291 if (FileError::ABORT_ERR == code) |
| 295 fireEvent(EventTypeNames::abort); | 292 fireEvent(EventTypeNames::abort); |
| 296 else | 293 else |
| 297 fireEvent(EventTypeNames::error); | 294 fireEvent(EventTypeNames::error); |
| 298 } else | 295 } else |
| 299 fireEvent(EventTypeNames::write); | 296 fireEvent(EventTypeNames::write); |
| 300 fireEvent(EventTypeNames::writeend); | 297 fireEvent(EventTypeNames::writeend); |
| 301 | |
| 302 InspectorInstrumentation::traceAsyncOperationCompleted(getExecutionContext() , m_asyncOperationId); | |
| 303 m_asyncOperationId = 0; | |
| 304 } | 298 } |
| 305 | 299 |
| 306 void FileWriter::fireEvent(const AtomicString& type) | 300 void FileWriter::fireEvent(const AtomicString& type) |
| 307 { | 301 { |
| 308 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync CallbackStarting(getExecutionContext(), m_asyncOperationId); | |
| 309 ++m_recursionDepth; | 302 ++m_recursionDepth; |
| 310 dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWri te)); | 303 dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWri te)); |
| 311 --m_recursionDepth; | 304 --m_recursionDepth; |
| 312 ASSERT(m_recursionDepth >= 0); | 305 ASSERT(m_recursionDepth >= 0); |
| 313 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); | |
| 314 } | 306 } |
| 315 | 307 |
| 316 void FileWriter::setError(FileError::ErrorCode errorCode, ExceptionState& except ionState) | 308 void FileWriter::setError(FileError::ErrorCode errorCode, ExceptionState& except ionState) |
| 317 { | 309 { |
| 318 ASSERT(errorCode); | 310 ASSERT(errorCode); |
| 319 FileError::throwDOMException(exceptionState, errorCode); | 311 FileError::throwDOMException(exceptionState, errorCode); |
| 320 m_error = FileError::create(errorCode); | 312 m_error = FileError::create(errorCode); |
| 321 } | 313 } |
| 322 | 314 |
| 323 DEFINE_TRACE(FileWriter) | 315 DEFINE_TRACE(FileWriter) |
| 324 { | 316 { |
| 325 visitor->trace(m_error); | 317 visitor->trace(m_error); |
| 326 visitor->trace(m_blobBeingWritten); | 318 visitor->trace(m_blobBeingWritten); |
| 327 EventTargetWithInlineData::trace(visitor); | 319 EventTargetWithInlineData::trace(visitor); |
| 328 FileWriterBase::trace(visitor); | 320 FileWriterBase::trace(visitor); |
| 329 ActiveDOMObject::trace(visitor); | 321 ActiveDOMObject::trace(visitor); |
| 330 } | 322 } |
| 331 | 323 |
| 332 } // namespace blink | 324 } // namespace blink |
| OLD | NEW |