blob: f3c735fe670845bb64ab9dc1ff33584b8e5391d9 [file] [log] [blame]
// Copyright 2019 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/updater/unzipper.h"
#include <string>
#include <utility>
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/time/time.h"
#include "third_party/zlib/google/zip.h"
namespace cobalt {
namespace updater {
namespace {
class UnzipperImpl : public update_client::Unzipper {
public:
UnzipperImpl() = default;
void Unzip(const base::FilePath& zip_path,
const base::FilePath& output_path,
UnzipCompleteCallback callback) override {
int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
std::move(callback).Run(zip::Unzip(zip_path, output_path));
int64_t time_unzip_took_usec =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip;
LOG(INFO) << "Unzip file path = " << zip_path;
LOG(INFO) << "output_path = " << output_path;
LOG(INFO) << "Unzip took "
<< time_unzip_took_usec / base::Time::kMicrosecondsPerMillisecond
<< " milliseconds.";
}
#if defined(IN_MEMORY_UPDATES)
void Unzip(const std::string& zip_str, const base::FilePath& output_path,
UnzipCompleteCallback callback) override {
int64_t time_before_unzip = (base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds();
std::move(callback).Run(zip::Unzip(zip_str, output_path));
int64_t time_unzip_took_usec =
(base::TimeTicks::Now() - base::TimeTicks()).InMicroseconds() - time_before_unzip;
LOG(INFO) << "Unzip from string";
LOG(INFO) << "output_path = " << output_path;
LOG(INFO) << "Unzip took "
<< time_unzip_took_usec / base::Time::kMicrosecondsPerMillisecond
<< " milliseconds.";
}
#endif
};
} // namespace
UnzipperFactory::UnzipperFactory() = default;
std::unique_ptr<update_client::Unzipper> UnzipperFactory::Create() const {
return std::make_unique<UnzipperImpl>();
}
UnzipperFactory::~UnzipperFactory() = default;
} // namespace updater
} // namespace cobalt