Chromium Code Reviews| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 static final String PREF_SEARCH_ENGINE_SHORTNAME = | 116 static final String PREF_SEARCH_ENGINE_SHORTNAME = |
| 117 "org.chromium.chrome.browser.searchwidget.SEARCH_ENGINE_SHORTNAME"; | 117 "org.chromium.chrome.browser.searchwidget.SEARCH_ENGINE_SHORTNAME"; |
| 118 | 118 |
| 119 /** Number of consecutive crashes this widget will absorb before giving up. */ | 119 /** Number of consecutive crashes this widget will absorb before giving up. */ |
| 120 private static final int CRASH_LIMIT = 3; | 120 private static final int CRASH_LIMIT = 3; |
| 121 | 121 |
| 122 private static final String TAG = "searchwidget"; | 122 private static final String TAG = "searchwidget"; |
| 123 private static final Object DELEGATE_LOCK = new Object(); | 123 private static final Object DELEGATE_LOCK = new Object(); |
| 124 private static final Object OBSERVER_LOCK = new Object(); | 124 private static final Object OBSERVER_LOCK = new Object(); |
| 125 | 125 |
| 126 // TODO(crbug.com/635567): Fix this properly. | |
| 127 @SuppressLint("StaticFieldLeak") | |
| 126 private static SearchWidgetTemplateUrlServiceObserver sObserver; | 128 private static SearchWidgetTemplateUrlServiceObserver sObserver; |
| 129 // TODO(crbug.com/635567): Fix this properly. | |
| 130 @SuppressLint("StaticFieldLeak") | |
| 127 private static SearchWidgetProviderDelegate sDelegate; | 131 private static SearchWidgetProviderDelegate sDelegate; |
| 128 | 132 |
| 129 /** | 133 /** |
| 130 * Creates the singleton instance of the observer that will monitor for sear ch engine changes. | 134 * Creates the singleton instance of the observer that will monitor for sear ch engine changes. |
| 131 * The native library and the browser process must have been fully loaded be fore calling this. | 135 * The native library and the browser process must have been fully loaded be fore calling this. |
| 132 */ | 136 */ |
| 133 public static void initialize() { | 137 public static void initialize() { |
| 134 ThreadUtils.assertOnUiThread(); | 138 ThreadUtils.assertOnUiThread(); |
| 135 assert LibraryLoader.isInitialized(); | 139 assert LibraryLoader.isInitialized(); |
| 136 | 140 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 308 |
| 305 if (!shouldShowFullString()) engineName = null; | 309 if (!shouldShowFullString()) engineName = null; |
| 306 | 310 |
| 307 if (!TextUtils.equals(getCachedEngineName(prefs), engineName)) { | 311 if (!TextUtils.equals(getCachedEngineName(prefs), engineName)) { |
| 308 prefs.edit().putString(PREF_SEARCH_ENGINE_SHORTNAME, engineName).app ly(); | 312 prefs.edit().putString(PREF_SEARCH_ENGINE_SHORTNAME, engineName).app ly(); |
| 309 performUpdate(null); | 313 performUpdate(null); |
| 310 } | 314 } |
| 311 } | 315 } |
| 312 | 316 |
| 313 /** Updates the number of consecutive crashes this widget has absorbed. */ | 317 /** Updates the number of consecutive crashes this widget has absorbed. */ |
| 314 @SuppressLint("CommitPrefEdits") | 318 @SuppressLint({ |
|
Ted C
2017/04/27 19:02:47
can this not all fit on a single line?
F
2017/04/28 18:25:15
Done.
| |
| 319 "CommitPrefEdits", "ApplySharedPref" | |
| 320 }) | |
| 315 static void updateNumConsecutiveCrashes(int newValue) { | 321 static void updateNumConsecutiveCrashes(int newValue) { |
| 316 SharedPreferences prefs = getDelegate().getSharedPreferences(); | 322 SharedPreferences prefs = getDelegate().getSharedPreferences(); |
| 317 if (getNumConsecutiveCrashes(prefs) == newValue) return; | 323 if (getNumConsecutiveCrashes(prefs) == newValue) return; |
| 318 | 324 |
| 319 SharedPreferences.Editor editor = prefs.edit(); | 325 SharedPreferences.Editor editor = prefs.edit(); |
| 320 if (newValue == 0) { | 326 if (newValue == 0) { |
| 321 editor.remove(PREF_NUM_CONSECUTIVE_CRASHES); | 327 editor.remove(PREF_NUM_CONSECUTIVE_CRASHES); |
| 322 } else { | 328 } else { |
| 323 editor.putInt(PREF_NUM_CONSECUTIVE_CRASHES, newValue); | 329 editor.putInt(PREF_NUM_CONSECUTIVE_CRASHES, newValue); |
| 324 } | 330 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 return freIntent == null; | 383 return freIntent == null; |
| 378 } | 384 } |
| 379 | 385 |
| 380 /** Sets an {@link SearchWidgetProviderDelegate} to interact with. */ | 386 /** Sets an {@link SearchWidgetProviderDelegate} to interact with. */ |
| 381 @VisibleForTesting | 387 @VisibleForTesting |
| 382 static void setDelegateForTest(SearchWidgetProviderDelegate delegate) { | 388 static void setDelegateForTest(SearchWidgetProviderDelegate delegate) { |
| 383 assert sDelegate == null; | 389 assert sDelegate == null; |
| 384 sDelegate = delegate; | 390 sDelegate = delegate; |
| 385 } | 391 } |
| 386 } | 392 } |
| OLD | NEW |