| OLD | NEW |
| 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 Loading... |
| 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 // Access the WebappDataStorage to force it to finish loading. A
strict mode |
| 117 // exception is thrown if the WebappDataStorage is accessed on t
he UI thread prior |
| 118 // to the storage being fully loaded. |
| 119 storage.getLastUsedTime(); |
| 120 return storage; |
| 116 } | 121 } |
| 117 | 122 |
| 118 @Override | 123 @Override |
| 119 protected final void onPostExecute(WebappDataStorage storage) { | 124 protected final void onPostExecute(WebappDataStorage storage) { |
| 120 // Guarantee that last used time != WebappDataStorage.LAST_USED_
INVALID. Must be | 125 // Update the last used time in order to prevent |
| 121 // run on the main thread as SharedPreferences.Editor.apply() is
called. | 126 // {@link WebappRegistry@unregisterOldWebapps()} from deleting t
he |
| 127 // WebappDataStorage. Must be run on the main thread as |
| 128 // SharedPreferences.Editor.apply() is called. |
| 122 mStorages.put(webappId, storage); | 129 mStorages.put(webappId, storage); |
| 123 mPreferences.edit().putStringSet(KEY_WEBAPP_SET, mStorages.keySe
t()).apply(); | 130 mPreferences.edit().putStringSet(KEY_WEBAPP_SET, mStorages.keySe
t()).apply(); |
| 124 storage.updateLastUsedTime(); | 131 storage.updateLastUsedTime(); |
| 125 if (callback != null) callback.onWebappDataStorageRetrieved(stor
age); | 132 if (callback != null) callback.onWebappDataStorageRetrieved(stor
age); |
| 126 } | 133 } |
| 127 }.execute(); | 134 }.execute(); |
| 128 } | 135 } |
| 129 | 136 |
| 130 /** | 137 /** |
| 131 * Returns the WebappDataStorage object for webappId, or null if one cannot
be found. | 138 * 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 Loading... |
| 279 } | 286 } |
| 280 } | 287 } |
| 281 } else { | 288 } else { |
| 282 if (webapps.contains(idToInitialize) | 289 if (webapps.contains(idToInitialize) |
| 283 && (replaceExisting || !mStorages.containsKey(idToInitialize
))) { | 290 && (replaceExisting || !mStorages.containsKey(idToInitialize
))) { |
| 284 mStorages.put(idToInitialize, WebappDataStorage.open(idToInitial
ize)); | 291 mStorages.put(idToInitialize, WebappDataStorage.open(idToInitial
ize)); |
| 285 } | 292 } |
| 286 } | 293 } |
| 287 } | 294 } |
| 288 } | 295 } |
| OLD | NEW |