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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.contextualsearch;
6
7 import org.chromium.base.annotations.CalledByNative;
8
9 /**
10 * Provides a context in which to search, and links to the native ContextualSear chContext.
11 * Includes the selection, selection offsets, surrounding page content, etc.
12 */
13 public class ContextualSearchContext {
14 private long mNativePointer;
15
16 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.
17
18 // Whether the context should include brief page content or a larger amount as would be
19 // appropriate when resolving the search term.
20 private boolean mUseBriefPageContent;
21
22 /**
23 * Constructs a context that cannot resolve a search term and has a small am ount of
24 * page content.
25 */
26 ContextualSearchContext(String selection) {
27 mNativePointer = nativeInit();
28 mUseBriefPageContent = true;
29 mSelection = selection;
30 nativeSetUseBriefPageContent(getNativePointer(), true);
31 }
32
33 /**
34 * Constructs a context that can resolve a search term and has a large amoun t of
35 * page content.
36 */
37 ContextualSearchContext(String selection, String homeCountry, boolean maySen dBasePageUrl) {
Theresa 2017/03/08 01:54:38 nit: JavaDocs for parameters
Donn Denman 2017/03/09 17:35:04 Done.
38 mNativePointer = nativeInit();
39 mUseBriefPageContent = false;
40 mSelection = selection;
41 nativeSetUseBriefPageContent(getNativePointer(), false);
42 nativeSetProperties(getNativePointer(), selection, homeCountry, maySendB asePageUrl);
43 }
44
45 /**
46 * This method should be called to clean up storage when an instance of this class is
47 * no longer in use.
48 */
49 void destroy() {
50 assert mNativePointer != 0;
51 nativeDestroy(mNativePointer);
52 mNativePointer = 0;
53 }
54
55 String getSelection() {
56 return mSelection;
57 }
58
59 // ========================================================================= ===================
60 // Native callback support.
61 // ========================================================================= ===================
62
63 @CalledByNative
64 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
65 assert mNativePointer != 0;
66 mNativePointer = 0;
67 }
68
69 @CalledByNative
70 private long getNativePointer() {
71 assert mNativePointer != 0;
72 return mNativePointer;
73 }
74
75 // ========================================================================= ===================
76 // Native methods.
77 // ========================================================================= ===================
78 private native long nativeInit();
79 private native void nativeDestroy(long nativeContextualSearchContext);
80 private native void nativeSetUseBriefPageContent(
81 long nativeContextualSearchContext, boolean useBriefPageContent);
82 private native void nativeSetProperties(long nativeContextualSearchContext, String selection,
83 String homeCountry, boolean maySendBasePageUrl);
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698