Commit 519b6308 authored by Mehran Mahmoudi's avatar Mehran Mahmoudi Committed by Commit Bot

[Paint Preview] Remove java PaintPreviewBaseService Class

This CL:
1. Removes Android-specific code from paint_preview_base_service.(cc|h).
2. Replaces the PaintPreviewBaseService Java class with the
   NativePaintPreviewServiceProvider interface. This enables each
   implementer of paint_preview_base_service.cc to independently handle
   its JNI communications.

Bug: 1058405
Change-Id: Id629aa95560cb4c0f202079c1437a16c67798d0d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090592Reviewed-by: default avatarCalder Kitagawa <ckitagawa@chromium.org>
Commit-Queue: Mehran Mahmoudi <mahmoudi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747475}
parent 5d4b4102
......@@ -46,10 +46,6 @@ source_set("browser") {
"//url",
]
if (is_android) {
deps += [ ":jni_headers" ]
}
public_deps = [
"//components/paint_preview/common",
"//components/paint_preview/common/mojom",
......@@ -59,12 +55,6 @@ source_set("browser") {
]
}
if (is_android) {
generate_jni("jni_headers") {
sources = [ "android/java/src/org/chromium/components/paintpreview/browser/PaintPreviewBaseService.java" ]
}
}
source_set("test_support") {
testonly = true
sources = [
......
......@@ -14,7 +14,7 @@ android_library("java") {
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
sources = [
"java/src/org/chromium/components/paintpreview/browser/PaintPreviewBaseService.java",
"java/src/org/chromium/components/paintpreview/browser/NativePaintPreviewServiceProvider.java",
"java/src/org/chromium/components/paintpreview/browser/PaintPreviewUtils.java",
]
......
// Copyright 2019 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.components.paintpreview.browser;
/**
* The Java-side implementations of paint_preview_base_service.cc should implement this interface.
* Provides a method for accessing the native PaintPreviewBaseService.
*/
public interface NativePaintPreviewServiceProvider { long getNativeService(); }
\ No newline at end of file
// Copyright 2019 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.components.paintpreview.browser;
import org.chromium.base.annotations.CalledByNative;
/**
* The Java-side implementation of paint_preview_base_service.cc. This class is owned and managed by
* its C++ counterpart.
*/
public class PaintPreviewBaseService {
private long mNativePaintPreviewBaseService;
@CalledByNative
public PaintPreviewBaseService(long nativePaintPreviewBaseService) {
mNativePaintPreviewBaseService = nativePaintPreviewBaseService;
}
@CalledByNative
public void onDestroy() {
mNativePaintPreviewBaseService = 0;
}
public long getNativePaintPreviewBaseService() {
return mNativePaintPreviewBaseService;
}
}
\ No newline at end of file
......@@ -24,12 +24,6 @@
#include "content/public/browser/web_contents.h"
#include "ui/gfx/geometry/rect.h"
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "components/paint_preview/browser/jni_headers/PaintPreviewBaseService_jni.h"
#endif // defined(OS_ANDROID)
namespace paint_preview {
namespace {
......@@ -46,22 +40,9 @@ PaintPreviewBaseService::PaintPreviewBaseService(
: policy_(std::move(policy)),
file_manager_(
path.AppendASCII(kPaintPreviewDir).AppendASCII(ascii_feature_name)),
is_off_the_record_(is_off_the_record) {
#if defined(OS_ANDROID)
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobject> java_ref =
Java_PaintPreviewBaseService_Constructor(
env, reinterpret_cast<intptr_t>(this));
java_ref_.Reset(java_ref);
#endif // defined(OS_ANDROID)
}
is_off_the_record_(is_off_the_record) {}
PaintPreviewBaseService::~PaintPreviewBaseService() {
#if defined(OS_ANDROID)
JNIEnv* env = base::android::AttachCurrentThread();
Java_PaintPreviewBaseService_onDestroy(env, java_ref_);
#endif // defined(OS_ANDROID)
}
PaintPreviewBaseService::~PaintPreviewBaseService() = default;
void PaintPreviewBaseService::GetCapturedPaintPreviewProto(
const DirectoryKey& key,
......
......@@ -23,10 +23,6 @@
#include "components/paint_preview/common/proto/paint_preview.pb.h"
#include "components/paint_preview/public/paint_preview_compositor_service.h"
#include "content/public/browser/web_contents.h"
#if defined(OS_ANDROID)
#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#endif // defined(OS_ANDROID)
namespace paint_preview {
......@@ -119,12 +115,6 @@ class PaintPreviewBaseService : public KeyedService {
std::unique_ptr<PaintPreviewCompositorService> StartCompositorService(
base::OnceClosure disconnect_handler);
#if defined(OS_ANDROID)
base::android::ScopedJavaGlobalRef<jobject> GetJavaObject() {
return java_ref_;
}
#endif // defined(OS_ANDROID)
private:
void OnCaptured(base::TimeTicks start_time,
OnCapturedCallback callback,
......@@ -136,11 +126,6 @@ class PaintPreviewBaseService : public KeyedService {
FileManager file_manager_;
bool is_off_the_record_;
#if defined(OS_ANDROID)
// Points to the Java reference.
base::android::ScopedJavaGlobalRef<jobject> java_ref_;
#endif // defined(OS_ANDROID)
base::WeakPtrFactory<PaintPreviewBaseService> weak_ptr_factory_{this};
PaintPreviewBaseService(const PaintPreviewBaseService&) = delete;
......
......@@ -13,7 +13,7 @@ import org.chromium.base.UnguessableToken;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.components.paintpreview.browser.PaintPreviewBaseService;
import org.chromium.components.paintpreview.browser.NativePaintPreviewServiceProvider;
import javax.annotation.Nonnull;
......@@ -32,12 +32,12 @@ class PlayerCompositorDelegateImpl implements PlayerCompositorDelegate {
private CompositorListener mCompositorListener;
private long mNativePlayerCompositorDelegate;
PlayerCompositorDelegateImpl(PaintPreviewBaseService service, String directoryKey,
PlayerCompositorDelegateImpl(NativePaintPreviewServiceProvider service, String directoryKey,
@Nonnull CompositorListener compositorListener) {
mCompositorListener = compositorListener;
if (service != null && service.getNativePaintPreviewBaseService() != 0) {
if (service != null && service.getNativeService() != 0) {
mNativePlayerCompositorDelegate = PlayerCompositorDelegateImplJni.get().initialize(
this, service.getNativePaintPreviewBaseService(), directoryKey);
this, service.getNativeService(), directoryKey);
}
// TODO(crbug.com/1021590): Handle initialization errors when
// mNativePlayerCompositorDelegate == 0.
......
......@@ -13,7 +13,7 @@ import android.widget.FrameLayout;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.UnguessableToken;
import org.chromium.components.paintpreview.browser.PaintPreviewBaseService;
import org.chromium.components.paintpreview.browser.NativePaintPreviewServiceProvider;
import org.chromium.components.paintpreview.player.frame.PlayerFrameCoordinator;
import java.util.HashMap;
......@@ -29,7 +29,8 @@ public class PlayerManager {
private PlayerFrameCoordinator mRootFrameCoordinator;
private FrameLayout mHostView;
public PlayerManager(Context context, PaintPreviewBaseService service, String directoryKey) {
public PlayerManager(
Context context, NativePaintPreviewServiceProvider service, String directoryKey) {
mContext = context;
mDelegate =
new PlayerCompositorDelegateImpl(service, directoryKey, this::onCompositorReady);
......
......@@ -6,15 +6,22 @@ package org.chromium.components.paintpreview.player;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.components.paintpreview.browser.PaintPreviewBaseService;
import org.chromium.components.paintpreview.browser.NativePaintPreviewServiceProvider;
/**
* A simple implementation of {@link PaintPreviewBaseService} used in tests.
* A simple implementation of {@link NativePaintPreviewServiceProvider} used in tests.
*/
@JNINamespace("paint_preview")
public class TestImplementerService extends PaintPreviewBaseService {
public class TestImplementerService implements NativePaintPreviewServiceProvider {
private long mNativeTestImplementerService;
public TestImplementerService(String storagePath) {
super(TestImplementerServiceJni.get().getInstance(storagePath));
mNativeTestImplementerService = TestImplementerServiceJni.get().getInstance(storagePath);
}
@Override
public long getNativeService() {
return mNativeTestImplementerService;
}
@NativeMethods
......
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