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 17 matching lines...) Expand all Loading... |
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 "config.h" | 31 #include "config.h" |
32 #include "modules/filesystem/FileWriter.h" | 32 #include "modules/filesystem/FileWriter.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
35 #include "core/dom/ExceptionCode.h" | 35 #include "core/dom/ExceptionCode.h" |
36 #include "core/events/ProgressEvent.h" | 36 #include "core/events/ProgressEvent.h" |
37 #include "core/fileapi/Blob.h" | 37 #include "core/fileapi/Blob.h" |
| 38 #include "core/inspector/InspectorInstrumentation.h" |
38 #include "public/platform/WebFileWriter.h" | 39 #include "public/platform/WebFileWriter.h" |
39 #include "public/platform/WebURL.h" | 40 #include "public/platform/WebURL.h" |
40 #include "wtf/CurrentTime.h" | 41 #include "wtf/CurrentTime.h" |
41 | 42 |
42 namespace blink { | 43 namespace blink { |
43 | 44 |
44 static const int kMaxRecursionDepth = 3; | 45 static const int kMaxRecursionDepth = 3; |
45 static const double progressNotificationIntervalMS = 50; | 46 static const double progressNotificationIntervalMS = 50; |
46 | 47 |
47 FileWriter* FileWriter::create(ExecutionContext* context) | 48 FileWriter* FileWriter::create(ExecutionContext* context) |
48 { | 49 { |
49 FileWriter* fileWriter = adoptRefCountedGarbageCollectedWillBeNoop(new FileW
riter(context)); | 50 FileWriter* fileWriter = adoptRefCountedGarbageCollectedWillBeNoop(new FileW
riter(context)); |
50 fileWriter->suspendIfNeeded(); | 51 fileWriter->suspendIfNeeded(); |
51 return fileWriter; | 52 return fileWriter; |
52 } | 53 } |
53 | 54 |
54 FileWriter::FileWriter(ExecutionContext* context) | 55 FileWriter::FileWriter(ExecutionContext* context) |
55 : ActiveDOMObject(context) | 56 : ActiveDOMObject(context) |
56 , m_readyState(INIT) | 57 , m_readyState(INIT) |
57 , m_operationInProgress(OperationNone) | 58 , m_operationInProgress(OperationNone) |
58 , m_queuedOperation(OperationNone) | 59 , m_queuedOperation(OperationNone) |
59 , m_bytesWritten(0) | 60 , m_bytesWritten(0) |
60 , m_bytesToWrite(0) | 61 , m_bytesToWrite(0) |
61 , m_truncateLength(-1) | 62 , m_truncateLength(-1) |
62 , m_numAborts(0) | 63 , m_numAborts(0) |
63 , m_recursionDepth(0) | 64 , m_recursionDepth(0) |
64 , m_lastProgressNotificationTimeMS(0) | 65 , m_lastProgressNotificationTimeMS(0) |
| 66 , m_asyncOperationId(0) |
65 { | 67 { |
66 ScriptWrappable::init(this); | 68 ScriptWrappable::init(this); |
67 } | 69 } |
68 | 70 |
69 FileWriter::~FileWriter() | 71 FileWriter::~FileWriter() |
70 { | 72 { |
71 ASSERT(!m_recursionDepth); | 73 ASSERT(!m_recursionDepth); |
72 if (m_readyState == WRITING) | 74 if (m_readyState == WRITING) |
73 stop(); | 75 stop(); |
74 } | 76 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 { | 248 { |
247 ASSERT(m_operationInProgress == OperationAbort); | 249 ASSERT(m_operationInProgress == OperationAbort); |
248 m_operationInProgress = OperationNone; | 250 m_operationInProgress = OperationNone; |
249 Operation operation = m_queuedOperation; | 251 Operation operation = m_queuedOperation; |
250 m_queuedOperation = OperationNone; | 252 m_queuedOperation = OperationNone; |
251 doOperation(operation); | 253 doOperation(operation); |
252 } | 254 } |
253 | 255 |
254 void FileWriter::doOperation(Operation operation) | 256 void FileWriter::doOperation(Operation operation) |
255 { | 257 { |
| 258 m_asyncOperationId = InspectorInstrumentation::traceAsyncOperationStarting(e
xecutionContext(), "FileWriter", m_asyncOperationId); |
256 switch (operation) { | 259 switch (operation) { |
257 case OperationWrite: | 260 case OperationWrite: |
258 ASSERT(m_operationInProgress == OperationNone); | 261 ASSERT(m_operationInProgress == OperationNone); |
259 ASSERT(m_truncateLength == -1); | 262 ASSERT(m_truncateLength == -1); |
260 ASSERT(m_blobBeingWritten.get()); | 263 ASSERT(m_blobBeingWritten.get()); |
261 ASSERT(m_readyState == WRITING); | 264 ASSERT(m_readyState == WRITING); |
262 writer()->write(position(), m_blobBeingWritten->uuid()); | 265 writer()->write(position(), m_blobBeingWritten->uuid()); |
263 break; | 266 break; |
264 case OperationTruncate: | 267 case OperationTruncate: |
265 ASSERT(m_operationInProgress == OperationNone); | 268 ASSERT(m_operationInProgress == OperationNone); |
(...skipping 27 matching lines...) Expand all Loading... |
293 m_truncateLength = -1; | 296 m_truncateLength = -1; |
294 if (FileError::OK != code) { | 297 if (FileError::OK != code) { |
295 m_error = FileError::create(code); | 298 m_error = FileError::create(code); |
296 if (FileError::ABORT_ERR == code) | 299 if (FileError::ABORT_ERR == code) |
297 fireEvent(EventTypeNames::abort); | 300 fireEvent(EventTypeNames::abort); |
298 else | 301 else |
299 fireEvent(EventTypeNames::error); | 302 fireEvent(EventTypeNames::error); |
300 } else | 303 } else |
301 fireEvent(EventTypeNames::write); | 304 fireEvent(EventTypeNames::write); |
302 fireEvent(EventTypeNames::writeend); | 305 fireEvent(EventTypeNames::writeend); |
| 306 |
| 307 InspectorInstrumentation::traceAsyncOperationCompleted(executionContext(), m
_asyncOperationId); |
| 308 m_asyncOperationId = 0; |
303 } | 309 } |
304 | 310 |
305 void FileWriter::fireEvent(const AtomicString& type) | 311 void FileWriter::fireEvent(const AtomicString& type) |
306 { | 312 { |
| 313 InspectorInstrumentationCookie cookie = InspectorInstrumentation::traceAsync
CallbackStarting(executionContext(), m_asyncOperationId); |
307 ++m_recursionDepth; | 314 ++m_recursionDepth; |
308 dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWri
te)); | 315 dispatchEvent(ProgressEvent::create(type, true, m_bytesWritten, m_bytesToWri
te)); |
309 --m_recursionDepth; | 316 --m_recursionDepth; |
310 ASSERT(m_recursionDepth >= 0); | 317 ASSERT(m_recursionDepth >= 0); |
| 318 InspectorInstrumentation::traceAsyncCallbackCompleted(cookie); |
311 } | 319 } |
312 | 320 |
313 void FileWriter::setError(FileError::ErrorCode errorCode, ExceptionState& except
ionState) | 321 void FileWriter::setError(FileError::ErrorCode errorCode, ExceptionState& except
ionState) |
314 { | 322 { |
315 ASSERT(errorCode); | 323 ASSERT(errorCode); |
316 FileError::throwDOMException(exceptionState, errorCode); | 324 FileError::throwDOMException(exceptionState, errorCode); |
317 m_error = FileError::create(errorCode); | 325 m_error = FileError::create(errorCode); |
318 } | 326 } |
319 | 327 |
320 void FileWriter::trace(Visitor* visitor) | 328 void FileWriter::trace(Visitor* visitor) |
321 { | 329 { |
322 visitor->trace(m_error); | 330 visitor->trace(m_error); |
323 visitor->trace(m_blobBeingWritten); | 331 visitor->trace(m_blobBeingWritten); |
324 FileWriterBase::trace(visitor); | 332 FileWriterBase::trace(visitor); |
325 EventTargetWithInlineData::trace(visitor); | 333 EventTargetWithInlineData::trace(visitor); |
326 } | 334 } |
327 | 335 |
328 } // namespace blink | 336 } // namespace blink |
OLD | NEW |