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

Use base::Time for modification time instead of a plain int64_t

Also, update the comment about the 'modification_time' field in the
compression request.

BUG=889703

Change-Id: I37df9e8abc50b195b73ffd9cf101444dc682ff33
Reviewed-on: https://chromium-review.googlesource.com/c/1279199
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599735}
parent 6f76ea33
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/time/time.h"
#include "chrome/browser/resources/chromeos/zip_archiver/cpp/compressor_archive_minizip.h" #include "chrome/browser/resources/chromeos/zip_archiver/cpp/compressor_archive_minizip.h"
#include "chrome/browser/resources/chromeos/zip_archiver/cpp/compressor_io_javascript_stream.h" #include "chrome/browser/resources/chromeos/zip_archiver/cpp/compressor_io_javascript_stream.h"
#include "chrome/browser/resources/chromeos/zip_archiver/cpp/javascript_compressor_requestor_interface.h" #include "chrome/browser/resources/chromeos/zip_archiver/cpp/javascript_compressor_requestor_interface.h"
...@@ -93,8 +94,9 @@ void Compressor::AddToArchiveCallback(int32_t, ...@@ -93,8 +94,9 @@ void Compressor::AddToArchiveCallback(int32_t,
bool is_directory = dictionary.Get(request::key::kIsDirectory).AsBool(); bool is_directory = dictionary.Get(request::key::kIsDirectory).AsBool();
PP_DCHECK(dictionary.Get(request::key::kModificationTime).is_string()); PP_DCHECK(dictionary.Get(request::key::kModificationTime).is_string());
// Since modification_time is milliseconds, we hold the value in int64_t. // modification_time comes from a JS Date object, which expresses time in
int64_t modification_time = static_cast<int64_t>( // milliseconds since the UNIX epoch.
base::Time modification_time = base::Time::FromJsTime(
request::GetInt64FromString(dictionary, request::key::kModificationTime)); request::GetInt64FromString(dictionary, request::key::kModificationTime));
if (!compressor_archive_->AddToArchive(pathname, file_size, modification_time, if (!compressor_archive_->AddToArchive(pathname, file_size, modification_time,
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include "base/time/time.h"
class CompressorStream; class CompressorStream;
// Defines a wrapper for packing operations executed on an archive. API is not // Defines a wrapper for packing operations executed on an archive. API is not
...@@ -45,7 +47,7 @@ class CompressorArchive { ...@@ -45,7 +47,7 @@ class CompressorArchive {
// can be obtained with CompressorArchive::error_message(). // can be obtained with CompressorArchive::error_message().
virtual bool AddToArchive(const std::string& filename, virtual bool AddToArchive(const std::string& filename,
int64_t file_size, int64_t file_size,
int64_t modification_time, base::Time modification_time,
bool is_directory) = 0; bool is_directory) = 0;
// A getter function for compressor_stream_. // A getter function for compressor_stream_.
......
...@@ -23,13 +23,13 @@ const char kCloseArchiveError[] = "Failed to close archive."; ...@@ -23,13 +23,13 @@ const char kCloseArchiveError[] = "Failed to close archive.";
// We need at least 256KB for MiniZip. // We need at least 256KB for MiniZip.
const int64_t kMaximumDataChunkSize = 512 * 1024; const int64_t kMaximumDataChunkSize = 512 * 1024;
uint32_t UnixToDosdate(const int64_t datetime) { uint32_t UnixToDosdate(const base::Time datetime) {
tm tm_datetime; base::Time::Exploded exploded;
localtime_r(&datetime, &tm_datetime); datetime.LocalExplode(&exploded);
return (tm_datetime.tm_year - 80) << 25 | (tm_datetime.tm_mon + 1) << 21 | return (exploded.year - 1980) << 25 | exploded.month << 21 |
tm_datetime.tm_mday << 16 | tm_datetime.tm_hour << 11 | exploded.day_of_month << 16 | exploded.hour << 11 |
tm_datetime.tm_min << 5 | (tm_datetime.tm_sec >> 1); exploded.minute << 5 | exploded.second >> 1;
} }
}; // namespace }; // namespace
...@@ -160,7 +160,7 @@ bool CompressorArchiveMinizip::CreateArchive() { ...@@ -160,7 +160,7 @@ bool CompressorArchiveMinizip::CreateArchive() {
bool CompressorArchiveMinizip::AddToArchive(const std::string& filename, bool CompressorArchiveMinizip::AddToArchive(const std::string& filename,
int64_t file_size, int64_t file_size,
int64_t modification_time, base::Time modification_time,
bool is_directory) { bool is_directory) {
// Minizip takes filenames that end with '/' as directories. // Minizip takes filenames that end with '/' as directories.
std::string normalized_filename = filename; std::string normalized_filename = filename;
...@@ -169,8 +169,7 @@ bool CompressorArchiveMinizip::AddToArchive(const std::string& filename, ...@@ -169,8 +169,7 @@ bool CompressorArchiveMinizip::AddToArchive(const std::string& filename,
// Fill zipfileMetadata with modification_time. // Fill zipfileMetadata with modification_time.
zip_fileinfo zipfileMetadata; zip_fileinfo zipfileMetadata;
// modification_time is millisecond-based, while FromTimeT takes seconds. zipfileMetadata.dos_date = UnixToDosdate(modification_time);
zipfileMetadata.dos_date = UnixToDosdate((int64_t)modification_time / 1000);
// Section 4.4.4 http://www.pkware.com/documents/casestudies/APPNOTE.TXT // Section 4.4.4 http://www.pkware.com/documents/casestudies/APPNOTE.TXT
// Setting the Language encoding flag so the file is told to be in utf-8. // Setting the Language encoding flag so the file is told to be in utf-8.
......
...@@ -49,7 +49,7 @@ class CompressorArchiveMinizip : public CompressorArchive { ...@@ -49,7 +49,7 @@ class CompressorArchiveMinizip : public CompressorArchive {
// Adds an entry to the archive. // Adds an entry to the archive.
bool AddToArchive(const std::string& filename, bool AddToArchive(const std::string& filename,
int64_t file_size, int64_t file_size,
int64_t modification_time, base::Time modification_time,
bool is_directory) override; bool is_directory) override;
// A getter function for zip_file_. // A getter function for zip_file_.
......
...@@ -46,8 +46,8 @@ const char kEntryId[] = "entry_id"; // Should be an int. ...@@ -46,8 +46,8 @@ const char kEntryId[] = "entry_id"; // Should be an int.
const char kPathname[] = "pathname"; // Should be a string. const char kPathname[] = "pathname"; // Should be a string.
const char kFileSize[] = "file_size"; // Should be a string. const char kFileSize[] = "file_size"; // Should be a string.
const char kIsDirectory[] = "is_directory"; // Should be a bool. const char kIsDirectory[] = "is_directory"; // Should be a bool.
const char kModificationTime[] = "modification_time"; // Should be a string // Local time in milliseconds since UNIX epoch, as a string.
// (mm/dd/yy h:m:s). const char kModificationTime[] = "modification_time";
const char kHasError[] = "has_error"; // Should be a bool. const char kHasError[] = "has_error"; // Should be a bool.
// Optional keys used for both packing and unpacking operations. // Optional keys used for both packing and unpacking operations.
......
...@@ -41,15 +41,15 @@ unpacker.request = { ...@@ -41,15 +41,15 @@ unpacker.request = {
COMPRESSOR_ID: 'compressor_id', // Should be an int. COMPRESSOR_ID: 'compressor_id', // Should be an int.
// Optional keys unique to packing operations. // Optional keys unique to packing operations.
ENTRY_ID: 'entry_id', // Should be an int. ENTRY_ID: 'entry_id', // Should be an int.
PATHNAME: 'pathname', // should be a string. PATHNAME: 'pathname', // should be a string.
FILE_SIZE: 'file_size', // should be a string. Same reason FILE_SIZE: 'file_size', // should be a string. Same reason
// as ARCHIVE_SIZE. // as ARCHIVE_SIZE.
IS_DIRECTORY: 'is_directory', // should be a boolean. IS_DIRECTORY: 'is_directory', // should be a boolean.
MODIFICATION_TIME: 'modification_time', // should be a string. // Local time in milliseconds since UNIX epoch, as a string.
// (mm/dd/yy h:m:s) MODIFICATION_TIME: 'modification_time',
HAS_ERROR: 'has_error', // Should be a boolean Sent from JS HAS_ERROR: 'has_error', // Should be a boolean Sent from JS
// to NaCL. // to NaCL.
// Optional keys used for both packing and unpacking operations. // Optional keys used for both packing and unpacking operations.
ERROR: 'error', // Should be a string. ERROR: 'error', // Should be a string.
......
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