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 28 matching lines...) Expand all Loading... |
111 int result = 1; | 112 int result = 1; |
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; |
| 122 // Explicitly excluding mTemplateUrlType as that will change if the
search engine is |
| 123 // set as default. |
121 return mIndex == otherTemplateUrl.mIndex | 124 return mIndex == otherTemplateUrl.mIndex |
| 125 && mIsPrepopulated == otherTemplateUrl.mIsPrepopulated |
| 126 && TextUtils.equals(mKeyword, otherTemplateUrl.mKeyword) |
122 && TextUtils.equals(mShortName, otherTemplateUrl.mShortName)
; | 127 && TextUtils.equals(mShortName, otherTemplateUrl.mShortName)
; |
123 } | 128 } |
| 129 |
| 130 @Override |
| 131 public String toString() { |
| 132 return String.format(Locale.US, |
| 133 "TemplateURL -- keyword: %s, short name: %s, index: %d, " |
| 134 + "type: %d, prepopulated: %b", |
| 135 mKeyword, mShortName, mIndex, mTemplateUrlType, mIsPrepopula
ted); |
| 136 } |
124 } | 137 } |
125 | 138 |
126 private static TemplateUrlService sService; | 139 private static TemplateUrlService sService; |
127 | 140 |
128 public static TemplateUrlService getInstance() { | 141 public static TemplateUrlService getInstance() { |
129 ThreadUtils.assertOnUiThread(); | 142 ThreadUtils.assertOnUiThread(); |
130 if (sService == null) { | 143 if (sService == null) { |
131 sService = new TemplateUrlService(); | 144 sService = new TemplateUrlService(); |
132 } | 145 } |
133 return sService; | 146 return sService; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 String query, String currentUrl); | 407 String query, String currentUrl); |
395 private native String nativeGetUrlForContextualSearchQuery(long nativeTempla
teUrlServiceAndroid, | 408 private native String nativeGetUrlForContextualSearchQuery(long nativeTempla
teUrlServiceAndroid, |
396 String query, String alternateTerm, boolean shouldPrefetch, String p
rotocolVersion); | 409 String query, String alternateTerm, boolean shouldPrefetch, String p
rotocolVersion); |
397 private native String nativeGetSearchEngineUrlFromTemplateUrl( | 410 private native String nativeGetSearchEngineUrlFromTemplateUrl( |
398 long nativeTemplateUrlServiceAndroid, String keyword); | 411 long nativeTemplateUrlServiceAndroid, String keyword); |
399 private native String nativeAddSearchEngineForTesting( | 412 private native String nativeAddSearchEngineForTesting( |
400 long nativeTemplateUrlServiceAndroid, String keyword, int offset); | 413 long nativeTemplateUrlServiceAndroid, String keyword, int offset); |
401 private native String nativeUpdateLastVisitedForTesting( | 414 private native String nativeUpdateLastVisitedForTesting( |
402 long nativeTemplateUrlServiceAndroid, String keyword); | 415 long nativeTemplateUrlServiceAndroid, String keyword); |
403 } | 416 } |
OLD | NEW |