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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java

Issue 1334533004: Hide existing StrictMode violations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes per review. Created 5 years, 3 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 | « chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivityTab.java ('k') | no next file » | 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/webapps/WebappDirectoryManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java
index 734fc90c9dc9954910add716c251cdb962289912..db8d63297c52aa8182d19c8f5890b80ab91a8144 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappDirectoryManager.java
@@ -13,6 +13,7 @@ import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
+import android.os.StrictMode;
import android.text.TextUtils;
import android.util.Log;
@@ -102,9 +103,15 @@ public class WebappDirectoryManager extends AsyncTask<Void, Void, Void> {
private void cleanUpOldWebappDirectories(
HashSet<File> directoriesToDelete, String baseDirectory) {
Context context = ApplicationStatus.getApplicationContext();
-
- String webappDirectoryAppBaseName =
- context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE).getName();
+ File webappBaseDirectory = null;
+
+ // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ webappBaseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE);
+ } finally {
+ StrictMode.setThreadPolicy(oldPolicy);
+ }
// Figure out what WebappActivities are still listed in Android's recents menu.
HashSet<String> liveWebapps = new HashSet<String>();
@@ -135,25 +142,27 @@ public class WebappDirectoryManager extends AsyncTask<Void, Void, Void> {
}
}
- // Delete all webapp directories in the main directory.
- File dataDirectory = new File(baseDirectory);
- File[] files = dataDirectory.listFiles();
- if (files != null) {
- for (File file : files) {
- String filename = file.getName();
- if (!filename.startsWith(webappDirectoryAppBaseName)) continue;
- if (filename.length() == webappDirectoryAppBaseName.length()) continue;
- directoriesToDelete.add(file);
- }
- }
-
- // Clean out webapp directories no longer corresponding to tasks in Recents.
- File webappBaseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE);
- if (webappBaseDirectory.exists()) {
- files = webappBaseDirectory.listFiles();
+ if (webappBaseDirectory != null) {
+ // Delete all webapp directories in the main directory.
+ String webappDirectoryAppBaseName = webappBaseDirectory.getName();
+ File dataDirectory = new File(baseDirectory);
+ File[] files = dataDirectory.listFiles();
if (files != null) {
for (File file : files) {
- if (!liveWebapps.contains(file.getName())) directoriesToDelete.add(file);
+ String filename = file.getName();
+ if (!filename.startsWith(webappDirectoryAppBaseName)) continue;
+ if (filename.length() == webappDirectoryAppBaseName.length()) continue;
+ directoriesToDelete.add(file);
+ }
+ }
+
+ // Clean out webapp directories no longer corresponding to tasks in Recents.
+ if (webappBaseDirectory.exists()) {
+ files = webappBaseDirectory.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (!liveWebapps.contains(file.getName())) directoriesToDelete.add(file);
+ }
}
}
}
@@ -166,11 +175,17 @@ public class WebappDirectoryManager extends AsyncTask<Void, Void, Void> {
*/
public static File getWebappDirectory(String identifier) {
Context context = ApplicationStatus.getApplicationContext();
- File baseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE);
- File webappDirectory = new File(baseDirectory, identifier);
- if (!webappDirectory.exists() && !webappDirectory.mkdir()) {
- Log.e(TAG, "Failed to create webapp directory.");
+ // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ File baseDirectory = context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE);
+ File webappDirectory = new File(baseDirectory, identifier);
+ if (!webappDirectory.exists() && !webappDirectory.mkdir()) {
+ Log.e(TAG, "Failed to create webapp directory.");
+ }
+ return webappDirectory;
+ } finally {
+ StrictMode.setThreadPolicy(oldPolicy);
}
- return webappDirectory;
}
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/webapps/FullScreenActivityTab.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698