org.chromium.base.FileUtils Java Examples

The following examples show how to use org.chromium.base.FileUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentModeAssassin.java    From delion with Apache License 2.0 5 votes vote down vote up
/** Deletes all remnants of the document mode directory and preferences. */
final void deleteDocumentModeData() {
    ThreadUtils.assertOnUiThread();
    if (!setStage(STAGE_CHANGE_SETTINGS_DONE, STAGE_DELETION_STARTED)) return;

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            Log.d(TAG, "Starting to delete document mode data.");

            // Delete the old tab state directory.
            FileUtils.recursivelyDeleteFile(getDocumentDataDirectory());

            // Clean up the {@link DocumentTabModel} shared preferences.
            SharedPreferences prefs = getContext().getSharedPreferences(
                    DocumentTabModelImpl.PREF_PACKAGE, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = prefs.edit();
            editor.clear();
            editor.apply();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            Log.d(TAG, "Finished deleting document mode data.");
            setStage(STAGE_DELETION_STARTED, STAGE_DONE);
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #2
Source File: WebappDirectoryManager.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes web app directories with stale data.
 *
 * This should be called by a {@link WebappActivity} after it has restored all the data it
 * needs from its directory because the directory will be deleted during the process.
 *
 * @param context         Context to pull info and Files from.
 * @param currentWebappId ID for the currently running web app.
 * @return                AsyncTask doing the cleaning.
 */
public AsyncTask<Void, Void, Void> cleanUpDirectories(
        final Context context, final String currentWebappId) {
    if (mCleanupTask != null) return mCleanupTask;

    mCleanupTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected final Void doInBackground(Void... params) {
            Set<File> directoriesToDelete = new HashSet<File>();
            directoriesToDelete.add(getWebappDirectory(context, currentWebappId));

            boolean shouldDeleteOldDirectories =
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
            if (shouldDeleteOldDirectories && sMustCleanUpOldDirectories.getAndSet(false)) {
                findStaleWebappDirectories(context, directoriesToDelete);
            }

            for (File directory : directoriesToDelete) {
                if (isCancelled()) return null;
                FileUtils.recursivelyDeleteFile(directory);
            }

            return null;
        }
    };
    mCleanupTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    return mCleanupTask;
}
 
Example #3
Source File: OfflinePageUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Clears all shared mhtml files.
 * @param context Context that is used to access external cache directory.
 */
public static void clearSharedOfflineFiles(final Context context) {
    if (!OfflinePageBridge.isPageSharingEnabled()) return;
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            File offlinePath = getDirectoryForOfflineSharing(context);
            if (offlinePath != null) {
                FileUtils.recursivelyDeleteFile(offlinePath);
            }
            return null;
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #4
Source File: DocumentModeAssassin.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/** Deletes all remnants of the document mode directory and preferences. */
final void deleteDocumentModeData() {
    ThreadUtils.assertOnUiThread();
    if (!setStage(STAGE_CHANGE_SETTINGS_DONE, STAGE_DELETION_STARTED)) return;

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            Log.d(TAG, "Starting to delete document mode data.");

            // Delete the old tab state directory.
            FileUtils.recursivelyDeleteFile(getDocumentDataDirectory());

            // Clean up the {@link DocumentTabModel} shared preferences.
            SharedPreferences prefs = getContext().getSharedPreferences(
                    DocumentTabModelImpl.PREF_PACKAGE, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = prefs.edit();
            editor.clear();
            editor.apply();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            Log.d(TAG, "Finished deleting document mode data.");
            setStage(STAGE_DELETION_STARTED, STAGE_DONE);
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #5
Source File: DownloadManagerUi.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onDismissNoAction(Object actionData) {
    @SuppressWarnings("unchecked")
    List<DownloadHistoryItemWrapper> items = (List<DownloadHistoryItemWrapper>) actionData;

    // Deletion was not undone. Remove downloads from backend.
    final ArrayList<File> filesToDelete = new ArrayList<>();

    // Some types of DownloadHistoryItemWrappers delete their own files when #remove()
    // is called. Determine which files are not deleted by the #remove() call.
    for (int i = 0; i < items.size(); i++) {
        DownloadHistoryItemWrapper wrappedItem  = items.get(i);
        if (!wrappedItem.remove()) filesToDelete.add(wrappedItem.getFile());
    }

    // Delete the files associated with the download items (if necessary) using a single
    // AsyncTask that batch deletes all of the files. The thread pool has a finite
    // number of tasks that can be queued at once. If too many tasks are queued an
    // exception is thrown. See crbug.com/643811.
    if (filesToDelete.size() != 0) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            public Void doInBackground(Void... params) {
                FileUtils.batchDeleteFiles(filesToDelete);
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    RecordUserAction.record("Android.DownloadManager.Delete");
}
 
Example #6
Source File: WebappDirectoryManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes web app directories with stale data.
 *
 * This should be called by a {@link WebappActivity} after it has restored all the data it
 * needs from its directory because the directory will be deleted during the process.
 *
 * @param context         Context to pull info and Files from.
 * @param currentWebappId ID for the currently running web app.
 * @return                AsyncTask doing the cleaning.
 */
public AsyncTask<Void, Void, Void> cleanUpDirectories(
        final Context context, final String currentWebappId) {
    if (mCleanupTask != null) return mCleanupTask;

    mCleanupTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected final Void doInBackground(Void... params) {
            Set<File> directoriesToDelete = new HashSet<File>();
            directoriesToDelete.add(getWebappDirectory(context, currentWebappId));

            boolean shouldDeleteOldDirectories =
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
            if (shouldDeleteOldDirectories && sMustCleanUpOldDirectories.getAndSet(false)) {
                findStaleWebappDirectories(context, directoriesToDelete);
            }

            for (File directory : directoriesToDelete) {
                if (isCancelled()) return null;
                FileUtils.recursivelyDeleteFile(directory);
            }

            return null;
        }
    };
    mCleanupTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    return mCleanupTask;
}
 
Example #7
Source File: OfflinePageUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Clears all shared mhtml files.
 * @param context Context that is used to access external cache directory.
 */
public static void clearSharedOfflineFiles(final Context context) {
    if (!OfflinePageBridge.isPageSharingEnabled()) return;
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            File offlinePath = getDirectoryForOfflineSharing(context);
            if (offlinePath != null) {
                FileUtils.recursivelyDeleteFile(offlinePath);
            }
            return null;
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #8
Source File: DocumentModeAssassin.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Deletes all remnants of the document mode directory and preferences. */
final void deleteDocumentModeData() {
    ThreadUtils.assertOnUiThread();
    if (!setStage(STAGE_CHANGE_SETTINGS_DONE, STAGE_DELETION_STARTED)) return;

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            Log.d(TAG, "Starting to delete document mode data.");

            // Delete the old tab state directory.
            FileUtils.recursivelyDeleteFile(getDocumentDataDirectory());

            // Clean up the {@link DocumentTabModel} shared preferences.
            SharedPreferences prefs = getContext().getSharedPreferences(
                    DocumentTabModelImpl.PREF_PACKAGE, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = prefs.edit();
            editor.clear();
            editor.apply();
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            Log.d(TAG, "Finished deleting document mode data.");
            setStage(STAGE_DELETION_STARTED, STAGE_DONE);
        }
    }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
 
Example #9
Source File: DownloadManagerUi.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onDismissNoAction(Object actionData) {
    @SuppressWarnings("unchecked")
    List<DownloadHistoryItemWrapper> items = (List<DownloadHistoryItemWrapper>) actionData;

    // Deletion was not undone. Remove downloads from backend.
    final ArrayList<File> filesToDelete = new ArrayList<>();

    // Some types of DownloadHistoryItemWrappers delete their own files when #remove()
    // is called. Determine which files are not deleted by the #remove() call.
    for (int i = 0; i < items.size(); i++) {
        DownloadHistoryItemWrapper wrappedItem  = items.get(i);
        if (!wrappedItem.remove()) filesToDelete.add(wrappedItem.getFile());
    }

    // Delete the files associated with the download items (if necessary) using a single
    // AsyncTask that batch deletes all of the files. The thread pool has a finite
    // number of tasks that can be queued at once. If too many tasks are queued an
    // exception is thrown. See crbug.com/643811.
    if (filesToDelete.size() != 0) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            public Void doInBackground(Void... params) {
                FileUtils.batchDeleteFiles(filesToDelete);
                return null;
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }

    RecordUserAction.record("Android.DownloadManager.Delete");
}
 
Example #10
Source File: DownloadUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a URI that points at the file.
 * @param file File to get a URI for.
 * @return URI that points at that file, either as a content:// URI or a file:// URI.
 */
public static Uri getUriForItem(File file) {
    Uri uri = null;

    // FileUtils.getUriForFile() causes a disk read when it calls into
    // FileProvider#getUriForFile. Obtaining a content URI is on the critical path for creating
    // a share intent after the user taps on the share button, so even if we were to run this
    // method on a background thread we would have to wait. As it depends on user-selected
    // items, we cannot know/preload which URIs we need until the user presses share.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    uri = FileUtils.getUriForFile(file);
    StrictMode.setThreadPolicy(oldPolicy);

    return uri;
}
 
Example #11
Source File: WebappDirectoryManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes web app directories with stale data.
 *
 * This should be called by a {@link WebappActivity} after it has restored all the data it
 * needs from its directory because the directory will be deleted during the process.
 *
 * @param context         Context to pull info and Files from.
 * @param currentWebappId ID for the currently running web app.
 * @return                AsyncTask doing the cleaning.
 */
public AsyncTask<Void, Void, Void> cleanUpDirectories(
        final Context context, final String currentWebappId) {
    if (mCleanupTask != null) return mCleanupTask;

    mCleanupTask = new AsyncTask<Void, Void, Void>() {
        @Override
        protected final Void doInBackground(Void... params) {
            Set<File> directoriesToDelete = new HashSet<File>();
            directoriesToDelete.add(getWebappDirectory(context, currentWebappId));

            boolean shouldDeleteOldDirectories =
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
            if (shouldDeleteOldDirectories && sMustCleanUpOldDirectories.getAndSet(false)) {
                findStaleWebappDirectories(context, directoriesToDelete);
            }

            for (File directory : directoriesToDelete) {
                if (isCancelled()) return null;
                FileUtils.recursivelyDeleteFile(directory);
            }

            return null;
        }
    };
    mCleanupTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    return mCleanupTask;
}