Commit ebf9e7be authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Query Tiles: Delete unused code for image cache.

Removes unused code for image cache, we use components/image_fetcher
now.

Bug: 1058534
Change-Id: I2f33cd418249d1770dd44f8cbb381f9c718f8553
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2162108
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762042}
parent de3880c4
......@@ -13,12 +13,6 @@ source_set("internal") {
"cached_image_loader.h",
"config.cc",
"config.h",
"image_data_store.cc",
"image_data_store.h",
"image_decoder.cc",
"image_decoder.h",
"image_info_store.cc",
"image_info_store.h",
"image_loader.h",
"proto_conversion.cc",
"proto_conversion.h",
......@@ -43,7 +37,6 @@ source_set("internal") {
"//components/image_fetcher/core",
"//components/leveldb_proto",
"//net",
"//services/data_decoder/public/cpp",
"//services/network/public/cpp",
"//skia",
"//url",
......@@ -56,7 +49,6 @@ source_set("unit_tests") {
sources = [
"cached_image_loader_unittest.cc",
"image_decoder_unittest.cc",
"proto_conversion_unittest.cc",
"tile_fetcher_unittest.cc",
"tile_group_unittest.cc",
......@@ -74,7 +66,6 @@ source_set("unit_tests") {
"//components/image_fetcher/core:test_support",
"//components/leveldb_proto",
"//components/leveldb_proto:test_support",
"//services/data_decoder/public/cpp:test_support",
"//skia",
"//testing/gmock",
"//testing/gtest",
......
// Copyright 2020 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/upboarding/query_tiles/internal/image_data_store.h"
#include <utility>
#include "base/logging.h"
namespace upboarding {
namespace {
// An image data storage based on leveldb.
class ImageDataStoreImpl : public ImageDataStore {
public:
ImageDataStoreImpl() = default;
~ImageDataStoreImpl() override = default;
private:
// ImageDataStore implementation.
void Init(SuccessCallback callback) override { NOTIMPLEMENTED(); }
void Update(std::unique_ptr<ImageData> data,
SuccessCallback callback) override {
NOTIMPLEMENTED();
}
void GetImageData(const std::string& image_id,
ImageDataCallback callback) override {
NOTIMPLEMENTED();
}
void Delete(std::vector<std::string> image_ids,
SuccessCallback callback) override {
NOTIMPLEMENTED();
}
};
} // namespace
ImageData::ImageData(const std::string& id, std::string data)
: id_(id), data_(std::move(data)) {}
ImageData::~ImageData() = default;
void ImageData::TakeData(std::string* output) {
DCHECK(output);
output->swap(data_);
}
// static
std::unique_ptr<ImageDataStore> ImageDataStore::Create() {
return std::make_unique<ImageDataStoreImpl>();
}
} // namespace upboarding
// Copyright 2020 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.
#ifndef CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_DATA_STORE_H_
#define CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_DATA_STORE_H_
#include <memory>
#include <string>
#include <vector>
#include "base/callback.h"
namespace upboarding {
// Contains decoded image data.
// Serialized to ImageData protobuf in image.proto.
class ImageData {
public:
ImageData(const std::string& id, std::string data);
ImageData(const ImageData&) = delete;
ImageData& operator=(const ImageData&) = delete;
~ImageData();
const std::string& id() const { return id_; }
// Transfers the ownership of |data_|.
void TakeData(std::string* output);
private:
// Unique id of the image.
std::string id_;
// Raw bytes of the image.
std::string data_;
};
// Storage to save deoded query tile images' raw data.
// Only supports loads one image at a time.
class ImageDataStore {
public:
using SuccessCallback = base::OnceCallback<void(bool /*success*/)>;
using ImageDataCallback =
base::OnceCallback<void(std::unique_ptr<ImageData>)>;
static std::unique_ptr<ImageDataStore> Create();
ImageDataStore() = default;
ImageDataStore(const ImageDataStore&) = delete;
ImageDataStore& operator=(const ImageDataStore&) = delete;
virtual ~ImageDataStore() = default;
// Initializes the store.
virtual void Init(SuccessCallback callback) = 0;
// Updates one image.
virtual void Update(std::unique_ptr<ImageData> data,
SuccessCallback callback) = 0;
// Loads one image data into memory.
virtual void GetImageData(const std::string& image_id,
ImageDataCallback callback) = 0;
// Deletes images from the store.
virtual void Delete(std::vector<std::string> image_ids,
SuccessCallback callback) = 0;
};
} // namespace upboarding
#endif // CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_DATA_STORE_H_
// Copyright 2020 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/upboarding/query_tiles/internal/image_decoder.h"
#include <utility>
#include "services/data_decoder/public/cpp/decode_image.h"
#include "ui/gfx/geometry/size.h"
namespace upboarding {
namespace {
// The maximum size of data to be decoded.
constexpr size_t kMaximumEncodedDataSize = 10 * 1024 * 1024 /*10MB*/;
// Decodes an image in a utility process. Destroy the object will release the
// IPC connection.
class SafeImageDecoder : public ImageDecoder {
public:
SafeImageDecoder() = default;
SafeImageDecoder(const SafeImageDecoder&) = delete;
SafeImageDecoder& operator=(const SafeImageDecoder&) = delete;
~SafeImageDecoder() override = default;
private:
// ImageDecoder implementation.
void Decode(EncodedData data,
const gfx::Size& output_size,
DecodeCallback decode_callback) override {
DCHECK(decode_callback);
if (data.empty()) {
std::move(decode_callback).Run(SkBitmap());
return;
}
// Each decoding operation happens in its own process.
// TODO(xingliu): Consider to use a shared utility process.
data_decoder::DecodeImageIsolated(
std::move(data), data_decoder::mojom::ImageCodec::DEFAULT,
/*shrink_to_fit=*/true, kMaximumEncodedDataSize, output_size,
std::move(decode_callback));
}
};
} // namespace
// static
std::unique_ptr<ImageDecoder> ImageDecoder::Create() {
return std::make_unique<SafeImageDecoder>();
}
ImageDecoder::ImageDecoder() = default;
ImageDecoder::~ImageDecoder() = default;
} // namespace upboarding
// Copyright 2020 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.
#ifndef CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_DECODER_H_
#define CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_DECODER_H_
#include <memory>
#include <vector>
#include "base/callback.h"
namespace gfx {
class Size;
} // namespace gfx
class SkBitmap;
namespace upboarding {
// Decodes an image into bitmap, to be consumed by UI.
class ImageDecoder {
public:
using DecodeCallback = base::OnceCallback<void(const SkBitmap&)>;
using EncodedData = std::vector<uint8_t>;
static std::unique_ptr<ImageDecoder> Create();
ImageDecoder(const ImageDecoder&) = delete;
ImageDecoder& operator=(const ImageDecoder&) = delete;
virtual ~ImageDecoder();
// Decodes the image. |data| should be moved into this function.
virtual void Decode(EncodedData data,
const gfx::Size& output_size,
DecodeCallback decode_callback) = 0;
protected:
ImageDecoder();
};
} // namespace upboarding
#endif // CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_DECODER_H_
// Copyright 2020 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/upboarding/query_tiles/internal/image_decoder.h"
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
namespace upboarding {
namespace {
const base::FilePath::CharType kTestDataDir[] =
FILE_PATH_LITERAL("chrome/test/data/image_decoding/droids.jpg");
class ImageDecoderTest : public testing::Test {
public:
ImageDecoderTest() = default;
ImageDecoderTest(const ImageDecoderTest&) = delete;
ImageDecoderTest& operator=(const ImageDecoderTest&) = delete;
~ImageDecoderTest() override = default;
void SetUp() override { image_decoder_ = ImageDecoder::Create(); }
protected:
void Decode(ImageDecoder::EncodedData data,
const gfx::Size& size,
ImageDecoder::DecodeCallback callback) {
image_decoder_->Decode(std::move(data), size, std::move(callback));
}
private:
// Needed test support objects.
base::test::TaskEnvironment task_environment_;
data_decoder::test::InProcessDataDecoder decoder_service;
std::unique_ptr<ImageDecoder> image_decoder_;
};
// Verifies empty input will result in empty output.
TEST_F(ImageDecoderTest, DecodeEmpty) {
base::RunLoop loop;
auto callback = base::BindLambdaForTesting([&](const SkBitmap& bitmap) {
EXPECT_TRUE(bitmap.empty());
loop.Quit();
});
Decode(ImageDecoder::EncodedData(), gfx::Size(1, 1), std::move(callback));
loop.Run();
}
// Decodes an image.
TEST_F(ImageDecoderTest, Decode) {
// Read in a test image.
base::FilePath data_dir;
ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, &data_dir));
base::FilePath file_path = data_dir.Append(base::FilePath(kTestDataDir));
std::string file_data;
ASSERT_TRUE(base::ReadFileToString(file_path, &file_data));
EXPECT_FALSE(file_data.empty());
ImageDecoder::EncodedData data(file_data.begin(), file_data.end());
EXPECT_FALSE(data.empty());
// Decode the image data.
base::RunLoop loop;
auto callback = base::BindLambdaForTesting([&](const SkBitmap& bitmap) {
EXPECT_FALSE(bitmap.empty());
loop.Quit();
});
Decode(std::move(data), gfx::Size(16, 16), std::move(callback));
loop.Run();
}
} // namespace
} // namespace upboarding
// Copyright 2020 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/upboarding/query_tiles/internal/image_info_store.h"
#include <utility>
#include "base/logging.h"
namespace upboarding {
namespace {
class ImageInfoStoreImpl : public ImageInfoStore {
public:
ImageInfoStoreImpl() = default;
~ImageInfoStoreImpl() override = default;
private:
void InitAndLoad(Store::LoadCallback callback) override { NOTIMPLEMENTED(); }
void Update(const std::string& key,
const ImageInfo& entry,
Store::UpdateCallback callback) override {
NOTIMPLEMENTED();
}
void Delete(const std::string& key, Store::DeleteCallback callback) override {
NOTIMPLEMENTED();
}
};
} // namespace
// static
std::unique_ptr<ImageInfoStore> ImageInfoStore::Create() {
return std::make_unique<ImageInfoStoreImpl>();
}
} // namespace upboarding
// Copyright 2020 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.
#ifndef CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_INFO_STORE_H_
#define CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_INFO_STORE_H_
#include <map>
#include <memory>
#include <string>
#include "base/callback.h"
#include "base/time/time.h"
#include "chrome/browser/upboarding/query_tiles/internal/store.h"
#include "url/gurl.h"
namespace upboarding {
// Contains information for a query tile image. This doesn't include the raw
// bytes of the image.
// Serialized to ImageInfo protobuf in image.proto.
struct ImageInfo {
// Unique image id.
std::string id;
// URL of the image.
GURL url;
// The most recent update time, image will be expired after a certain period
// of time,
base::Time last_update;
};
// Store to save query tiles image info.
class ImageInfoStore : public Store<ImageInfo> {
public:
ImageInfoStore() = default;
~ImageInfoStore() override = default;
static std::unique_ptr<ImageInfoStore> Create();
};
} // namespace upboarding
#endif // CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_IMAGE_INFO_STORE_H_
......@@ -5,8 +5,5 @@
import("//third_party/protobuf/proto_library.gni")
proto_library("proto") {
sources = [
"image.proto",
"tile.proto",
]
sources = [ "tile.proto" ]
}
// Copyright 2020 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.
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package upboarding.query_tiles.proto;
// Information of a query tile image, doesn't contain image raw bytes.
// Next tag: 4
message ImageInfo {
// Unique id of the image.
string id = 1;
// URL of the image.
string url = 2;
// The last update time in milliseconds since epoch, image will be expired
// after a certain amount of time.
int64 last_update_time_ms = 3;
}
// Contains the decoded image bytes.
// Next tag: 3
message ImageData {
// Unique id of the image.
string id = 1;
// Decoded image data.
bytes data = 2;
}
\ No newline at end of file
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