OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.search_engines; | 5 package org.chromium.chrome.browser.search_engines; |
6 | 6 |
7 import android.support.annotation.IntDef; | 7 import android.support.annotation.IntDef; |
8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
9 | 9 |
10 import org.chromium.base.ObserverList; | 10 import org.chromium.base.ObserverList; |
11 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
12 import org.chromium.base.VisibleForTesting; | 12 import org.chromium.base.VisibleForTesting; |
13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
14 | 14 |
15 import java.lang.annotation.Retention; | 15 import java.lang.annotation.Retention; |
16 import java.lang.annotation.RetentionPolicy; | 16 import java.lang.annotation.RetentionPolicy; |
17 import java.util.ArrayList; | 17 import java.util.ArrayList; |
18 import java.util.List; | 18 import java.util.List; |
19 import java.util.Locale; | |
19 | 20 |
20 /** | 21 /** |
21 * Android wrapper of the TemplateUrlService which provides access from the Java | 22 * Android wrapper of the TemplateUrlService which provides access from the Java |
22 * layer. | 23 * layer. |
23 * | 24 * |
24 * Only usable from the UI thread as it's primary purpose is for supporting the Android | 25 * Only usable from the UI thread as it's primary purpose is for supporting the Android |
25 * preferences UI. | 26 * preferences UI. |
26 * | 27 * |
27 * See components/search_engines/template_url_service.h for more details. | 28 * See components/search_engines/template_url_service.h for more details. |
28 */ | 29 */ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 */ | 62 */ |
62 public static class TemplateUrl { | 63 public static class TemplateUrl { |
63 private final int mIndex; | 64 private final int mIndex; |
64 private final String mShortName; | 65 private final String mShortName; |
65 private final boolean mIsPrepopulated; | 66 private final boolean mIsPrepopulated; |
66 private final String mKeyword; | 67 private final String mKeyword; |
67 @TemplateUrlType private int mTemplateUrlType; | 68 @TemplateUrlType private int mTemplateUrlType; |
68 | 69 |
69 @CalledByNative("TemplateUrl") | 70 @CalledByNative("TemplateUrl") |
70 public static TemplateUrl create( | 71 public static TemplateUrl create( |
71 int id, String shortName, boolean isPrepopulated, String keyword ) { | 72 int index, String shortName, boolean isPrepopulated, String keyw ord) { |
72 return new TemplateUrl(id, shortName, isPrepopulated, keyword); | 73 return new TemplateUrl(index, shortName, isPrepopulated, keyword); |
73 } | 74 } |
74 | 75 |
75 public TemplateUrl( | 76 public TemplateUrl( |
76 int index, String shortName, boolean isPrepopulated, String keyw ord) { | 77 int index, String shortName, boolean isPrepopulated, String keyw ord) { |
77 mIndex = index; | 78 mIndex = index; |
78 mShortName = shortName; | 79 mShortName = shortName; |
79 mIsPrepopulated = isPrepopulated; | 80 mIsPrepopulated = isPrepopulated; |
80 mKeyword = keyword; | 81 mKeyword = keyword; |
81 } | 82 } |
82 | 83 |
(...skipping 29 matching lines...) Expand all Loading... | |
112 result = prime * result + mIndex; | 113 result = prime * result + mIndex; |
113 result = prime * result + ((mShortName == null) ? 0 : mShortName.has hCode()); | 114 result = prime * result + ((mShortName == null) ? 0 : mShortName.has hCode()); |
114 return result; | 115 return result; |
115 } | 116 } |
116 | 117 |
117 @Override | 118 @Override |
118 public boolean equals(Object other) { | 119 public boolean equals(Object other) { |
119 if (!(other instanceof TemplateUrl)) return false; | 120 if (!(other instanceof TemplateUrl)) return false; |
120 TemplateUrl otherTemplateUrl = (TemplateUrl) other; | 121 TemplateUrl otherTemplateUrl = (TemplateUrl) other; |
121 return mIndex == otherTemplateUrl.mIndex | 122 return mIndex == otherTemplateUrl.mIndex |
123 && mIsPrepopulated == otherTemplateUrl.mIsPrepopulated | |
124 && mTemplateUrlType == otherTemplateUrl.mTemplateUrlType | |
Ted C
2017/01/31 00:54:34
had to remove mTemplateUrlType because that change
| |
125 && TextUtils.equals(mKeyword, otherTemplateUrl.mKeyword) | |
122 && TextUtils.equals(mShortName, otherTemplateUrl.mShortName) ; | 126 && TextUtils.equals(mShortName, otherTemplateUrl.mShortName) ; |
123 } | 127 } |
128 | |
129 @Override | |
130 public String toString() { | |
131 return String.format(Locale.US, | |
132 "TemplateURL -- keyword: %s, short name: %s, index: %d, " | |
133 + "type: %d, prepopulated: %b", | |
134 mKeyword, mShortName, mIndex, mTemplateUrlType, mIsPrepopula ted); | |
135 } | |
124 } | 136 } |
125 | 137 |
126 private static TemplateUrlService sService; | 138 private static TemplateUrlService sService; |
127 | 139 |
128 public static TemplateUrlService getInstance() { | 140 public static TemplateUrlService getInstance() { |
129 ThreadUtils.assertOnUiThread(); | 141 ThreadUtils.assertOnUiThread(); |
130 if (sService == null) { | 142 if (sService == null) { |
131 sService = new TemplateUrlService(); | 143 sService = new TemplateUrlService(); |
132 } | 144 } |
133 return sService; | 145 return sService; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 String query, String currentUrl); | 406 String query, String currentUrl); |
395 private native String nativeGetUrlForContextualSearchQuery(long nativeTempla teUrlServiceAndroid, | 407 private native String nativeGetUrlForContextualSearchQuery(long nativeTempla teUrlServiceAndroid, |
396 String query, String alternateTerm, boolean shouldPrefetch, String p rotocolVersion); | 408 String query, String alternateTerm, boolean shouldPrefetch, String p rotocolVersion); |
397 private native String nativeGetSearchEngineUrlFromTemplateUrl( | 409 private native String nativeGetSearchEngineUrlFromTemplateUrl( |
398 long nativeTemplateUrlServiceAndroid, String keyword); | 410 long nativeTemplateUrlServiceAndroid, String keyword); |
399 private native String nativeAddSearchEngineForTesting( | 411 private native String nativeAddSearchEngineForTesting( |
400 long nativeTemplateUrlServiceAndroid, String keyword, int offset); | 412 long nativeTemplateUrlServiceAndroid, String keyword, int offset); |
401 private native String nativeUpdateLastVisitedForTesting( | 413 private native String nativeUpdateLastVisitedForTesting( |
402 long nativeTemplateUrlServiceAndroid, String keyword); | 414 long nativeTemplateUrlServiceAndroid, String keyword); |
403 } | 415 } |
OLD | NEW |