Commit f57a1c98 authored by Gang Wu's avatar Gang Wu Committed by Commit Bot

[Feed] Remove old storage implementation

Remove old storage implementation for both Java and C++.

Bug: 828935
Change-Id: Ib6144e206b513272510763559337dc6aa16e06b6
Reviewed-on: https://chromium-review.googlesource.com/1185794Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Gang Wu <gangwu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585645}
parent 6988b464
// 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.
package org.chromium.chrome.browser.feed;
import org.chromium.base.Callback;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.profiles.Profile;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Provides access to native implementations of content storage and journal storage.
*/
@JNINamespace("feed")
public class FeedStorageBridge {
private long mNativeFeedStorageBridge;
/**
* Creates a {@link FeedStorageBridge} for accessing native content and journal storage
* implementation for the current user, and initial native side bridge.
*
* @param profile {@link Profile} of the user we are rendering the Feed for.
*/
public FeedStorageBridge() {}
/**
* Inits native side bridge.
*
* @param profile {@link Profile} of the user we are rendering the Feed for.
*/
public void init(Profile profile) {
mNativeFeedStorageBridge = nativeInit(profile);
}
/** Cleans up native half of this bridge. */
public void destroy() {
assert mNativeFeedStorageBridge != 0;
nativeDestroy(mNativeFeedStorageBridge);
mNativeFeedStorageBridge = 0;
}
public void loadContent(List<String> keys, Callback<Map<String, byte[]>> callback) {
assert mNativeFeedStorageBridge != 0;
String[] keysArray = keys.toArray(new String[keys.size()]);
nativeLoadContent(mNativeFeedStorageBridge, keysArray, callback);
}
public void loadContentByPrefix(String prefix, Callback<Map<String, byte[]>> callback) {
assert mNativeFeedStorageBridge != 0;
nativeLoadContentByPrefix(mNativeFeedStorageBridge, prefix, callback);
}
public void loadAllContentKeys(Callback<List<String>> callback) {
assert mNativeFeedStorageBridge != 0;
nativeLoadAllContentKeys(mNativeFeedStorageBridge, callback);
}
public void saveContent(String[] keys, byte[][] data, Callback<Boolean> callback) {
assert mNativeFeedStorageBridge != 0;
nativeSaveContent(mNativeFeedStorageBridge, keys, data, callback);
}
public void deleteContent(List<String> keys, Callback<Boolean> callback) {
assert mNativeFeedStorageBridge != 0;
String[] keysArray = keys.toArray(new String[keys.size()]);
nativeDeleteContent(mNativeFeedStorageBridge, keysArray, callback);
}
public void deleteContentByPrefix(String prefix, Callback<Boolean> callback) {
assert mNativeFeedStorageBridge != 0;
nativeDeleteContentByPrefix(mNativeFeedStorageBridge, prefix, callback);
}
public void deleteAllContent(Callback<Boolean> callback) {
assert mNativeFeedStorageBridge != 0;
nativeDeleteAllContent(mNativeFeedStorageBridge, callback);
}
@CalledByNative
private static Object createKeyAndDataMap(String[] keys, byte[][] data) {
assert keys.length == data.length;
Map<String, byte[]> valueMap = new HashMap<>(keys.length);
for (int i = 0; i < keys.length && i < data.length; ++i) {
valueMap.put(keys[i], data[i]);
}
return valueMap;
}
@CalledByNative
private static List<String> createJavaList(String[] keys) {
return Arrays.asList(keys);
}
private native long nativeInit(Profile profile);
private native void nativeDestroy(long nativeFeedStorageBridge);
private native void nativeLoadContent(
long nativeFeedStorageBridge, String[] keys, Callback<Map<String, byte[]>> callback);
private native void nativeLoadContentByPrefix(
long nativeFeedStorageBridge, String prefix, Callback<Map<String, byte[]>> callback);
private native void nativeLoadAllContentKeys(
long nativeFeedStorageBridge, Callback<List<String>> callback);
private native void nativeSaveContent(
long nativeFeedStorageBridge, String[] keys, byte[][] data, Callback<Boolean> callback);
private native void nativeDeleteContent(
long nativeFeedStorageBridge, String[] keys, Callback<Boolean> callback);
private native void nativeDeleteContentByPrefix(
long nativeFeedStorageBridge, String prefix, Callback<Boolean> callback);
private native void nativeDeleteAllContent(
long nativeFeedStorageBridge, Callback<Boolean> callback);
}
......@@ -24,7 +24,6 @@ if (enable_feed_in_chrome) {
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedRefreshTask.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedScheduler.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedSchedulerBridge.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedStorageBridge.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/StreamLifecycleManager.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/TestFeedScheduler.java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/TestNetworkClient.java",
......
......@@ -4421,8 +4421,6 @@ jumbo_split_static_library("browser") {
"android/feed/feed_network_bridge.h",
"android/feed/feed_scheduler_bridge.cc",
"android/feed/feed_scheduler_bridge.h",
"android/feed/feed_storage_bridge.cc",
"android/feed/feed_storage_bridge.h",
]
deps += [ "//components/feed/core:feed_core" ]
}
......@@ -4694,7 +4692,6 @@ if (is_android) {
"../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedJournalBridge.java",
"../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedNetworkBridge.java",
"../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedSchedulerBridge.java",
"../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedStorageBridge.java",
]
}
......
......@@ -21,7 +21,6 @@
#include "components/feed/core/feed_journal_database.h"
#include "components/feed/core/feed_networking_host.h"
#include "components/feed/core/feed_scheduler_host.h"
#include "components/feed/core/feed_storage_database.h"
#include "components/image_fetcher/core/image_fetcher_impl.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/version_info/version_info.h"
......@@ -90,16 +89,14 @@ KeyedService* FeedHostServiceFactory::BuildServiceInstanceFor(
profile->GetPrefs(), g_browser_process->local_state(),
base::DefaultClock::GetInstance());
auto storage_database = std::make_unique<FeedStorageDatabase>(feed_dir);
auto content_database = std::make_unique<FeedContentDatabase>(feed_dir);
auto journal_database = std::make_unique<FeedJournalDatabase>(feed_dir);
return new FeedHostService(
std::move(image_manager), std::move(networking_host),
std::move(scheduler_host), std::move(storage_database),
std::move(content_database), std::move(journal_database));
std::move(scheduler_host), std::move(content_database),
std::move(journal_database));
}
content::BrowserContext* FeedHostServiceFactory::GetBrowserContextToUse(
......
// 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/android/feed/feed_storage_bridge.h"
#include <jni.h>
#include <string>
#include <vector>
#include "base/android/callback_android.h"
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/bind.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/android/feed/feed_host_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h"
#include "components/feed/core/feed_host_service.h"
#include "components/feed/core/feed_storage_database.h"
#include "jni/FeedStorageBridge_jni.h"
#include "ui/gfx/android/java_bitmap.h"
#include "ui/gfx/image/image.h"
namespace feed {
using base::android::AppendJavaStringArrayToStringVector;
using base::android::AttachCurrentThread;
using base::android::ConvertJavaStringToUTF8;
using base::android::JavaArrayOfByteArrayToStringVector;
using base::android::JavaIntArrayToIntVector;
using base::android::JavaRef;
using base::android::JavaParamRef;
using base::android::ScopedJavaGlobalRef;
using base::android::ScopedJavaLocalRef;
using base::android::ToJavaArrayOfByteArray;
using base::android::ToJavaArrayOfStrings;
static jlong JNI_FeedStorageBridge_Init(
JNIEnv* env,
const JavaParamRef<jobject>& j_this,
const JavaParamRef<jobject>& j_profile) {
Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile);
FeedHostService* host_service =
FeedHostServiceFactory::GetForBrowserContext(profile);
DCHECK(host_service);
FeedStorageDatabase* feed_storage_database =
host_service->GetStorageDatabase();
DCHECK(feed_storage_database);
FeedStorageBridge* native_storage_bridge =
new FeedStorageBridge(feed_storage_database);
return reinterpret_cast<intptr_t>(native_storage_bridge);
}
FeedStorageBridge::FeedStorageBridge(FeedStorageDatabase* feed_storage_database)
: feed_storage_database_(feed_storage_database), weak_ptr_factory_(this) {}
FeedStorageBridge::~FeedStorageBridge() = default;
void FeedStorageBridge::Destroy(JNIEnv* env, const JavaRef<jobject>& j_this) {
delete this;
}
void FeedStorageBridge::LoadContent(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobjectArray>& j_keys,
const JavaRef<jobject>& j_callback) {
std::vector<std::string> keys;
AppendJavaStringArrayToStringVector(j_env, j_keys.obj(), &keys);
ScopedJavaGlobalRef<jobject> callback(j_callback);
feed_storage_database_->LoadContent(
keys, base::BindOnce(&FeedStorageBridge::OnLoadContentDone,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void FeedStorageBridge::LoadContentByPrefix(
JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jstring>& j_prefix,
const JavaRef<jobject>& j_callback) {
std::string prefix = ConvertJavaStringToUTF8(j_env, j_prefix);
ScopedJavaGlobalRef<jobject> callback(j_callback);
feed_storage_database_->LoadContentByPrefix(
prefix, base::BindOnce(&FeedStorageBridge::OnLoadContentDone,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void FeedStorageBridge::LoadAllContentKeys(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobject>& j_callback) {
ScopedJavaGlobalRef<jobject> callback(j_callback);
feed_storage_database_->LoadAllContentKeys(
base::BindOnce(&FeedStorageBridge::OnLoadAllContentKeysDone,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void FeedStorageBridge::SaveContent(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobjectArray>& j_keys,
const JavaRef<jobjectArray>& j_data,
const JavaRef<jobject>& j_callback) {
std::vector<std::string> keys;
std::vector<std::string> data;
AppendJavaStringArrayToStringVector(j_env, j_keys.obj(), &keys);
JavaArrayOfByteArrayToStringVector(j_env, j_data.obj(), &data);
ScopedJavaGlobalRef<jobject> callback(j_callback);
DCHECK_EQ(keys.size(), data.size());
std::vector<FeedStorageDatabase::KeyAndData> pairs;
for (size_t i = 0; i < keys.size() && i < data.size(); ++i) {
pairs.emplace_back(keys[i], data[i]);
}
feed_storage_database_->SaveContent(
std::move(pairs),
base::BindOnce(&FeedStorageBridge::OnStorageCommitDone,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void FeedStorageBridge::DeleteContent(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobjectArray>& j_keys,
const JavaRef<jobject>& j_callback) {
std::vector<std::string> keys;
AppendJavaStringArrayToStringVector(j_env, j_keys.obj(), &keys);
ScopedJavaGlobalRef<jobject> callback(j_callback);
feed_storage_database_->DeleteContent(
keys, base::BindOnce(&FeedStorageBridge::OnStorageCommitDone,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void FeedStorageBridge::DeleteContentByPrefix(
JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jstring>& j_prefix,
const JavaRef<jobject>& j_callback) {
std::string prefix = ConvertJavaStringToUTF8(j_env, j_prefix);
ScopedJavaGlobalRef<jobject> callback(j_callback);
feed_storage_database_->DeleteContentByPrefix(
prefix, base::BindOnce(&FeedStorageBridge::OnStorageCommitDone,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void FeedStorageBridge::DeleteAllContent(JNIEnv* j_env,
const JavaRef<jobject>& j_this,
const JavaRef<jobject>& j_callback) {
ScopedJavaGlobalRef<jobject> callback(j_callback);
feed_storage_database_->DeleteAllContent(
base::BindOnce(&FeedStorageBridge::OnStorageCommitDone,
weak_ptr_factory_.GetWeakPtr(), callback));
}
void FeedStorageBridge::OnLoadContentDone(
ScopedJavaGlobalRef<jobject> callback,
std::vector<FeedStorageDatabase::KeyAndData> pairs) {
std::vector<std::string> keys;
std::vector<std::string> data;
for (auto pair : pairs) {
keys.push_back(std::move(pair.first));
data.push_back(std::move(pair.second));
}
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobjectArray> j_keys = ToJavaArrayOfStrings(env, keys);
ScopedJavaLocalRef<jobjectArray> j_data = ToJavaArrayOfByteArray(env, data);
// Ceate Java Map by JNI call.
ScopedJavaLocalRef<jobject> j_pairs =
Java_FeedStorageBridge_createKeyAndDataMap(env, j_keys, j_data);
RunObjectCallbackAndroid(callback, j_pairs);
}
void FeedStorageBridge::OnLoadAllContentKeysDone(
ScopedJavaGlobalRef<jobject> callback,
std::vector<std::string> keys) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobjectArray> j_keys = ToJavaArrayOfStrings(env, keys);
// Ceate Java List by JNI call.
ScopedJavaLocalRef<jobject> j_keys_list =
Java_FeedStorageBridge_createJavaList(env, j_keys);
RunObjectCallbackAndroid(callback, j_keys_list);
}
void FeedStorageBridge::OnStorageCommitDone(
ScopedJavaGlobalRef<jobject> callback,
bool success) {
RunBooleanCallbackAndroid(callback, success);
}
} // namespace feed
// 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.
#ifndef CHROME_BROWSER_ANDROID_FEED_FEED_STORAGE_BRIDGE_H_
#define CHROME_BROWSER_ANDROID_FEED_FEED_STORAGE_BRIDGE_H_
#include "base/android/scoped_java_ref.h"
#include "base/memory/weak_ptr.h"
#include "components/feed/core/feed_storage_database.h"
namespace feed {
class FeedStorageDatabase;
// Native counterpart of FeedStorageBridge.java. Holds non-owning pointers
// to native implementation, to which operations are delegated. Results are
// passed back by a single argument callback so
// base::android::RunBooleanCallbackAndroid() and
// base::android::RunObjectCallbackAndroid() can be used. This bridge is
// instantiated, owned, and destroyed from Java.
class FeedStorageBridge {
public:
explicit FeedStorageBridge(FeedStorageDatabase* feed_Storage_database);
~FeedStorageBridge();
void Destroy(JNIEnv* j_env, const base::android::JavaRef<jobject>& j_this);
void LoadContent(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobjectArray>& j_keys,
const base::android::JavaRef<jobject>& j_callback);
void LoadContentByPrefix(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_prefix,
const base::android::JavaRef<jobject>& j_callback);
void LoadAllContentKeys(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback);
void SaveContent(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobjectArray>& j_keys,
const base::android::JavaRef<jobjectArray>& j_data,
const base::android::JavaRef<jobject>& j_callback);
void DeleteContent(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobjectArray>& j_keys,
const base::android::JavaRef<jobject>& j_callback);
void DeleteContentByPrefix(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_prefix,
const base::android::JavaRef<jobject>& j_callback);
void DeleteAllContent(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback);
private:
void OnLoadContentDone(base::android::ScopedJavaGlobalRef<jobject> callback,
std::vector<FeedStorageDatabase::KeyAndData> pairs);
void OnLoadAllContentKeysDone(
base::android::ScopedJavaGlobalRef<jobject> callback,
std::vector<std::string> keys);
void OnStorageCommitDone(base::android::ScopedJavaGlobalRef<jobject> callback,
bool success);
FeedStorageDatabase* feed_storage_database_;
base::WeakPtrFactory<FeedStorageBridge> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FeedStorageBridge);
};
} // namespace feed
#endif // CHROME_BROWSER_ANDROID_FEED_FEED_STORAGE_BRIDGE_H_
......@@ -30,8 +30,6 @@ source_set("feed_core") {
"feed_networking_host.h",
"feed_scheduler_host.cc",
"feed_scheduler_host.h",
"feed_storage_database.cc",
"feed_storage_database.h",
"pref_names.cc",
"pref_names.h",
"refresh_throttler.cc",
......@@ -85,7 +83,6 @@ source_set("core_unit_tests") {
"feed_journal_mutation_unittest.cc",
"feed_networking_host_unittest.cc",
"feed_scheduler_host_unittest.cc",
"feed_storage_database_unittest.cc",
"refresh_throttler_unittest.cc",
"user_classifier_unittest.cc",
]
......
......@@ -12,13 +12,11 @@ FeedHostService::FeedHostService(
std::unique_ptr<FeedImageManager> image_manager,
std::unique_ptr<FeedNetworkingHost> networking_host,
std::unique_ptr<FeedSchedulerHost> scheduler_host,
std::unique_ptr<FeedStorageDatabase> storage_database,
std::unique_ptr<FeedContentDatabase> content_database,
std::unique_ptr<FeedJournalDatabase> journal_database)
: image_manager_(std::move(image_manager)),
networking_host_(std::move(networking_host)),
scheduler_host_(std::move(scheduler_host)),
storage_database_(std::move(storage_database)),
content_database_(std::move(content_database)),
journal_database_(std::move(journal_database)) {}
......@@ -36,10 +34,6 @@ FeedSchedulerHost* FeedHostService::GetSchedulerHost() {
return scheduler_host_.get();
}
FeedStorageDatabase* FeedHostService::GetStorageDatabase() {
return storage_database_.get();
}
FeedContentDatabase* FeedHostService::GetContentDatabase() {
return content_database_.get();
}
......
......@@ -13,7 +13,6 @@
#include "components/feed/core/feed_journal_database.h"
#include "components/feed/core/feed_networking_host.h"
#include "components/feed/core/feed_scheduler_host.h"
#include "components/feed/core/feed_storage_database.h"
#include "components/keyed_service/core/keyed_service.h"
namespace feed {
......@@ -28,7 +27,6 @@ class FeedHostService : public KeyedService {
FeedHostService(std::unique_ptr<FeedImageManager> image_manager,
std::unique_ptr<FeedNetworkingHost> networking_host,
std::unique_ptr<FeedSchedulerHost> scheduler_host,
std::unique_ptr<FeedStorageDatabase> storage_database,
std::unique_ptr<FeedContentDatabase> content_database,
std::unique_ptr<FeedJournalDatabase> journal_database);
~FeedHostService() override;
......@@ -36,7 +34,6 @@ class FeedHostService : public KeyedService {
FeedImageManager* GetImageManager();
FeedNetworkingHost* GetNetworkingHost();
FeedSchedulerHost* GetSchedulerHost();
FeedStorageDatabase* GetStorageDatabase();
FeedContentDatabase* GetContentDatabase();
FeedJournalDatabase* GetJournalDatabase();
......@@ -44,7 +41,6 @@ class FeedHostService : public KeyedService {
std::unique_ptr<FeedImageManager> image_manager_;
std::unique_ptr<FeedNetworkingHost> networking_host_;
std::unique_ptr<FeedSchedulerHost> scheduler_host_;
std::unique_ptr<FeedStorageDatabase> storage_database_;
std::unique_ptr<FeedContentDatabase> content_database_;
std::unique_ptr<FeedJournalDatabase> journal_database_;
......
This diff is collapsed.
// 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.
#ifndef COMPONENTS_FEED_CORE_FEED_STORAGE_DATABASE_H_
#define COMPONENTS_FEED_CORE_FEED_STORAGE_DATABASE_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "components/leveldb_proto/proto_database.h"
namespace feed {
class FeedStorageProto;
// FeedStorageDatabase is leveldb backed store for feed's content storage data
// and jounal storage data.
class FeedStorageDatabase {
public:
enum State {
UNINITIALIZED,
INITIALIZED,
INIT_FAILURE,
};
using KeyAndData = std::pair<std::string, std::string>;
// Returns the storage data as a vector of key-value pairs when calling
// loading data.
using ContentLoadCallback = base::OnceCallback<void(std::vector<KeyAndData>)>;
// Returns the content keys as a vector when calling loading all content keys.
using ContentKeyCallback = base::OnceCallback<void(std::vector<std::string>)>;
// Returns the journal data as a vector of strings when calling loading data
// or keys.
using JournalLoadCallback =
base::OnceCallback<void(std::vector<std::string>)>;
// Returns whether the commit operation succeeded when calling for database
// operations, or return whether the entry exists when calling for checking
// the entry's existence.
using ConfirmationCallback = base::OnceCallback<void(bool)>;
// Initializes the database with |database_folder|.
explicit FeedStorageDatabase(const base::FilePath& database_folder);
// Initializes the database with |database_folder|. Creates storage using the
// given |storage_database| for local storage. Useful for testing.
FeedStorageDatabase(
const base::FilePath& database_folder,
std::unique_ptr<leveldb_proto::ProtoDatabase<FeedStorageProto>>
storage_database);
~FeedStorageDatabase();
// Returns true if initialization has finished successfully, else false.
// While this is false, initialization may already started, or initialization
// failed.
bool IsInitialized() const;
// Loads the content data for the |keys| and passes them to |callback|.
void LoadContent(const std::vector<std::string>& keys,
ContentLoadCallback callback);
// Loads the content data whose key matches |prefix|, and passes them to
// |callback|.
void LoadContentByPrefix(const std::string& prefix,
ContentLoadCallback callback);
// Loads all content keys in the storage, and passes them to |callback|.
void LoadAllContentKeys(ContentKeyCallback callback);
// Inserts or updates the content data |pairs|, |callback| will be called when
// the data are saved or if there is an error. The fields in |pairs| will be
// std::move.
void SaveContent(std::vector<KeyAndData> pairs,
ConfirmationCallback callback);
// Deletes the content data for |keys_to_delete|, |callback| will be called
// when the data are deleted or if there is an error.
void DeleteContent(const std::vector<std::string>& keys_to_delete,
ConfirmationCallback callback);
// Deletes the content data whose key matches |prefix_to_delete|, |callback|
// will be called when the content are deleted or if there is an error.
void DeleteContentByPrefix(const std::string& prefix_to_delete,
ConfirmationCallback callback);
// Delete all content, |callback| will be called when all content is deleted
// or if there is an error.
void DeleteAllContent(ConfirmationCallback callback);
// Loads the journal data for the |key| and passes it to |callback|.
void LoadJournal(const std::string& key, JournalLoadCallback callback);
// Checks if the journal for the |key| exists, and return the result to
// |callback|.
void DoesJournalExist(const std::string& key, ConfirmationCallback callback);
// Loads all journal keys in the storage, and passes them to |callback|.
void LoadAllJournalKeys(JournalLoadCallback callback);
// Appends |entries| to a journal whose key is |key|, if there the journal do
// not exist, create one. |callback| will be called when the data are saved or
// if there is an error.
void AppendToJournal(const std::string& key,
std::vector<std::string> entries,
ConfirmationCallback callback);
// Creates a new journal with name |to_key|, and copys all data from the
// journal with |from_key| to it. |callback| will be called when the data are
// saved or if there is an error.
void CopyJournal(const std::string& from_key,
const std::string& to_key,
ConfirmationCallback callback);
// Deletes the journal with |key|, |callback| will be called when the journal
// is deleted or if there is an error.
void DeleteJournal(const std::string& key, ConfirmationCallback callback);
// Delete all journals, |callback| will be called when all journals are
// deleted or if there is an error.
void DeleteAllJournals(ConfirmationCallback callback);
private:
// Callback methods given to |storage_database_| for async responses.
void OnDatabaseInitialized(bool success);
void OnLoadEntriesForLoadContent(
ContentLoadCallback callback,
bool success,
std::unique_ptr<std::vector<FeedStorageProto>> content);
void OnLoadKeysForLoadAllContentKeys(
ContentKeyCallback callback,
bool success,
std::unique_ptr<std::vector<std::string>> keys);
void OnGetEntryForLoadJournal(JournalLoadCallback callback,
bool success,
std::unique_ptr<FeedStorageProto> journal);
void OnGetEntryForDoesJournalExist(ConfirmationCallback callback,
bool success,
std::unique_ptr<FeedStorageProto> journal);
void OnGetEntryAppendToJournal(ConfirmationCallback callback,
const std::string& key,
std::vector<std::string> entries,
bool success,
std::unique_ptr<FeedStorageProto> journal);
void OnGetEntryForCopyJournal(ConfirmationCallback callback,
const std::string& to_key,
bool success,
std::unique_ptr<FeedStorageProto> journal);
void OnLoadKeysForLoadAllJournalKeys(
JournalLoadCallback callback,
bool success,
std::unique_ptr<std::vector<std::string>> keys);
void OnStorageCommitted(ConfirmationCallback callback, bool success);
State database_status_;
std::unique_ptr<leveldb_proto::ProtoDatabase<FeedStorageProto>>
storage_database_;
SEQUENCE_CHECKER(sequence_checker_);
base::WeakPtrFactory<FeedStorageDatabase> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FeedStorageDatabase);
};
} // namespace feed
#endif // COMPONENTS_FEED_CORE_FEED_STORAGE_DATABASE_H_
This diff is collapsed.
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