Commit bafaf234 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Query Tiles : Added native factory and hooked up Java

This CL creates the TileService interface, factory in native and connects
them to the Java layer.

Bug: 1059409
Change-Id: I964eb6d662a86196f6dc764e7de33703765de7e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2097304
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749763}
parent ece38372
...@@ -10,7 +10,6 @@ import android.view.ViewGroup.LayoutParams; ...@@ -10,7 +10,6 @@ import android.view.ViewGroup.LayoutParams;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.query_tiles.list.QueryTileCoordinator;
/** /**
* Represents the query tiles section on the new tab page. Abstracts away the general tasks related * Represents the query tiles section on the new tab page. Abstracts away the general tasks related
...@@ -28,7 +27,7 @@ public class QueryTileSection { ...@@ -28,7 +27,7 @@ public class QueryTileSection {
if (!ChromeFeatureList.isEnabled(ChromeFeatureList.QUERY_TILES)) return; if (!ChromeFeatureList.isEnabled(ChromeFeatureList.QUERY_TILES)) return;
mTileProvider = TileProviderFactory.getForProfile(profile); mTileProvider = TileProviderFactory.getForProfile(profile);
mQueryTileCoordinator = new QueryTileCoordinator( mQueryTileCoordinator = QueryTileCoordinatorFactory.create(
mQueryTileSectionView.getContext(), mTileProvider, this::onQueryTilesChanged); mQueryTileSectionView.getContext(), mTileProvider, this::onQueryTilesChanged);
mQueryTileSectionView.addView(mQueryTileCoordinator.getView(), mQueryTileSectionView.addView(mQueryTileCoordinator.getView(),
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
......
...@@ -14,15 +14,24 @@ if (is_android) { ...@@ -14,15 +14,24 @@ if (is_android) {
} }
group("query_tiles") { group("query_tiles") {
public_deps = [ ":public" ] public_deps = [
":factory",
":public",
]
deps = [ "internal" ] deps = [ "internal" ]
} }
source_set("public") { source_set("public") {
sources = [] sources = [ "tile_service.h" ]
deps = [] deps = []
public_deps = [
"//base",
"//components/keyed_service/core",
]
if (is_android) { if (is_android) {
sources += [ sources += [
"android/tile_provider_bridge.cc", "android/tile_provider_bridge.cc",
...@@ -33,13 +42,27 @@ source_set("public") { ...@@ -33,13 +42,27 @@ source_set("public") {
} }
} }
source_set("factory") {
sources = [
"tile_service_factory.cc",
"tile_service_factory.h",
]
deps = [
":public",
"internal:internal",
]
}
if (is_android) { if (is_android) {
android_library("public_java") { android_library("public_java") {
sources = [ sources = [
"android/java/src/org/chromium/chrome/browser/query_tiles/QueryTileCoordinator.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/QueryTileCoordinatorFactory.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/Tile.java", "android/java/src/org/chromium/chrome/browser/query_tiles/Tile.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/TileProvider.java", "android/java/src/org/chromium/chrome/browser/query_tiles/TileProvider.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/bridges/TileProviderBridge.java", "android/java/src/org/chromium/chrome/browser/query_tiles/bridges/TileProviderBridge.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/list/QueryTileCoordinator.java", "android/java/src/org/chromium/chrome/browser/query_tiles/list/QueryTileCoordinatorImpl.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/list/TileListModel.java", "android/java/src/org/chromium/chrome/browser/query_tiles/list/TileListModel.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/list/TileListProperties.java", "android/java/src/org/chromium/chrome/browser/query_tiles/list/TileListProperties.java",
"android/java/src/org/chromium/chrome/browser/query_tiles/list/TileListPropertyViewBinder.java", "android/java/src/org/chromium/chrome/browser/query_tiles/list/TileListPropertyViewBinder.java",
......
// 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.
package org.chromium.chrome.browser.query_tiles;
import android.view.View;
/**
* The top level coordinator for the query tiles UI.
*/
public interface QueryTileCoordinator {
/** @return A {@link View} representing this coordinator. */
View getView();
}
// 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.
package org.chromium.chrome.browser.query_tiles;
import android.content.Context;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.query_tiles.list.QueryTileCoordinatorImpl;
/**
* Factory to create {@link QueryTileCoordinator} instances.
*/
public class QueryTileCoordinatorFactory {
/**
* Creates a {@link QueryTileCoordinator}.
* @param context The context associated with the current activity.
* @param tileProvider The {@link TileProvider} to provide tiles.
* @param visibilityCallback A callback to show/hide the query tile section
* @return A {@link QueryTileCoordinator}.
*/
public static QueryTileCoordinator create(
Context context, TileProvider tileProvider, Callback<Boolean> visibilityCallback) {
return new QueryTileCoordinatorImpl(context, tileProvider, visibilityCallback);
}
}
...@@ -9,19 +9,21 @@ import android.graphics.Bitmap; ...@@ -9,19 +9,21 @@ import android.graphics.Bitmap;
import android.view.View; import android.view.View;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.chrome.browser.query_tiles.QueryTileCoordinator;
import org.chromium.chrome.browser.query_tiles.Tile; import org.chromium.chrome.browser.query_tiles.Tile;
import org.chromium.chrome.browser.query_tiles.TileProvider; import org.chromium.chrome.browser.query_tiles.TileProvider;
/** /**
* The top level coordinator for the query tiles UI. * The top level coordinator for the query tiles UI.
*/ */
public class QueryTileCoordinator { public class QueryTileCoordinatorImpl implements QueryTileCoordinator {
private final TileListModel mModel; private final TileListModel mModel;
private final TileListView mView; private final TileListView mView;
private final TileProvider mTileProvider; private final TileProvider mTileProvider;
private final Callback<Boolean> mVisibilityCallback; private final Callback<Boolean> mVisibilityCallback;
public QueryTileCoordinator( /** Constructor. */
public QueryTileCoordinatorImpl(
Context context, TileProvider tileProvider, Callback<Boolean> visibilityCallback) { Context context, TileProvider tileProvider, Callback<Boolean> visibilityCallback) {
mTileProvider = tileProvider; mTileProvider = tileProvider;
mVisibilityCallback = visibilityCallback; mVisibilityCallback = visibilityCallback;
...@@ -33,7 +35,7 @@ public class QueryTileCoordinator { ...@@ -33,7 +35,7 @@ public class QueryTileCoordinator {
onQueryTileClicked(null); onQueryTileClicked(null);
} }
/** @return The {@link View} that represents this coordinator. */ @Override
public View getView() { public View getView() {
return mView.getView(); return mView.getView();
} }
......
...@@ -8,7 +8,28 @@ ...@@ -8,7 +8,28 @@
namespace upboarding { namespace upboarding {
TileProviderBridge::TileProviderBridge() { namespace {
const char kTileProviderBridgeKey[] = "tile_provider_bridge";
}
// static
ScopedJavaLocalRef<jobject> TileProviderBridge::GetBridgeForTileService(
TileService* tile_service) {
if (!tile_service->GetUserData(kTileProviderBridgeKey)) {
tile_service->SetUserData(
kTileProviderBridgeKey,
std::make_unique<TileProviderBridge>(tile_service));
}
TileProviderBridge* bridge = static_cast<TileProviderBridge*>(
tile_service->GetUserData(kTileProviderBridgeKey));
return ScopedJavaLocalRef<jobject>(bridge->java_obj_);
}
TileProviderBridge::TileProviderBridge(TileService* tile_service)
: tile_service_(tile_service) {
DCHECK(tile_service_);
JNIEnv* env = base::android::AttachCurrentThread(); JNIEnv* env = base::android::AttachCurrentThread();
java_obj_.Reset( java_obj_.Reset(
env, Java_TileProviderBridge_create(env, reinterpret_cast<int64_t>(this)) env, Java_TileProviderBridge_create(env, reinterpret_cast<int64_t>(this))
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define CHROME_BROWSER_UPBOARDING_QUERY_TILES_ANDROID_TILE_PROVIDER_BRIDGE_H_ #define CHROME_BROWSER_UPBOARDING_QUERY_TILES_ANDROID_TILE_PROVIDER_BRIDGE_H_
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/supports_user_data.h"
#include "chrome/browser/upboarding/query_tiles/tile_service.h"
using base::android::JavaParamRef; using base::android::JavaParamRef;
using base::android::JavaRef; using base::android::JavaRef;
...@@ -15,10 +17,15 @@ using base::android::ScopedJavaLocalRef; ...@@ -15,10 +17,15 @@ using base::android::ScopedJavaLocalRef;
namespace upboarding { namespace upboarding {
// Helper class responsible for bridging the TileProvider between C++ and Java. // Helper class responsible for bridging the TileProvider between C++ and Java.
class TileProviderBridge { class TileProviderBridge : public base::SupportsUserData::Data {
public: public:
TileProviderBridge(); // Returns a Java TileProviderBridge for |tile_service|. There will
~TileProviderBridge(); // be only one bridge per TileProviderBridge.
static ScopedJavaLocalRef<jobject> GetBridgeForTileService(
TileService* tile_service);
explicit TileProviderBridge(TileService* tile_service);
~TileProviderBridge() override;
// Methods called from Java via JNI. // Methods called from Java via JNI.
void GetQueryTiles(JNIEnv* env, void GetQueryTiles(JNIEnv* env,
...@@ -35,6 +42,9 @@ class TileProviderBridge { ...@@ -35,6 +42,9 @@ class TileProviderBridge {
// TileProviderBridge.java. // TileProviderBridge.java.
ScopedJavaGlobalRef<jobject> java_obj_; ScopedJavaGlobalRef<jobject> java_obj_;
// Not owned.
TileService* tile_service_;
DISALLOW_COPY_AND_ASSIGN(TileProviderBridge); DISALLOW_COPY_AND_ASSIGN(TileProviderBridge);
}; };
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h" #include "chrome/browser/profiles/profile_android.h"
#include "chrome/browser/profiles/profile_key.h" #include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/upboarding/query_tiles/android/tile_provider_bridge.h"
#include "chrome/browser/upboarding/query_tiles/tile_service_factory.h"
// Takes a Java Profile and returns a Java TileProvider. // Takes a Java Profile and returns a Java TileProvider.
static base::android::ScopedJavaLocalRef<jobject> static base::android::ScopedJavaLocalRef<jobject>
...@@ -21,7 +23,7 @@ JNI_TileProviderFactory_GetForProfile( ...@@ -21,7 +23,7 @@ JNI_TileProviderFactory_GetForProfile(
if (profile_key == nullptr) if (profile_key == nullptr)
return base::android::ScopedJavaLocalRef<jobject>(); return base::android::ScopedJavaLocalRef<jobject>();
// TODO(shaktisahu): Get TileProviderBridge. upboarding::TileService* tile_service =
upboarding::TileServiceFactory::GetInstance()->GetForKey(profile_key);
return base::android::ScopedJavaLocalRef<jobject>(); return upboarding::TileProviderBridge::GetBridgeForTileService(tile_service);
} }
// 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_TILE_SERVICE_H_
#define CHROME_BROWSER_UPBOARDING_QUERY_TILES_TILE_SERVICE_H_
#include "base/macros.h"
#include "base/supports_user_data.h"
#include "components/keyed_service/core/keyed_service.h"
namespace upboarding {
// The central class on chrome client responsible for fetching, storing,
// managing, and displaying query tiles in chrome.
class TileService : public KeyedService, public base::SupportsUserData {
public:
// TODO(shaktisahu): Add methods.
private:
DISALLOW_COPY_AND_ASSIGN(TileService);
};
} // namespace upboarding
#endif // CHROME_BROWSER_UPBOARDING_QUERY_TILES_TILE_SERVICE_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/tile_service_factory.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
namespace upboarding {
// static
TileServiceFactory* TileServiceFactory::GetInstance() {
return base::Singleton<TileServiceFactory>::get();
}
// static
TileService* TileServiceFactory::GetForKey(SimpleFactoryKey* key) {
return static_cast<TileService*>(
GetInstance()->GetServiceForKey(key, /*create=*/true));
}
TileServiceFactory::TileServiceFactory()
: SimpleKeyedServiceFactory("TileService",
SimpleDependencyManager::GetInstance()) {}
TileServiceFactory::~TileServiceFactory() {}
std::unique_ptr<KeyedService> TileServiceFactory::BuildServiceInstanceFor(
SimpleFactoryKey* key) const {
// TODO(shaktisahu): Create TileService instance.
return nullptr;
}
} // 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_TILE_SERVICE_FACTORY_H_
#define CHROME_BROWSER_UPBOARDING_QUERY_TILES_TILE_SERVICE_FACTORY_H_
#include <memory>
#include "base/macros.h"
#include "chrome/browser/upboarding/query_tiles/tile_service.h"
#include "components/keyed_service/core/simple_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
} // namespace base
namespace upboarding {
class TileService;
// A factory to create one unique TileService.
class TileServiceFactory : public SimpleKeyedServiceFactory {
public:
static TileServiceFactory* GetInstance();
static TileService* GetForKey(SimpleFactoryKey* key);
private:
friend struct base::DefaultSingletonTraits<TileServiceFactory>;
TileServiceFactory();
~TileServiceFactory() override;
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
SimpleFactoryKey* key) const override;
DISALLOW_COPY_AND_ASSIGN(TileServiceFactory);
};
} // namespace upboarding
#endif // CHROME_BROWSER_UPBOARDING_QUERY_TILES_TILE_SERVICE_FACTORY_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