Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Unified Diff: ui/file_manager/zip_archiver/cpp/volume_reader_javascript_stream.cc

Issue 2807063002: Replace Libarchive with MiniZip. (Closed)
Patch Set: Delete BUILD.gn Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/zip_archiver/cpp/volume_reader_javascript_stream.cc
diff --git a/ui/file_manager/zip_archiver/cpp/volume_reader_javascript_stream.cc b/ui/file_manager/zip_archiver/cpp/volume_reader_javascript_stream.cc
index 75a8ef6245534154ab3cb28fd3ade24fca476cb4..ef01cb3cf5c8a36e73740852bd1617d560e3190f 100644
--- a/ui/file_manager/zip_archiver/cpp/volume_reader_javascript_stream.cc
+++ b/ui/file_manager/zip_archiver/cpp/volume_reader_javascript_stream.cc
@@ -7,7 +7,8 @@
#include <algorithm>
#include <limits>
-#include "archive.h"
+#include "third_party/zlib/contrib/minizip/unzip.h"
+
#include "ppapi/cpp/logging.h"
VolumeReaderJavaScriptStream::VolumeReaderJavaScriptStream(
@@ -120,7 +121,7 @@ int64_t VolumeReaderJavaScriptStream::Read(int64_t bytes_to_read,
}
// Call in case of first read or read after Seek and Skip.
- if (last_read_chunk_offset_ != offset_)
+ if (last_read_chunk_offset_ != offset_ || !available_data_)
RequestChunk(bytes_to_read);
if (!available_data_) {
@@ -129,7 +130,7 @@ int64_t VolumeReaderJavaScriptStream::Read(int64_t bytes_to_read,
// was done outside guarded zone.
if (read_error_) {
pthread_mutex_unlock(&shared_state_lock_);
- return ARCHIVE_FATAL;
+ return -1;
}
pthread_cond_wait(&available_data_cond_, &shared_state_lock_);
}
@@ -137,7 +138,7 @@ int64_t VolumeReaderJavaScriptStream::Read(int64_t bytes_to_read,
if (read_error_) { // Read ahead failed.
pthread_mutex_unlock(&shared_state_lock_);
- return ARCHIVE_FATAL;
+ return -1;
}
// Make data available for libarchive custom read. No need to lock this part.
@@ -187,24 +188,24 @@ int64_t VolumeReaderJavaScriptStream::Seek(int64_t offset, int whence) {
int64_t new_offset = offset_;
switch (whence) {
- case SEEK_SET:
+ case ZLIB_FILEFUNC_SEEK_SET:
new_offset = offset;
break;
- case SEEK_CUR:
+ case ZLIB_FILEFUNC_SEEK_CUR:
new_offset += offset;
break;
- case SEEK_END:
+ case ZLIB_FILEFUNC_SEEK_END:
new_offset = archive_size_ + offset;
break;
default:
PP_NOTREACHED();
pthread_mutex_unlock(&shared_state_lock_);
- return ARCHIVE_FATAL;
+ return -1;
}
- if (new_offset < 0 || new_offset > archive_size_) {
+ if (new_offset < 0) {
pthread_mutex_unlock(&shared_state_lock_);
- return ARCHIVE_FATAL;
+ return -1;
}
offset_ = new_offset;
@@ -213,22 +214,8 @@ int64_t VolumeReaderJavaScriptStream::Seek(int64_t offset, int whence) {
return new_offset;
}
-int64_t VolumeReaderJavaScriptStream::Skip(int64_t bytes_to_skip) {
- pthread_mutex_lock(&shared_state_lock_);
- // Invalid bytes_to_skip. This "if" can be triggered for corrupted archives.
- // We return 0 instead of ARCHIVE_FATAL in order for libarchive to use normal
- // Read and return the correct error. In case we return ARCHIVE_FATAL here
- // then libarchive just stops without telling us why it wasn't able to
- // process the archive.
- if (archive_size_ - offset_ < bytes_to_skip || bytes_to_skip < 0) {
- pthread_mutex_unlock(&shared_state_lock_);
- return 0;
- }
-
- offset_ += bytes_to_skip;
- pthread_mutex_unlock(&shared_state_lock_);
-
- return bytes_to_skip;
+int64_t VolumeReaderJavaScriptStream::offset() {
+ return offset_;
}
void VolumeReaderJavaScriptStream::SetRequestId(const std::string& request_id) {

Powered by Google App Engine
This is Rietveld 408576698