| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 resetWriter(); | 80 resetWriter(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 bool FileWriter::hasPendingActivity() const { | 83 bool FileWriter::hasPendingActivity() const { |
| 84 return m_operationInProgress != OperationNone || | 84 return m_operationInProgress != OperationNone || |
| 85 m_queuedOperation != OperationNone || m_readyState == kWriting; | 85 m_queuedOperation != OperationNone || m_readyState == kWriting; |
| 86 } | 86 } |
| 87 | 87 |
| 88 void FileWriter::write(Blob* data, ExceptionState& exceptionState) { | 88 void FileWriter::write(Blob* data, ExceptionState& exceptionState) { |
| 89 if (!getExecutionContext()) |
| 90 return; |
| 89 ASSERT(data); | 91 ASSERT(data); |
| 90 ASSERT(writer()); | 92 ASSERT(writer()); |
| 91 ASSERT(m_truncateLength == -1); | 93 ASSERT(m_truncateLength == -1); |
| 92 if (m_readyState == kWriting) { | 94 if (m_readyState == kWriting) { |
| 93 setError(FileError::kInvalidStateErr, exceptionState); | 95 setError(FileError::kInvalidStateErr, exceptionState); |
| 94 return; | 96 return; |
| 95 } | 97 } |
| 96 if (m_recursionDepth > kMaxRecursionDepth) { | 98 if (m_recursionDepth > kMaxRecursionDepth) { |
| 97 setError(FileError::kSecurityErr, exceptionState); | 99 setError(FileError::kSecurityErr, exceptionState); |
| 98 return; | 100 return; |
| 99 } | 101 } |
| 100 | 102 |
| 101 m_blobBeingWritten = data; | 103 m_blobBeingWritten = data; |
| 102 m_readyState = kWriting; | 104 m_readyState = kWriting; |
| 103 m_bytesWritten = 0; | 105 m_bytesWritten = 0; |
| 104 m_bytesToWrite = data->size(); | 106 m_bytesToWrite = data->size(); |
| 105 ASSERT(m_queuedOperation == OperationNone); | 107 ASSERT(m_queuedOperation == OperationNone); |
| 106 if (m_operationInProgress != OperationNone) { | 108 if (m_operationInProgress != OperationNone) { |
| 107 // We must be waiting for an abort to complete, since m_readyState wasn't | 109 // We must be waiting for an abort to complete, since m_readyState wasn't |
| 108 // kWriting. | 110 // kWriting. |
| 109 ASSERT(m_operationInProgress == OperationAbort); | 111 ASSERT(m_operationInProgress == OperationAbort); |
| 110 m_queuedOperation = OperationWrite; | 112 m_queuedOperation = OperationWrite; |
| 111 } else | 113 } else |
| 112 doOperation(OperationWrite); | 114 doOperation(OperationWrite); |
| 113 | 115 |
| 114 fireEvent(EventTypeNames::writestart); | 116 fireEvent(EventTypeNames::writestart); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void FileWriter::seek(long long position, ExceptionState& exceptionState) { | 119 void FileWriter::seek(long long position, ExceptionState& exceptionState) { |
| 120 if (!getExecutionContext()) |
| 121 return; |
| 118 ASSERT(writer()); | 122 ASSERT(writer()); |
| 119 if (m_readyState == kWriting) { | 123 if (m_readyState == kWriting) { |
| 120 setError(FileError::kInvalidStateErr, exceptionState); | 124 setError(FileError::kInvalidStateErr, exceptionState); |
| 121 return; | 125 return; |
| 122 } | 126 } |
| 123 | 127 |
| 124 ASSERT(m_truncateLength == -1); | 128 ASSERT(m_truncateLength == -1); |
| 125 ASSERT(m_queuedOperation == OperationNone); | 129 ASSERT(m_queuedOperation == OperationNone); |
| 126 seekInternal(position); | 130 seekInternal(position); |
| 127 } | 131 } |
| 128 | 132 |
| 129 void FileWriter::truncate(long long position, ExceptionState& exceptionState) { | 133 void FileWriter::truncate(long long position, ExceptionState& exceptionState) { |
| 134 if (!getExecutionContext()) |
| 135 return; |
| 130 ASSERT(writer()); | 136 ASSERT(writer()); |
| 131 ASSERT(m_truncateLength == -1); | 137 ASSERT(m_truncateLength == -1); |
| 132 if (m_readyState == kWriting || position < 0) { | 138 if (m_readyState == kWriting || position < 0) { |
| 133 setError(FileError::kInvalidStateErr, exceptionState); | 139 setError(FileError::kInvalidStateErr, exceptionState); |
| 134 return; | 140 return; |
| 135 } | 141 } |
| 136 if (m_recursionDepth > kMaxRecursionDepth) { | 142 if (m_recursionDepth > kMaxRecursionDepth) { |
| 137 setError(FileError::kSecurityErr, exceptionState); | 143 setError(FileError::kSecurityErr, exceptionState); |
| 138 return; | 144 return; |
| 139 } | 145 } |
| 140 | 146 |
| 141 m_readyState = kWriting; | 147 m_readyState = kWriting; |
| 142 m_bytesWritten = 0; | 148 m_bytesWritten = 0; |
| 143 m_bytesToWrite = 0; | 149 m_bytesToWrite = 0; |
| 144 m_truncateLength = position; | 150 m_truncateLength = position; |
| 145 ASSERT(m_queuedOperation == OperationNone); | 151 ASSERT(m_queuedOperation == OperationNone); |
| 146 if (m_operationInProgress != OperationNone) { | 152 if (m_operationInProgress != OperationNone) { |
| 147 // We must be waiting for an abort to complete, since m_readyState wasn't | 153 // We must be waiting for an abort to complete, since m_readyState wasn't |
| 148 // kWriting. | 154 // kWriting. |
| 149 ASSERT(m_operationInProgress == OperationAbort); | 155 ASSERT(m_operationInProgress == OperationAbort); |
| 150 m_queuedOperation = OperationTruncate; | 156 m_queuedOperation = OperationTruncate; |
| 151 } else | 157 } else |
| 152 doOperation(OperationTruncate); | 158 doOperation(OperationTruncate); |
| 153 fireEvent(EventTypeNames::writestart); | 159 fireEvent(EventTypeNames::writestart); |
| 154 } | 160 } |
| 155 | 161 |
| 156 void FileWriter::abort(ExceptionState& exceptionState) { | 162 void FileWriter::abort(ExceptionState& exceptionState) { |
| 163 if (!getExecutionContext()) |
| 164 return; |
| 157 ASSERT(writer()); | 165 ASSERT(writer()); |
| 158 if (m_readyState != kWriting) | 166 if (m_readyState != kWriting) |
| 159 return; | 167 return; |
| 160 ++m_numAborts; | 168 ++m_numAborts; |
| 161 | 169 |
| 162 doOperation(OperationAbort); | 170 doOperation(OperationAbort); |
| 163 signalCompletion(FileError::kAbortErr); | 171 signalCompletion(FileError::kAbortErr); |
| 164 } | 172 } |
| 165 | 173 |
| 166 void FileWriter::didWrite(long long bytes, bool complete) { | 174 void FileWriter::didWrite(long long bytes, bool complete) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 320 |
| 313 DEFINE_TRACE(FileWriter) { | 321 DEFINE_TRACE(FileWriter) { |
| 314 visitor->trace(m_error); | 322 visitor->trace(m_error); |
| 315 visitor->trace(m_blobBeingWritten); | 323 visitor->trace(m_blobBeingWritten); |
| 316 EventTargetWithInlineData::trace(visitor); | 324 EventTargetWithInlineData::trace(visitor); |
| 317 FileWriterBase::trace(visitor); | 325 FileWriterBase::trace(visitor); |
| 318 SuspendableObject::trace(visitor); | 326 SuspendableObject::trace(visitor); |
| 319 } | 327 } |
| 320 | 328 |
| 321 } // namespace blink | 329 } // namespace blink |
| OLD | NEW |