Index: chrome/android/java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2faee25e4538b2ba9d6501648ae8c38a1d721796 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java |
@@ -0,0 +1,69 @@ |
+// Copyright 2016 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.locale; |
+ |
+/** |
+ * A handler that handles changes for a given special locale. This is a JNI bridge and it owns the |
+ * native object. Make sure to call Destroy() after this object is not used anymore. |
Maria
2016/09/16 23:44:01
nit: Switch first sentence to "A Handler for chang
Ian Wen
2016/09/19 17:37:55
Done.
|
+ */ |
+public class SpecialLocaleHandler { |
+ private long mNativeSpecialLocaleHandler; |
+ private String mLocaleId; |
Maria
2016/09/16 23:44:01
final
Ian Wen
2016/09/19 17:37:55
Done.
|
+ private boolean mAddedToService; |
+ |
+ /** |
+ * Creates a {@link SpecialLocaleHandler} that handles changes for the given locale. |
+ * @param localeId Country id of the locale. Should be 2-character long. |
Maria
2016/09/16 23:44:01
nit: character -> characters
Are all locales real
Ian Wen
2016/09/19 17:37:55
No it can't be. In [1] we compute the ID as intege
|
+ */ |
+ public SpecialLocaleHandler(String localeId) { |
+ assert localeId.length() == 2; |
+ mLocaleId = localeId; |
+ mNativeSpecialLocaleHandler = nativeInit(localeId); |
+ } |
+ |
+ /** |
+ * This *must* be called after the {@link SpecialLocaleHandler} is not used anymore. |
+ */ |
+ public void destroy() { |
+ assert mNativeSpecialLocaleHandler != 0; |
+ nativeDestroy(mNativeSpecialLocaleHandler); |
+ mNativeSpecialLocaleHandler = 0; |
+ } |
+ |
+ /** |
+ * Loads the template urls for this locale, and add it to template url service. If the devices |
Maria
2016/09/16 23:44:01
nit: add -> adds
Ian Wen
2016/09/19 17:37:55
Done.
|
+ * was initialized in the given special locale, no-op here. |
Maria
2016/09/16 23:44:01
nit: was -> were
Ian Wen
2016/09/19 17:37:55
Done.
|
+ * @return Whether loading is needed. |
+ */ |
+ public boolean loadTemplateUrls() { |
+ assert mNativeSpecialLocaleHandler != 0; |
+ // If the locale is the same as the one set at install time, there will be enough |
Maria
2016/09/16 23:44:01
Not sure I understand the comment
Ian Wen
2016/09/19 17:37:55
Oops. Fixed it.
|
+ mAddedToService = nativeLoadTemplateUrls(mNativeSpecialLocaleHandler); |
+ return mAddedToService; |
+ } |
+ |
+ /** |
+ * Removes the template urls that was added by {@link #loadTemplateUrls()}. No-op if |
+ * {@link #loadTemplateUrls()} returned false. |
+ */ |
+ public void removeTemplateUrls() { |
+ assert mNativeSpecialLocaleHandler != 0; |
+ if (mAddedToService) nativeRemoveTemplateUrls(mNativeSpecialLocaleHandler); |
+ } |
+ |
+ /** |
+ * Overrides the default search provider in special locale. |
+ */ |
+ public void overrideDefaultSearchProvider() { |
+ assert mNativeSpecialLocaleHandler != 0; |
+ nativeOverrideDefaultSearchProvider(mNativeSpecialLocaleHandler); |
+ } |
+ |
+ private static native long nativeInit(String localeId); |
+ private static native void nativeDestroy(long nativeSpecialLocaleHandler); |
+ private static native boolean nativeLoadTemplateUrls(long nativeSpecialLocaleHandler); |
+ private static native void nativeRemoveTemplateUrls(long nativeSpecialLocaleHandler); |
+ private static native void nativeOverrideDefaultSearchProvider(long nativeSpecialLocaleHandler); |
+} |