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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java

Issue 2347973002: Enable Chrome to tweak search engines for some locales (Closed)
Patch Set: comments Created 4 years, 3 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/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..593a99091e5e012ae4f03f4eca1683c48747cfa1
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/locale/SpecialLocaleHandler.java
@@ -0,0 +1,70 @@
+// 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 for changes in 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.
+ */
+public class SpecialLocaleHandler {
+ private final String mLocaleId;
+ private long mNativeSpecialLocaleHandler;
+ private boolean mAddedToService;
+
+ /**
+ * Creates a {@link SpecialLocaleHandler} that handles changes for the given locale.
+ * @param localeId Country id of the locale. Should be 2 characters long.
+ */
+ 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 adds it to template url service. If the device
+ * was initialized in the given special locale, no-op here.
+ * @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 is no need to load the
+ // search engines, as they are already cached in the template url service.
+ 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);
+}

Powered by Google App Engine
This is Rietveld 408576698