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

[Feed] Implement Journal storage JNI call

Implement Journal storage JNI call from java bridge to C++ bridge.
C++ bridge empty now, will implement C++ bridge in separate CL. Also,
will delete old storage stuff like bridge, database in separate CL as
well.

Bug:875902

Change-Id: Ia8adf37bd6bf7f6d5b47f8258cf886617930bb69
Reviewed-on: https://chromium-review.googlesource.com/1180727
Commit-Queue: Gang Wu <gangwu@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585172}
parent a75983ce
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
package org.chromium.chrome.browser.feed; package org.chromium.chrome.browser.feed;
import com.google.android.libraries.feed.host.storage.JournalMutation; import com.google.android.libraries.feed.host.storage.JournalMutation;
import com.google.android.libraries.feed.host.storage.JournalOperation;
import com.google.android.libraries.feed.host.storage.JournalOperation.Append;
import com.google.android.libraries.feed.host.storage.JournalOperation.Copy;
import com.google.android.libraries.feed.host.storage.JournalOperation.Type;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
...@@ -30,13 +34,22 @@ public class FeedJournalBridge { ...@@ -30,13 +34,22 @@ public class FeedJournalBridge {
* *
* @param profile {@link Profile} of the user we are rendering the Feed for. * @param profile {@link Profile} of the user we are rendering the Feed for.
*/ */
public void init(Profile profile) {} public void init(Profile profile) {
mNativeFeedJournalBridge = nativeInit(profile);
}
/** Cleans up native half of this bridge. */ /** Cleans up native half of this bridge. */
public void destroy() {} public void destroy() {
assert mNativeFeedJournalBridge != 0;
nativeDestroy(mNativeFeedJournalBridge);
mNativeFeedJournalBridge = 0;
}
/** Loads the journal and asynchronously returns the contents. */ /** Loads the journal and asynchronously returns the contents. */
public void loadJournal(String journalName, Callback<List<String>> callback) {} public void loadJournal(String journalName, Callback<List<String>> callback) {
assert mNativeFeedJournalBridge != 0;
nativeLoadJournal(mNativeFeedJournalBridge, journalName, callback);
}
/** /**
* Commits the operations in {@link JournalMutation} in order and asynchronously reports the * Commits the operations in {@link JournalMutation} in order and asynchronously reports the
...@@ -44,14 +57,69 @@ public class FeedJournalBridge { ...@@ -44,14 +57,69 @@ public class FeedJournalBridge {
* success result. If any operation fails, {@code callback} is called with a failure result and * success result. If any operation fails, {@code callback} is called with a failure result and
* the remaining operations are not processed. * the remaining operations are not processed.
*/ */
public void commitJournalMutation(JournalMutation mutation, Callback<Boolean> callback) {} public void commitJournalMutation(JournalMutation mutation, Callback<Boolean> callback) {
assert mNativeFeedJournalBridge != 0;
nativeCreateJournalMutation(mNativeFeedJournalBridge, mutation.getJournalName());
for (JournalOperation operation : mutation.getOperations()) {
switch (operation.getType()) {
case Type.APPEND:
Append append = (Append) operation;
nativeAddAppendOperation(
mNativeFeedJournalBridge, new String(append.getValue()));
break;
case Type.COPY:
Copy copy = (Copy) operation;
nativeAddCopyOperation(mNativeFeedJournalBridge, copy.getToJournalName());
break;
case Type.DELETE:
nativeAddDeleteOperation(mNativeFeedJournalBridge);
break;
default:
// Operation type is not supported, therefore failing immediately.
assert false : "Unsupported type of operation.";
nativeDeleteJournalMutation(mNativeFeedJournalBridge);
callback.onResult(false);
return;
}
}
nativeCommitJournalMutation(mNativeFeedJournalBridge, callback);
}
/** Determines whether a journal exists and asynchronously responds. */ /** Determines whether a journal exists and asynchronously responds. */
public void doesJournalExist(String journalName, Callback<Boolean> callback) {} public void doesJournalExist(String journalName, Callback<Boolean> callback) {
assert mNativeFeedJournalBridge != 0;
nativeDoesJournalExist(mNativeFeedJournalBridge, journalName, callback);
}
/** Asynchronously retrieve a list of all current journals' name. */ /** Asynchronously retrieve a list of all current journals' name. */
public void loadAllJournalKeys(Callback<List<String>> callback) {} public void loadAllJournalKeys(Callback<List<String>> callback) {
assert mNativeFeedJournalBridge != 0;
nativeLoadAllJournalKeys(mNativeFeedJournalBridge, callback);
}
/** Delete all journals. Reports success or failure. */ /** Delete all journals. Reports success or failure. */
public void deleteAllJournals(Callback<Boolean> callback) {} public void deleteAllJournals(Callback<Boolean> callback) {
assert mNativeFeedJournalBridge != 0;
nativeDeleteAllJournals(mNativeFeedJournalBridge, callback);
}
private native long nativeInit(Profile profile);
private native void nativeDestroy(long nativeFeedJournalBridge);
private native void nativeLoadJournal(
long nativeFeedJournalBridge, String journalName, Callback<List<String>> callback);
private native void nativeCommitJournalMutation(
long nativeFeedJournalBridge, Callback<Boolean> callback);
private native void nativeCreateJournalMutation(
long nativeFeedJournalBridge, String journalName);
private native void nativeDeleteJournalMutation(long nativeFeedJournalBridge);
private native void nativeAddAppendOperation(long nativeFeedJournalBridge, String value);
private native void nativeAddCopyOperation(long nativeFeedJournalBridge, String toJournalName);
private native void nativeAddDeleteOperation(long nativeFeedJournalBridge);
private native void nativeDoesJournalExist(
long nativeFeedJournalBridge, String journalName, Callback<Boolean> callback);
private native void nativeLoadAllJournalKeys(
long nativeFeedJournalBridge, Callback<List<String>> callback);
private native void nativeDeleteAllJournals(
long nativeFeedJournalBridge, Callback<Boolean> callback);
} }
...@@ -4404,6 +4404,8 @@ jumbo_split_static_library("browser") { ...@@ -4404,6 +4404,8 @@ jumbo_split_static_library("browser") {
"android/feed/feed_host_service_factory.h", "android/feed/feed_host_service_factory.h",
"android/feed/feed_image_loader_bridge.cc", "android/feed/feed_image_loader_bridge.cc",
"android/feed/feed_image_loader_bridge.h", "android/feed/feed_image_loader_bridge.h",
"android/feed/feed_journal_bridge.cc",
"android/feed/feed_journal_bridge.h",
"android/feed/feed_network_bridge.cc", "android/feed/feed_network_bridge.cc",
"android/feed/feed_network_bridge.h", "android/feed/feed_network_bridge.h",
"android/feed/feed_scheduler_bridge.cc", "android/feed/feed_scheduler_bridge.cc",
...@@ -4677,6 +4679,7 @@ if (is_android) { ...@@ -4677,6 +4679,7 @@ if (is_android) {
sources += [ sources += [
"../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedContentBridge.java", "../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedContentBridge.java",
"../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedImageLoaderBridge.java", "../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedImageLoaderBridge.java",
"../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/FeedNetworkBridge.java",
"../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedSchedulerBridge.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", "../android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedStorageBridge.java",
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/feed/core/feed_content_database.h" #include "components/feed/core/feed_content_database.h"
#include "components/feed/core/feed_host_service.h" #include "components/feed/core/feed_host_service.h"
#include "components/feed/core/feed_image_manager.h" #include "components/feed/core/feed_image_manager.h"
#include "components/feed/core/feed_journal_database.h"
#include "components/feed/core/feed_networking_host.h" #include "components/feed/core/feed_networking_host.h"
#include "components/feed/core/feed_scheduler_host.h" #include "components/feed/core/feed_scheduler_host.h"
#include "components/feed/core/feed_storage_database.h" #include "components/feed/core/feed_storage_database.h"
...@@ -93,10 +94,12 @@ KeyedService* FeedHostServiceFactory::BuildServiceInstanceFor( ...@@ -93,10 +94,12 @@ KeyedService* FeedHostServiceFactory::BuildServiceInstanceFor(
auto content_database = std::make_unique<FeedContentDatabase>(feed_dir); auto content_database = std::make_unique<FeedContentDatabase>(feed_dir);
auto journal_database = std::make_unique<FeedJournalDatabase>(feed_dir);
return new FeedHostService( return new FeedHostService(
std::move(image_manager), std::move(networking_host), std::move(image_manager), std::move(networking_host),
std::move(scheduler_host), std::move(storage_database), std::move(scheduler_host), std::move(storage_database),
std::move(content_database)); std::move(content_database), std::move(journal_database));
} }
content::BrowserContext* FeedHostServiceFactory::GetBrowserContextToUse( 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_journal_bridge.h"
#include <jni.h>
#include <list>
#include <memory>
#include <utility>
#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_journal_database.h"
#include "jni/FeedJournalBridge_jni.h"
namespace feed {
using base::android::JavaRef;
using base::android::JavaParamRef;
static jlong JNI_FeedJournalBridge_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);
FeedJournalDatabase* feed_journal_database =
host_service->GetJournalDatabase();
DCHECK(feed_journal_database);
FeedJournalBridge* native_journal_bridge =
new FeedJournalBridge(feed_journal_database);
return reinterpret_cast<intptr_t>(native_journal_bridge);
}
FeedJournalBridge::FeedJournalBridge(FeedJournalDatabase* feed_journal_database)
: feed_journal_database_(feed_journal_database), weak_ptr_factory_(this) {
DCHECK(feed_journal_database_);
}
FeedJournalBridge::~FeedJournalBridge() = default;
void FeedJournalBridge::Destroy(JNIEnv* env, const JavaRef<jobject>& j_this) {
delete this;
}
void FeedJournalBridge::LoadJournal(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_journal_name,
const base::android::JavaRef<jobject>& j_callback) {}
void FeedJournalBridge::CommitJournalMutation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback) {}
void FeedJournalBridge::DoesJournalExist(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_journal_name,
const base::android::JavaRef<jobject>& j_callback) {}
void FeedJournalBridge::LoadAllJournalKeys(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback) {}
void FeedJournalBridge::DeleteAllJournals(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback) {}
void FeedJournalBridge::CreateJournalMutation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_journal_name) {}
void FeedJournalBridge::DeleteJournalMutation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this) {}
void FeedJournalBridge::AddAppendOperation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_value) {}
void FeedJournalBridge::AddCopyOperation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_to_journal_name) {}
void FeedJournalBridge::AddDeleteOperation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this) {}
} // 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_JOURNAL_BRIDGE_H_
#define CHROME_BROWSER_ANDROID_FEED_FEED_JOURNAL_BRIDGE_H_
#include "base/android/scoped_java_ref.h"
#include "base/memory/weak_ptr.h"
namespace feed {
class FeedJournalDatabase;
// Native counterpart of FeedJournalBridge.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 FeedJournalBridge {
public:
explicit FeedJournalBridge(FeedJournalDatabase* feed_Storage_database);
~FeedJournalBridge();
void Destroy(JNIEnv* j_env, const base::android::JavaRef<jobject>& j_this);
void LoadJournal(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_journal_name,
const base::android::JavaRef<jobject>& j_callback);
void CommitJournalMutation(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback);
void DoesJournalExist(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_journal_name,
const base::android::JavaRef<jobject>& j_callback);
void LoadAllJournalKeys(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback);
void DeleteAllJournals(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jobject>& j_callback);
void CreateJournalMutation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_journal_name);
void DeleteJournalMutation(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this);
void AddAppendOperation(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_value);
void AddCopyOperation(
JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this,
const base::android::JavaRef<jstring>& j_to_journal_name);
void AddDeleteOperation(JNIEnv* j_env,
const base::android::JavaRef<jobject>& j_this);
private:
FeedJournalDatabase* feed_journal_database_;
base::WeakPtrFactory<FeedJournalBridge> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FeedJournalBridge);
};
} // namespace feed
#endif // CHROME_BROWSER_ANDROID_FEED_FEED_JOURNAL_BRIDGE_H_
...@@ -20,6 +20,8 @@ source_set("feed_core") { ...@@ -20,6 +20,8 @@ source_set("feed_core") {
"feed_image_database.h", "feed_image_database.h",
"feed_image_manager.cc", "feed_image_manager.cc",
"feed_image_manager.h", "feed_image_manager.h",
"feed_journal_database.cc",
"feed_journal_database.h",
"feed_journal_mutation.cc", "feed_journal_mutation.cc",
"feed_journal_mutation.h", "feed_journal_mutation.h",
"feed_journal_operation.cc", "feed_journal_operation.cc",
......
...@@ -13,12 +13,14 @@ FeedHostService::FeedHostService( ...@@ -13,12 +13,14 @@ FeedHostService::FeedHostService(
std::unique_ptr<FeedNetworkingHost> networking_host, std::unique_ptr<FeedNetworkingHost> networking_host,
std::unique_ptr<FeedSchedulerHost> scheduler_host, std::unique_ptr<FeedSchedulerHost> scheduler_host,
std::unique_ptr<FeedStorageDatabase> storage_database, std::unique_ptr<FeedStorageDatabase> storage_database,
std::unique_ptr<FeedContentDatabase> content_database) std::unique_ptr<FeedContentDatabase> content_database,
std::unique_ptr<FeedJournalDatabase> journal_database)
: image_manager_(std::move(image_manager)), : image_manager_(std::move(image_manager)),
networking_host_(std::move(networking_host)), networking_host_(std::move(networking_host)),
scheduler_host_(std::move(scheduler_host)), scheduler_host_(std::move(scheduler_host)),
storage_database_(std::move(storage_database)), storage_database_(std::move(storage_database)),
content_database_(std::move(content_database)) {} content_database_(std::move(content_database)),
journal_database_(std::move(journal_database)) {}
FeedHostService::~FeedHostService() = default; FeedHostService::~FeedHostService() = default;
...@@ -42,4 +44,8 @@ FeedContentDatabase* FeedHostService::GetContentDatabase() { ...@@ -42,4 +44,8 @@ FeedContentDatabase* FeedHostService::GetContentDatabase() {
return content_database_.get(); return content_database_.get();
} }
FeedJournalDatabase* FeedHostService::GetJournalDatabase() {
return journal_database_.get();
}
} // namespace feed } // namespace feed
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/feed/core/feed_content_database.h" #include "components/feed/core/feed_content_database.h"
#include "components/feed/core/feed_image_manager.h" #include "components/feed/core/feed_image_manager.h"
#include "components/feed/core/feed_journal_database.h"
#include "components/feed/core/feed_networking_host.h" #include "components/feed/core/feed_networking_host.h"
#include "components/feed/core/feed_scheduler_host.h" #include "components/feed/core/feed_scheduler_host.h"
#include "components/feed/core/feed_storage_database.h" #include "components/feed/core/feed_storage_database.h"
...@@ -28,7 +29,8 @@ class FeedHostService : public KeyedService { ...@@ -28,7 +29,8 @@ class FeedHostService : public KeyedService {
std::unique_ptr<FeedNetworkingHost> networking_host, std::unique_ptr<FeedNetworkingHost> networking_host,
std::unique_ptr<FeedSchedulerHost> scheduler_host, std::unique_ptr<FeedSchedulerHost> scheduler_host,
std::unique_ptr<FeedStorageDatabase> storage_database, std::unique_ptr<FeedStorageDatabase> storage_database,
std::unique_ptr<FeedContentDatabase> content_database); std::unique_ptr<FeedContentDatabase> content_database,
std::unique_ptr<FeedJournalDatabase> journal_database);
~FeedHostService() override; ~FeedHostService() override;
FeedImageManager* GetImageManager(); FeedImageManager* GetImageManager();
...@@ -36,6 +38,7 @@ class FeedHostService : public KeyedService { ...@@ -36,6 +38,7 @@ class FeedHostService : public KeyedService {
FeedSchedulerHost* GetSchedulerHost(); FeedSchedulerHost* GetSchedulerHost();
FeedStorageDatabase* GetStorageDatabase(); FeedStorageDatabase* GetStorageDatabase();
FeedContentDatabase* GetContentDatabase(); FeedContentDatabase* GetContentDatabase();
FeedJournalDatabase* GetJournalDatabase();
private: private:
std::unique_ptr<FeedImageManager> image_manager_; std::unique_ptr<FeedImageManager> image_manager_;
...@@ -43,6 +46,7 @@ class FeedHostService : public KeyedService { ...@@ -43,6 +46,7 @@ class FeedHostService : public KeyedService {
std::unique_ptr<FeedSchedulerHost> scheduler_host_; std::unique_ptr<FeedSchedulerHost> scheduler_host_;
std::unique_ptr<FeedStorageDatabase> storage_database_; std::unique_ptr<FeedStorageDatabase> storage_database_;
std::unique_ptr<FeedContentDatabase> content_database_; std::unique_ptr<FeedContentDatabase> content_database_;
std::unique_ptr<FeedJournalDatabase> journal_database_;
DISALLOW_COPY_AND_ASSIGN(FeedHostService); DISALLOW_COPY_AND_ASSIGN(FeedHostService);
}; };
......
// 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 "components/feed/core/feed_journal_database.h"
namespace feed {
FeedJournalDatabase::FeedJournalDatabase(
const base::FilePath& database_folder) {}
FeedJournalDatabase::~FeedJournalDatabase() = default;
} // 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 COMPONENTS_FEED_CORE_FEED_JOURNAL_DATABASE_H_
#define COMPONENTS_FEED_CORE_FEED_JOURNAL_DATABASE_H_
#include "base/files/file_path.h"
#include "base/macros.h"
namespace feed {
// FeedJournalDatabase is leveldb backend store for Feed's journal storage data.
// Feed's journal data are key-value pairs.
class FeedJournalDatabase {
public:
// Initializes the database with |database_folder|.
explicit FeedJournalDatabase(const base::FilePath& database_folder);
~FeedJournalDatabase();
DISALLOW_COPY_AND_ASSIGN(FeedJournalDatabase);
};
} // namespace feed
#endif // COMPONENTS_FEED_CORE_FEED_JOURNAL_DATABASE_H_
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