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

Upboarding: Setup image cache persistence layer boilerplates.

This CL adds image cache protobuf and store interfaces. No
implementation is added yet.

The raw bytes are saved in a separate store, which only supports loading
one image at a time in its API.

Bug: 1058534
Change-Id: I0646b9906b81432e39f29dd5f235481d12a756c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2108180Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751729}
parent 4c2997ed
...@@ -9,8 +9,12 @@ if (is_android) { ...@@ -9,8 +9,12 @@ if (is_android) {
source_set("internal") { source_set("internal") {
sources = [ sources = [
"image_data_store.cc",
"image_data_store.h",
"image_decoder.cc", "image_decoder.cc",
"image_decoder.h", "image_decoder.h",
"image_info_store.cc",
"image_info_store.h",
"image_loader.cc", "image_loader.cc",
"image_loader.h", "image_loader.h",
"proto_conversion.cc", "proto_conversion.cc",
......
// 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_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_
...@@ -20,8 +20,7 @@ namespace upboarding { ...@@ -20,8 +20,7 @@ namespace upboarding {
// on disk. // on disk.
class ImageLoader { class ImageLoader {
public: public:
using UpdateCallback = base::OnceCallback<bool>; using SuccessCallback = base::OnceCallback<bool>;
using DeleteCallback = base::OnceCallback<bool>;
using BitmapCallback = base::OnceCallback<std::unique_ptr<SkBitmap>>; using BitmapCallback = base::OnceCallback<std::unique_ptr<SkBitmap>>;
using Id = std::string; using Id = std::string;
...@@ -32,9 +31,9 @@ class ImageLoader { ...@@ -32,9 +31,9 @@ class ImageLoader {
// immediately fetch the image, then invoke the callback. // immediately fetch the image, then invoke the callback.
virtual void Update(const Id& id, virtual void Update(const Id& id,
const GURL& url, const GURL& url,
UpdateCallback callback) = 0; SuccessCallback callback) = 0;
// Deletes an image cache for a specific tile. // Deletes an image cache for a specific tile.
virtual void Delete(const Id& id, DeleteCallback callback) = 0; virtual void Delete(const Id& id, SuccessCallback callback) = 0;
// Gets the bitmap for a specific tile. Callback will be invoked after // Gets the bitmap for a specific tile. Callback will be invoked after
// reading the data from disk or the fetch is done. // reading the data from disk or the fetch is done.
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#ifndef CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_STORE_H_ #ifndef CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_STORE_H_
#define CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_STORE_H_ #define CHROME_BROWSER_UPBOARDING_QUERY_TILES_INTERNAL_STORE_H_
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
namespace upboarding { namespace upboarding {
......
...@@ -5,5 +5,8 @@ ...@@ -5,5 +5,8 @@
import("//third_party/protobuf/proto_library.gni") import("//third_party/protobuf/proto_library.gni")
proto_library("proto") { proto_library("proto") {
sources = [ "query_tile_entry.proto" ] sources = [
"image.proto",
"query_tile_entry.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
...@@ -9,15 +9,15 @@ option optimize_for = LITE_RUNTIME; ...@@ -9,15 +9,15 @@ option optimize_for = LITE_RUNTIME;
package upboarding.query_tiles.proto; package upboarding.query_tiles.proto;
// The QuertTileEntry is the schema to represent data in query tile entry. // The QuertTileEntry is the schema to represent data in query tile entry.
// Next tag:7 // Next tag: 7
message QueryTileEntry { message QueryTileEntry {
// Metadata about the image. // Metadata about the image.
// Next tag:3 // Next tag: 3
message ImageMetadata { message ImageMetadata {
// Unique id of the query tile image. // Unique id of the query tile image.
string id = 1; string id = 1;
// Origin URL of the image. // URL of the image.
string url = 2; string url = 2;
} }
......
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