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

Side by Side 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: fix compile 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.locale;
6
7 /**
8 * A Handler for changes in a given special locale. This is a JNI bridge and it owns the native
9 * object. Make sure to call Destroy() after this object is not used anymore.
10 */
11 public class SpecialLocaleHandler {
12 private final String mLocaleId;
13 private long mNativeSpecialLocaleHandler;
14 private boolean mAddedToService;
15
16 /**
17 * Creates a {@link SpecialLocaleHandler} that handles changes for the given locale.
18 * @param localeId Country id of the locale. Should be 2 characters long.
19 */
20 public SpecialLocaleHandler(String localeId) {
21 assert localeId.length() == 2;
22 mLocaleId = localeId;
23 mNativeSpecialLocaleHandler = nativeInit(localeId);
24 }
25
26 /**
27 * This *must* be called after the {@link SpecialLocaleHandler} is not used anymore.
28 */
29 public void destroy() {
30 assert mNativeSpecialLocaleHandler != 0;
31 nativeDestroy(mNativeSpecialLocaleHandler);
32 mNativeSpecialLocaleHandler = 0;
33 }
34
35 /**
36 * Loads the template urls for this locale, and adds it to template url serv ice. If the device
37 * was initialized in the given special locale, no-op here.
38 * @return Whether loading is needed.
39 */
40 public boolean loadTemplateUrls() {
41 assert mNativeSpecialLocaleHandler != 0;
42 // If the locale is the same as the one set at install time, there is no need to load the
43 // search engines, as they are already cached in the template url servic e.
44 mAddedToService = nativeLoadTemplateUrls(mNativeSpecialLocaleHandler);
45 return mAddedToService;
46 }
47
48 /**
49 * Removes the template urls that was added by {@link #loadTemplateUrls()}. No-op if
50 * {@link #loadTemplateUrls()} returned false.
51 */
52 public void removeTemplateUrls() {
53 assert mNativeSpecialLocaleHandler != 0;
54 if (mAddedToService) nativeRemoveTemplateUrls(mNativeSpecialLocaleHandle r);
55 }
56
57 /**
58 * Overrides the default search provider in special locale.
59 */
60 public void overrideDefaultSearchProvider() {
61 assert mNativeSpecialLocaleHandler != 0;
62 nativeOverrideDefaultSearchProvider(mNativeSpecialLocaleHandler);
63 }
64
65 private static native long nativeInit(String localeId);
66 private static native void nativeDestroy(long nativeSpecialLocaleHandler);
67 private static native boolean nativeLoadTemplateUrls(long nativeSpecialLocal eHandler);
68 private static native void nativeRemoveTemplateUrls(long nativeSpecialLocale Handler);
69 private static native void nativeOverrideDefaultSearchProvider(long nativeSp ecialLocaleHandler);
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698