Commit 62b48b4f authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Clean up to allow zip archiver to compile using the non-NaCl toolchain.

These changes are necessary to eventually integrate the zip archivers
unit tests.

Changes include:
- virtual -> override
- Un-inlining overridden functions
- Correcting types

BUG=889703

Change-Id: I83030c6b77dda026c4a3fee50df2ecbcedb898f6
Reviewed-on: https://chromium-review.googlesource.com/1250281Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594972}
parent 5385bf5d
......@@ -22,6 +22,7 @@ executable("zip_archiver_pnacl") {
"request.h",
"volume.cc",
"volume.h",
"volume_archive.cc",
"volume_archive.h",
"volume_archive_minizip.cc",
"volume_archive_minizip.h",
......
......@@ -26,14 +26,14 @@ class JavaScriptCompressorRequestor
explicit JavaScriptCompressorRequestor(Compressor* compressor)
: compressor_(compressor) {}
virtual void WriteChunkRequest(int64_t offset,
int64_t length,
const pp::VarArrayBuffer& buffer) {
void WriteChunkRequest(int64_t offset,
int64_t length,
const pp::VarArrayBuffer& buffer) override {
compressor_->message_sender()->SendWriteChunk(compressor_->compressor_id(),
buffer, offset, length);
}
virtual void ReadFileChunkRequest(int64_t length) {
void ReadFileChunkRequest(int64_t length) override {
compressor_->message_sender()->SendReadFileChunk(
compressor_->compressor_id(), length);
}
......
......@@ -35,22 +35,22 @@ class CompressorArchiveMinizip : public CompressorArchive {
public:
explicit CompressorArchiveMinizip(CompressorStream* compressor_stream);
virtual ~CompressorArchiveMinizip();
~CompressorArchiveMinizip() override;
// Creates an archive object.
virtual bool CreateArchive();
bool CreateArchive() override;
// Closes the archive.
virtual bool CloseArchive(bool has_error);
bool CloseArchive(bool has_error) override;
// Cancels the compression process.
virtual void CancelArchive();
void CancelArchive() override;
// Adds an entry to the archive.
virtual bool AddToArchive(const std::string& filename,
int64_t file_size,
int64_t modification_time,
bool is_directory);
bool AddToArchive(const std::string& filename,
int64_t file_size,
int64_t modification_time,
bool is_directory) override;
// A getter function for zip_file_.
zipFile zip_file() const { return zip_file_; }
......
......@@ -23,23 +23,23 @@ class CompressorIOJavaScriptStream : public CompressorStream {
CompressorIOJavaScriptStream(
JavaScriptCompressorRequestorInterface* requestor);
virtual ~CompressorIOJavaScriptStream();
~CompressorIOJavaScriptStream() override;
// Flushes the data in buffer_. Since minizip sends tons of write requests and
// communication between C++ and JS is very expensive, we need to cache data
// in buffer_ and send them in a lump.
virtual int64_t Flush();
int64_t Flush() override;
virtual int64_t Write(int64_t zip_offset,
int64_t zip_length,
const char* zip_buffer);
int64_t Write(int64_t zip_offset,
int64_t zip_length,
const char* zip_buffer) override;
virtual int64_t WriteChunkDone(int64_t write_bytes);
int64_t WriteChunkDone(int64_t write_bytes) override;
virtual int64_t Read(int64_t bytes_to_read, char* destination_buffer);
int64_t Read(int64_t bytes_to_read, char* destination_buffer) override;
virtual int64_t ReadFileChunkDone(int64_t read_bytes,
pp::VarArrayBuffer* buffer);
int64_t ReadFileChunkDone(int64_t read_bytes,
pp::VarArrayBuffer* buffer) override;
private:
// A requestor that makes calls to JavaScript to read and write chunks.
......
......@@ -63,7 +63,7 @@ void ConstructMetadata(int64_t index,
pp::VarDictionary parent_entries =
pp::VarDictionary(parent_metadata->Get("entries"));
unsigned int position = entry_path.find(kPathDelimiter);
std::string::size_type position = entry_path.find(kPathDelimiter);
pp::VarDictionary entry_metadata;
std::string entry_name;
......@@ -114,16 +114,16 @@ class JavaScriptRequestor : public JavaScriptRequestorInterface {
// JavaScriptRequestor does not own the volume pointer.
explicit JavaScriptRequestor(Volume* volume) : volume_(volume) {}
virtual void RequestFileChunk(const std::string& request_id,
int64_t offset,
int64_t bytes_to_read) {
void RequestFileChunk(const std::string& request_id,
int64_t offset,
int64_t bytes_to_read) override {
PP_DCHECK(offset >= 0);
PP_DCHECK(bytes_to_read > 0);
volume_->message_sender()->SendFileChunkRequest(
volume_->file_system_id(), request_id, offset, bytes_to_read);
}
virtual void RequestPassphrase(const std::string& request_id) {
void RequestPassphrase(const std::string& request_id) override {
volume_->message_sender()->SendPassphraseRequest(volume_->file_system_id(),
request_id);
}
......@@ -136,8 +136,8 @@ class JavaScriptRequestor : public JavaScriptRequestorInterface {
// Volume constructor.
class VolumeArchiveFactory : public VolumeArchiveFactoryInterface {
public:
virtual std::unique_ptr<VolumeArchive> Create(
std::unique_ptr<VolumeReader> reader) {
std::unique_ptr<VolumeArchive> Create(
std::unique_ptr<VolumeReader> reader) override {
return std::make_unique<VolumeArchiveMinizip>(std::move(reader));
}
};
......@@ -149,7 +149,7 @@ class VolumeReaderFactory : public VolumeReaderFactoryInterface {
// VolumeReaderFactory does not own the volume pointer.
explicit VolumeReaderFactory(Volume* volume) : volume_(volume) {}
virtual std::unique_ptr<VolumeReader> Create(int64_t archive_size) {
std::unique_ptr<VolumeReader> Create(int64_t archive_size) override {
return std::make_unique<VolumeReaderJavaScriptStream>(archive_size,
volume_->requestor());
}
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/resources/chromeos/zip_archiver/cpp/volume_archive.h"
VolumeArchive::VolumeArchive(std::unique_ptr<VolumeReader> reader)
: reader_(std::move(reader)) {}
VolumeArchive::~VolumeArchive() = default;
......@@ -17,10 +17,9 @@
// to be thread safe and its methods shouldn't be called in parallel.
class VolumeArchive {
public:
explicit VolumeArchive(std::unique_ptr<VolumeReader> reader)
: reader_(std::move(reader)) {}
explicit VolumeArchive(std::unique_ptr<VolumeReader> reader);
virtual ~VolumeArchive() {}
virtual ~VolumeArchive();
// For functions that need to return more than pass/fail results.
enum Result {
......
......@@ -246,8 +246,8 @@ bool VolumeArchiveMinizip::Init(const std::string& encoding) {
int64_t previous_offset = reader()->offset();
char* buffer_pointer = static_cache_.get();
int64_t left_length = static_cache_size_;
static_cache_offset_ =
std::max(reader()->archive_size() - static_cache_size_, 0LL);
static_cache_offset_ = std::max(reader()->archive_size() - static_cache_size_,
static_cast<int64_t>(0));
if (reader()->Seek(static_cache_offset_, ZLIB_FILEFUNC_SEEK_SET) < 0) {
set_error_message(kArchiveOpenError);
return false /* Error */;
......
......@@ -45,31 +45,33 @@ class VolumeArchiveMinizip : public VolumeArchive {
public:
explicit VolumeArchiveMinizip(std::unique_ptr<VolumeReader> reader);
virtual ~VolumeArchiveMinizip();
~VolumeArchiveMinizip() override;
// See volume_archive_interface.h.
virtual bool Init(const std::string& encoding);
bool Init(const std::string& encoding) override;
// See volume_archive_interface.h.
virtual VolumeArchive::Result GetCurrentFileInfo(std::string* path_name,
bool* isEncodedInUtf8,
int64_t* size,
bool* is_directory,
time_t* modification_time);
VolumeArchive::Result GetCurrentFileInfo(std::string* path_name,
bool* isEncodedInUtf8,
int64_t* size,
bool* is_directory,
time_t* modification_time) override;
virtual VolumeArchive::Result GoToNextFile();
VolumeArchive::Result GoToNextFile() override;
// See volume_archive_interface.h.
virtual bool SeekHeader(const std::string& path_name);
bool SeekHeader(const std::string& path_name) override;
// See volume_archive_interface.h.
virtual int64_t ReadData(int64_t offset, int64_t length, const char** buffer);
int64_t ReadData(int64_t offset,
int64_t length,
const char** buffer) override;
// See volume_archive_interface.h.
virtual void MaybeDecompressAhead();
void MaybeDecompressAhead() override;
// See volume_archive_interface.h.
virtual bool Cleanup();
bool Cleanup() override;
int64_t reader_data_size() const { return reader_data_size_; }
......
......@@ -42,6 +42,14 @@ VolumeReaderJavaScriptStream::~VolumeReaderJavaScriptStream() {
second_array_buffer_.Unmap();
}
int64_t VolumeReaderJavaScriptStream::offset() {
return offset_;
}
int64_t VolumeReaderJavaScriptStream::archive_size() {
return archive_size_;
}
void VolumeReaderJavaScriptStream::SetBufferAndSignal(
const pp::VarArrayBuffer& array_buffer,
int64_t read_offset) {
......
......@@ -28,7 +28,7 @@ class VolumeReaderJavaScriptStream : public VolumeReader {
VolumeReaderJavaScriptStream(int64_t archive_size,
JavaScriptRequestorInterface* requestor);
virtual ~VolumeReaderJavaScriptStream();
~VolumeReaderJavaScriptStream() override;
// Sets the internal array buffer used for reads and signal the blocked
// VolumeReaderJavaScriptStream::Read to continue execution. Must be done in
......@@ -60,10 +60,10 @@ class VolumeReaderJavaScriptStream : public VolumeReader {
// See volume_reader.h for description. This method blocks on
// available_data_cond_. SetBufferAndSignal should unblock it from another
// thread.
virtual int64_t Read(int64_t bytes_to_read, const void** destination_buffer);
int64_t Read(int64_t bytes_to_read, const void** destination_buffer) override;
// See volume_reader.h for description.
virtual int64_t Seek(int64_t offset, int whence);
int64_t Seek(int64_t offset, int whence) override;
// Sets the request Id to be used by the reader.
void SetRequestId(const std::string& request_id);
......@@ -71,11 +71,11 @@ class VolumeReaderJavaScriptStream : public VolumeReader {
// See volume_reader.h for description. The method blocks on
// available_passphrase_cond_. SetPassphraseAndSignal should unblock it from
// another thread.
virtual std::unique_ptr<std::string> Passphrase();
std::unique_ptr<std::string> Passphrase() override;
virtual int64_t offset() { return offset_; }
int64_t offset() override;
int64_t archive_size() { return archive_size_; }
int64_t archive_size() override;
private:
// Request a chunk of length number of bytes from JavaScript starting from
......
......@@ -16,10 +16,10 @@ int64_t FakeVolumeReader::Skip(int64_t bytes_to_skip) {
return 0; // Not important.
}
int64_t FakeVolumeReader::Seek(int64_t offset, int whence) {
int64_t FakeVolumeReader::Seek(int64_t offset, base::File::Whence whence) {
return 0; // Not important.
}
const char* FakeVolumeReader::Passphrase() {
std::unique_ptr<std::string> FakeVolumeReader::Passphrase() {
return NULL; // Not important.
}
......@@ -15,12 +15,12 @@
class FakeVolumeReader : public VolumeReader {
public:
FakeVolumeReader();
virtual ~FakeVolumeReader();
~FakeVolumeReader() override;
int64_t Read(int64_t bytes_to_read, const void** destination_buffer);
int64_t Read(int64_t bytes_to_read, const void** destination_buffer) override;
int64_t Skip(int64_t bytes_to_skip);
int64_t Seek(int64_t offset, int whence);
const char* Passphrase();
int64_t Seek(int64_t offset, base::File::Whence whence) override;
std::unique_ptr<std::string> Passphrase() override;
};
#endif // CHROME_BROWSER_RESOURCES_CHROMEOS_ZIP_ARCHIVER_UNPACKER_TEST_CPP_FAKE_VOLUME_READER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment