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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 m_client->didStop(); | 65 m_client->didStop(); |
66 } | 66 } |
67 | 67 |
68 void FileStream::openForRead(Blob* blob) | 68 void FileStream::openForRead(Blob* blob) |
69 { | 69 { |
70 ASSERT(!isMainThread()); | 70 ASSERT(!isMainThread()); |
71 | 71 |
72 if (isHandleValid(m_handle)) | 72 if (isHandleValid(m_handle)) |
73 return; | 73 return; |
74 | 74 |
| 75 // FIXME: Need to handle multiple items that may include non-file ones when
BlobBuilder is introduced. |
| 76 ASSERT(blob->items().size() >= 1); |
| 77 const FileBlobItem* fileItem = blob->items().at(0)->toFileBlobItem(); |
| 78 if (!fileItem) { |
| 79 ASSERT(false); |
| 80 m_client->didFail(NOT_READABLE_ERR); |
| 81 return; |
| 82 } |
| 83 |
75 // Check if the file exists by querying its modification time. We choose not
to call fileExists() in order to save an | 84 // Check if the file exists by querying its modification time. We choose not
to call fileExists() in order to save an |
76 // extra file system call when the modification time is needed to check the
validity of the sliced file blob. | 85 // extra file system call when the modification time is needed to check the
validity of the sliced file blob. |
77 // Per the spec, we need to return different error codes to differentiate be
tween non-existent file and permission error. | 86 // Per the spec, we need to return different error codes to differentiate be
tween non-existent file and permission error. |
78 // openFile() could not tell use the failure reason. | 87 // openFile() could not tell use the failure reason. |
79 time_t currentModificationTime; | 88 time_t currentModificationTime; |
80 if (!getFileModificationTime(blob->path(), currentModificationTime)) { | 89 if (!getFileModificationTime(fileItem->path(), currentModificationTime)) { |
81 m_client->didFail(NOT_FOUND_ERR); | 90 m_client->didFail(NOT_FOUND_ERR); |
82 return; | 91 return; |
83 } | 92 } |
84 | 93 |
85 // Open the file blob. | 94 // Open the file blob. |
86 m_handle = openFile(blob->path(), OpenForRead); | 95 m_handle = openFile(fileItem->path(), OpenForRead); |
87 if (!isHandleValid(m_handle)) { | 96 if (!isHandleValid(m_handle)) { |
88 m_client->didFail(NOT_READABLE_ERR); | 97 m_client->didFail(NOT_READABLE_ERR); |
89 return; | 98 return; |
90 } | 99 } |
91 | 100 |
92 #if ENABLE(BLOB_SLICE) | 101 #if ENABLE(BLOB_SLICE) |
93 // Check the modificationt time for the possible file change. | 102 const FileRangeBlobItem* fileRangeItem = fileItem->toFileRangeBlobItem(); |
94 if (blob->modificationTime() != Blob::doNotCheckFileChange && static_cast<ti
me_t>(blob->modificationTime()) != currentModificationTime) { | 103 if (fileRangeItem) { |
95 m_client->didFail(NOT_READABLE_ERR); | 104 // Check the modificationt time for the possible file change. |
96 return; | 105 if (static_cast<time_t>(fileRangeItem->snapshotModificationTime()) != cu
rrentModificationTime) { |
97 } | |
98 | |
99 // Jump to the beginning position if the file has been sliced. | |
100 if (blob->start() > 0) { | |
101 if (!seekFile(m_handle, blob->start(), SeekFromBeginning)) { | |
102 m_client->didFail(NOT_READABLE_ERR); | 106 m_client->didFail(NOT_READABLE_ERR); |
103 return; | 107 return; |
104 } | 108 } |
| 109 |
| 110 // Jump to the beginning position if the file has been sliced. |
| 111 if (fileRangeItem->start() > 0) { |
| 112 if (seekFile(m_handle, fileRangeItem->start(), SeekFromBeginning) <
0) { |
| 113 m_client->didFail(NOT_READABLE_ERR); |
| 114 return; |
| 115 } |
| 116 } |
105 } | 117 } |
106 #endif | 118 #endif |
107 | 119 |
108 // Get the size. | 120 // Get the size. |
109 #if ENABLE(BLOB_SLICE) | |
110 m_totalBytesToRead = blob->length(); | |
111 if (m_totalBytesToRead == Blob::toEndOfFile) | |
112 m_totalBytesToRead = blob->size() - blob->start(); | |
113 #else | |
114 m_totalBytesToRead = blob->size(); | 121 m_totalBytesToRead = blob->size(); |
115 #endif | |
116 | |
117 m_client->didGetSize(m_totalBytesToRead); | 122 m_client->didGetSize(m_totalBytesToRead); |
118 } | 123 } |
119 | 124 |
120 void FileStream::openForWrite(const String&) | 125 void FileStream::openForWrite(const String&) |
121 { | 126 { |
122 ASSERT(!isMainThread()); | 127 ASSERT(!isMainThread()); |
123 // FIXME: to be implemented. | 128 // FIXME: to be implemented. |
124 } | 129 } |
125 | 130 |
126 void FileStream::close() | 131 void FileStream::close() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 176 |
172 void FileStream::truncate(long long) | 177 void FileStream::truncate(long long) |
173 { | 178 { |
174 ASSERT(!isMainThread()); | 179 ASSERT(!isMainThread()); |
175 // FIXME: to be implemented. | 180 // FIXME: to be implemented. |
176 } | 181 } |
177 | 182 |
178 } // namespace WebCore | 183 } // namespace WebCore |
179 | 184 |
180 #endif // ENABLE(FILE_READER) || ENABLE(FILE_WRITER) | 185 #endif // ENABLE(FILE_READER) || ENABLE(FILE_WRITER) |
OLD | NEW |