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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/tab/TabIdManager.java

Issue 1711063002: Avoid disk reads in TabPersistentStore for max tab_id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add refactoring to this CL. Created 4 years, 9 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelSelectorImpl.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/tab/TabIdManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabIdManager.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabIdManager.java
index 30113b1e2c6141a9e83b5a1873847271dfa0be89..4ccdf7cef0c3062dfc1bfef78c219a9814457463 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabIdManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabIdManager.java
@@ -10,6 +10,7 @@ import android.preference.PreferenceManager;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.VisibleForTesting;
+import org.chromium.chrome.browser.tabmodel.TabModel;
import java.util.concurrent.atomic.AtomicInteger;
@@ -38,6 +39,8 @@ public class TabIdManager {
private final Context mContext;
private final AtomicInteger mIdCounter = new AtomicInteger();
+ private SharedPreferences mPreferences;
+
/** Returns the Singleton instance of the TabIdManager. */
public static TabIdManager getInstance() {
return getInstance(ApplicationStatus.getApplicationContext());
@@ -80,14 +83,7 @@ public class TabIdManager {
// It's possible idCounter has been incremented between the get and the add but that's OK --
// in the worst case mIdCounter will just be overly incremented.
mIdCounter.addAndGet(diff);
- updateSharedPreference();
- }
-
- private void updateSharedPreference() {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
- SharedPreferences.Editor editor = prefs.edit();
- editor.putInt(PREF_NEXT_ID, mIdCounter.get());
- editor.apply();
+ mPreferences.edit().putInt(PREF_NEXT_ID, mIdCounter.get()).apply();
}
private TabIdManager(Context context) {
@@ -96,7 +92,7 @@ public class TabIdManager {
// Read the shared preference. This has to be done on the critical path to ensure that the
// myriad Activities that serve as entries into Chrome are all synchronized on the correct
// maximum Tab ID.
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
- mIdCounter.set(prefs.getInt(PREF_NEXT_ID, 0));
+ mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
+ mIdCounter.set(mPreferences.getInt(PREF_NEXT_ID, 0));
}
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelSelectorImpl.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698