Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4264)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java

Issue 2706333002: [TTS] Add a Java Context linked to existing native (Closed)
Patch Set: DCHECK that the context is created on the browser thread. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
new file mode 100644
index 0000000000000000000000000000000000000000..51a5c59dca2f67ea60fdd755a2ca3249e4adaac9
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchContext.java
@@ -0,0 +1,84 @@
+// Copyright 2017 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.contextualsearch;
+
+import org.chromium.base.annotations.CalledByNative;
+
+/**
+ * Provides a context in which to search, and links to the native ContextualSearchContext.
+ * Includes the selection, selection offsets, surrounding page content, etc.
+ */
+public class ContextualSearchContext {
+ private long mNativePointer;
+
+ private final String mSelection;
Theresa 2017/03/08 01:54:38 nit: final variables go first.
Donn Denman 2017/03/09 17:35:04 Done.
+
+ // Whether the context should include brief page content or a larger amount as would be
+ // appropriate when resolving the search term.
+ private boolean mUseBriefPageContent;
+
+ /**
+ * Constructs a context that cannot resolve a search term and has a small amount of
+ * page content.
+ */
+ ContextualSearchContext(String selection) {
+ mNativePointer = nativeInit();
+ mUseBriefPageContent = true;
+ mSelection = selection;
+ nativeSetUseBriefPageContent(getNativePointer(), true);
+ }
+
+ /**
+ * Constructs a context that can resolve a search term and has a large amount of
+ * page content.
+ */
+ ContextualSearchContext(String selection, String homeCountry, boolean maySendBasePageUrl) {
Theresa 2017/03/08 01:54:38 nit: JavaDocs for parameters
Donn Denman 2017/03/09 17:35:04 Done.
+ mNativePointer = nativeInit();
+ mUseBriefPageContent = false;
+ mSelection = selection;
+ nativeSetUseBriefPageContent(getNativePointer(), false);
+ nativeSetProperties(getNativePointer(), selection, homeCountry, maySendBasePageUrl);
+ }
+
+ /**
+ * This method should be called to clean up storage when an instance of this class is
+ * no longer in use.
+ */
+ void destroy() {
+ assert mNativePointer != 0;
+ nativeDestroy(mNativePointer);
+ mNativePointer = 0;
+ }
+
+ String getSelection() {
+ return mSelection;
+ }
+
+ // ============================================================================================
+ // Native callback support.
+ // ============================================================================================
+
+ @CalledByNative
+ private void clearNativePointer() {
Theresa 2017/03/08 01:54:38 When is this called vs destroy()?
Donn Denman 2017/03/09 17:35:04 Added JavaDoc. Destroy is called from the java, b
Theresa 2017/03/09 18:29:44 What I was trying to ask is when is the object des
Donn Denman 2017/03/09 22:00:25 BTW, here's that sample code I was telling you abo
+ assert mNativePointer != 0;
+ mNativePointer = 0;
+ }
+
+ @CalledByNative
+ private long getNativePointer() {
+ assert mNativePointer != 0;
+ return mNativePointer;
+ }
+
+ // ============================================================================================
+ // Native methods.
+ // ============================================================================================
+ private native long nativeInit();
+ private native void nativeDestroy(long nativeContextualSearchContext);
+ private native void nativeSetUseBriefPageContent(
+ long nativeContextualSearchContext, boolean useBriefPageContent);
+ private native void nativeSetProperties(long nativeContextualSearchContext, String selection,
+ String homeCountry, boolean maySendBasePageUrl);
+}

Powered by Google App Engine
This is Rietveld 408576698