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

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

Issue 2935853002: [Android Refactor] Reland: Merge WebappDataStorage#LAST_USED_UNSET and LAST_USED_INVALID (Closed)
Patch Set: ABCD Created 3 years, 6 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.content.pm.PackageManager; 9 import android.content.pm.PackageManager;
10 import android.os.AsyncTask; 10 import android.os.AsyncTask;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 * @param webappId The id of the web app to register. 105 * @param webappId The id of the web app to register.
106 * @param callback The callback to run with the WebappDataStorage argument. 106 * @param callback The callback to run with the WebappDataStorage argument.
107 * @return The storage object for the web app. 107 * @return The storage object for the web app.
108 */ 108 */
109 public void register(final String webappId, final FetchWebappDataStorageCall back callback) { 109 public void register(final String webappId, final FetchWebappDataStorageCall back callback) {
110 new AsyncTask<Void, Void, WebappDataStorage>() { 110 new AsyncTask<Void, Void, WebappDataStorage>() {
111 @Override 111 @Override
112 protected final WebappDataStorage doInBackground(Void... nothing) { 112 protected final WebappDataStorage doInBackground(Void... nothing) {
113 // Create the WebappDataStorage on the background thread, as thi s must create and 113 // Create the WebappDataStorage on the background thread, as thi s must create and
114 // open a new SharedPreferences. 114 // open a new SharedPreferences.
115 return WebappDataStorage.open(webappId); 115 WebappDataStorage storage = WebappDataStorage.open(webappId);
116 // The first read from {@link WebappDataStorage} must be done in the background.
dominickn 2017/06/13 01:36:57 This is an interesting restriction! Is it new?
pkotwicz 2017/06/13 03:14:29 Thank you for your question! It forced me to do mo
dominickn 2017/06/13 23:13:21 Perhaps this bit of code should be moved to warmUp
117 // Otherwise a strict mode exception is thrown. Do it now.
118 storage.getLastUsedTime();
119 return storage;
116 } 120 }
117 121
118 @Override 122 @Override
119 protected final void onPostExecute(WebappDataStorage storage) { 123 protected final void onPostExecute(WebappDataStorage storage) {
120 // Guarantee that last used time != WebappDataStorage.LAST_USED_ INVALID. Must be 124 // Update the last used time in order to prevent
121 // run on the main thread as SharedPreferences.Editor.apply() is called. 125 // {@link WebappRegistry@unregisterOldWebapps()} from deleting t he
126 // WebappDataStorage. Must be run on the main thread as
127 // SharedPreferences.Editor.apply() is called.
122 mStorages.put(webappId, storage); 128 mStorages.put(webappId, storage);
123 mPreferences.edit().putStringSet(KEY_WEBAPP_SET, mStorages.keySe t()).apply(); 129 mPreferences.edit().putStringSet(KEY_WEBAPP_SET, mStorages.keySe t()).apply();
124 storage.updateLastUsedTime(); 130 storage.updateLastUsedTime();
125 if (callback != null) callback.onWebappDataStorageRetrieved(stor age); 131 if (callback != null) callback.onWebappDataStorageRetrieved(stor age);
126 } 132 }
127 }.execute(); 133 }.execute();
128 } 134 }
129 135
130 /** 136 /**
131 * Returns the WebappDataStorage object for webappId, or null if one cannot be found. 137 * Returns the WebappDataStorage object for webappId, or null if one cannot be found.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 285 }
280 } 286 }
281 } else { 287 } else {
282 if (webapps.contains(idToInitialize) 288 if (webapps.contains(idToInitialize)
283 && (replaceExisting || !mStorages.containsKey(idToInitialize ))) { 289 && (replaceExisting || !mStorages.containsKey(idToInitialize ))) {
284 mStorages.put(idToInitialize, WebappDataStorage.open(idToInitial ize)); 290 mStorages.put(idToInitialize, WebappDataStorage.open(idToInitial ize));
285 } 291 }
286 } 292 }
287 } 293 }
288 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698