OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.searchwidget; | 5 package org.chromium.chrome.browser.searchwidget; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
9 import android.appwidget.AppWidgetManager; | 9 import android.appwidget.AppWidgetManager; |
10 import android.appwidget.AppWidgetProvider; | 10 import android.appwidget.AppWidgetProvider; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 /** Number of consecutive crashes this widget will absorb before giving up.
*/ | 120 /** Number of consecutive crashes this widget will absorb before giving up.
*/ |
121 private static final int CRASH_LIMIT = 3; | 121 private static final int CRASH_LIMIT = 3; |
122 | 122 |
123 private static final String TAG = "searchwidget"; | 123 private static final String TAG = "searchwidget"; |
124 private static final Object DELEGATE_LOCK = new Object(); | 124 private static final Object DELEGATE_LOCK = new Object(); |
125 private static final Object OBSERVER_LOCK = new Object(); | 125 private static final Object OBSERVER_LOCK = new Object(); |
126 | 126 |
127 /** The default search engine's root URL. */ | 127 /** The default search engine's root URL. */ |
128 private static String sDefaultSearchEngineUrl; | 128 private static String sDefaultSearchEngineUrl; |
129 | 129 |
| 130 @SuppressLint("StaticFieldLeak") |
130 private static SearchWidgetTemplateUrlServiceObserver sObserver; | 131 private static SearchWidgetTemplateUrlServiceObserver sObserver; |
| 132 @SuppressLint("StaticFieldLeak") |
131 private static SearchWidgetProviderDelegate sDelegate; | 133 private static SearchWidgetProviderDelegate sDelegate; |
132 | 134 |
133 /** | 135 /** |
134 * Creates the singleton instance of the observer that will monitor for sear
ch engine changes. | 136 * Creates the singleton instance of the observer that will monitor for sear
ch engine changes. |
135 * The native library and the browser process must have been fully loaded be
fore calling this. | 137 * The native library and the browser process must have been fully loaded be
fore calling this. |
136 */ | 138 */ |
137 public static void initialize() { | 139 public static void initialize() { |
138 ThreadUtils.assertOnUiThread(); | 140 ThreadUtils.assertOnUiThread(); |
139 assert LibraryLoader.isInitialized(); | 141 assert LibraryLoader.isInitialized(); |
140 | 142 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 316 |
315 if (!shouldShowFullString()) engineName = null; | 317 if (!shouldShowFullString()) engineName = null; |
316 | 318 |
317 if (!TextUtils.equals(getCachedEngineName(prefs), engineName)) { | 319 if (!TextUtils.equals(getCachedEngineName(prefs), engineName)) { |
318 prefs.edit().putString(PREF_SEARCH_ENGINE_SHORTNAME, engineName).app
ly(); | 320 prefs.edit().putString(PREF_SEARCH_ENGINE_SHORTNAME, engineName).app
ly(); |
319 performUpdate(null); | 321 performUpdate(null); |
320 } | 322 } |
321 } | 323 } |
322 | 324 |
323 /** Updates the number of consecutive crashes this widget has absorbed. */ | 325 /** Updates the number of consecutive crashes this widget has absorbed. */ |
324 @SuppressLint("CommitPrefEdits") | 326 @SuppressLint({"ApplySharedPref", "CommitPrefEdits"}) |
325 static void updateNumConsecutiveCrashes(int newValue) { | 327 static void updateNumConsecutiveCrashes(int newValue) { |
326 SharedPreferences prefs = getDelegate().getSharedPreferences(); | 328 SharedPreferences prefs = getDelegate().getSharedPreferences(); |
327 if (getNumConsecutiveCrashes(prefs) == newValue) return; | 329 if (getNumConsecutiveCrashes(prefs) == newValue) return; |
328 | 330 |
329 SharedPreferences.Editor editor = prefs.edit(); | 331 SharedPreferences.Editor editor = prefs.edit(); |
330 if (newValue == 0) { | 332 if (newValue == 0) { |
331 editor.remove(PREF_NUM_CONSECUTIVE_CRASHES); | 333 editor.remove(PREF_NUM_CONSECUTIVE_CRASHES); |
332 } else { | 334 } else { |
333 editor.putInt(PREF_NUM_CONSECUTIVE_CRASHES, newValue); | 335 editor.putInt(PREF_NUM_CONSECUTIVE_CRASHES, newValue); |
334 } | 336 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 assert sDelegate == null; | 395 assert sDelegate == null; |
394 sDelegate = delegate; | 396 sDelegate = delegate; |
395 } | 397 } |
396 | 398 |
397 /** See {@link #sDefaultSearchEngineUrl}. */ | 399 /** See {@link #sDefaultSearchEngineUrl}. */ |
398 static String getDefaultSearchEngineUrl() { | 400 static String getDefaultSearchEngineUrl() { |
399 // TODO(yusufo): Get rid of this. | 401 // TODO(yusufo): Get rid of this. |
400 return sDefaultSearchEngineUrl; | 402 return sDefaultSearchEngineUrl; |
401 } | 403 } |
402 } | 404 } |
OLD | NEW |