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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/ActivityAssigner.java

Issue 1618973002: Measure time spent in SharedPrefs-loading StrictMode violations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: unbreak Created 4 years, 10 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.SharedPreferences; 8 import android.content.SharedPreferences;
9 import android.os.SystemClock;
9 import android.util.Log; 10 import android.util.Log;
10 11
11 import org.chromium.base.ThreadUtils; 12 import org.chromium.base.ThreadUtils;
12 import org.chromium.base.VisibleForTesting; 13 import org.chromium.base.VisibleForTesting;
14 import org.chromium.base.metrics.RecordHistogram;
13 15
14 import java.util.ArrayList; 16 import java.util.ArrayList;
15 import java.util.HashSet; 17 import java.util.HashSet;
16 import java.util.List; 18 import java.util.List;
17 import java.util.Set; 19 import java.util.Set;
20 import java.util.concurrent.TimeUnit;
18 21
19 /** 22 /**
20 * Manages a rotating LRU buffer of WebappActivities to assign webapps to. 23 * Manages a rotating LRU buffer of WebappActivities to assign webapps to.
21 * 24 *
22 * In order to accommodate a limited number of WebappActivities with a potential ly unlimited number 25 * In order to accommodate a limited number of WebappActivities with a potential ly unlimited number
23 * of webapps, we have to rotate the available WebappActivities between the weba pps we start up. 26 * of webapps, we have to rotate the available WebappActivities between the weba pps we start up.
24 * Activities are reused in order of when they were last used, with the least re cently used 27 * Activities are reused in order of when they were last used, with the least re cently used
25 * ones culled first. 28 * ones culled first.
26 * 29 *
27 * It is impossible to know whether Tasks have been removed from the Recent Task list without the 30 * It is impossible to know whether Tasks have been removed from the Recent Task list without the
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // Activity has already been assigned. 210 // Activity has already been assigned.
208 Set<Integer> availableWebapps = new HashSet<Integer>(); 211 Set<Integer> availableWebapps = new HashSet<Integer>();
209 for (int i = 0; i < NUM_WEBAPP_ACTIVITIES; ++i) { 212 for (int i = 0; i < NUM_WEBAPP_ACTIVITIES; ++i) {
210 availableWebapps.add(i); 213 availableWebapps.add(i);
211 } 214 }
212 215
213 // Restore any entries that were previously saved. If it seems that the preferences have 216 // Restore any entries that were previously saved. If it seems that the preferences have
214 // been corrupted somehow, just discard the whole map. 217 // been corrupted somehow, just discard the whole map.
215 SharedPreferences prefs = mContext.getSharedPreferences(PREF_PACKAGE, Co ntext.MODE_PRIVATE); 218 SharedPreferences prefs = mContext.getSharedPreferences(PREF_PACKAGE, Co ntext.MODE_PRIVATE);
216 try { 219 try {
220 long time = SystemClock.elapsedRealtime();
217 final int numSavedEntries = prefs.getInt(PREF_NUM_SAVED_ENTRIES, 0); 221 final int numSavedEntries = prefs.getInt(PREF_NUM_SAVED_ENTRIES, 0);
222 try {
223 RecordHistogram.recordTimesHistogram("Android.StrictMode.WebappS haredPrefs",
224 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECO NDS);
225 } catch (UnsatisfiedLinkError error) {
226 // Intentionally ignored - it's ok to miss recording the metric occasionally.
227 }
218 if (numSavedEntries <= NUM_WEBAPP_ACTIVITIES) { 228 if (numSavedEntries <= NUM_WEBAPP_ACTIVITIES) {
219 for (int i = 0; i < numSavedEntries; ++i) { 229 for (int i = 0; i < numSavedEntries; ++i) {
220 String currentActivityIndexPref = PREF_ACTIVITY_INDEX + i; 230 String currentActivityIndexPref = PREF_ACTIVITY_INDEX + i;
221 String currentWebappIdPref = PREF_WEBAPP_ID + i; 231 String currentWebappIdPref = PREF_WEBAPP_ID + i;
222 232
223 int activityIndex = prefs.getInt(currentActivityIndexPref, i ); 233 int activityIndex = prefs.getInt(currentActivityIndexPref, i );
224 String webappId = prefs.getString(currentWebappIdPref, null) ; 234 String webappId = prefs.getString(currentWebappIdPref, null) ;
225 ActivityEntry entry = new ActivityEntry(activityIndex, webap pId); 235 ActivityEntry entry = new ActivityEntry(activityIndex, webap pId);
226 236
227 if (availableWebapps.remove(entry.mActivityIndex)) { 237 if (availableWebapps.remove(entry.mActivityIndex)) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 editor.putInt(PREF_NUM_SAVED_ENTRIES, mActivityList.size()); 275 editor.putInt(PREF_NUM_SAVED_ENTRIES, mActivityList.size());
266 for (int i = 0; i < mActivityList.size(); ++i) { 276 for (int i = 0; i < mActivityList.size(); ++i) {
267 String currentActivityIndexPref = PREF_ACTIVITY_INDEX + i; 277 String currentActivityIndexPref = PREF_ACTIVITY_INDEX + i;
268 String currentWebappIdPref = PREF_WEBAPP_ID + i; 278 String currentWebappIdPref = PREF_WEBAPP_ID + i;
269 editor.putInt(currentActivityIndexPref, mActivityList.get(i).mActivi tyIndex); 279 editor.putInt(currentActivityIndexPref, mActivityList.get(i).mActivi tyIndex);
270 editor.putString(currentWebappIdPref, mActivityList.get(i).mWebappId ); 280 editor.putString(currentWebappIdPref, mActivityList.get(i).mWebappId );
271 } 281 }
272 editor.apply(); 282 editor.apply();
273 } 283 }
274 } 284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698