diff options
author | lalitm <lalitm@google.com> | 2015-09-03 11:04:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-03 18:04:46 +0000 |
commit | 53667972102b9cf2d7ad60694518301a0d4b8025 (patch) | |
tree | cf97cb18d0725b68f0115ce9c146c2a729b715e9 /testing/android | |
parent | fd1a6fd38213817eb7d7e8d0df6c82fc9223ee0c (diff) | |
download | chromium_src-53667972102b9cf2d7ad60694518301a0d4b8025.zip chromium_src-53667972102b9cf2d7ad60694518301a0d4b8025.tar.gz chromium_src-53667972102b9cf2d7ad60694518301a0d4b8025.tar.bz2 |
webapps: Add a registry to keep track of web apps with data
Web apps which are storing data using SharedPreferences will need to be cleaned
up at some point. To do this, we need a way of knowing the web apps which have
stored data.
The way used in this CL is preferrable to iterating over the Files as less IO
happens during cleanup plus we don't need to have ugly hardcoded paths. Hardcoding
would be necessary as Android does not have a way of finding all the
SharedPreferences an application has created.
BUG=508627
Review URL: https://codereview.chromium.org/1312403004
Cr-Commit-Position: refs/heads/master@{#347189}
Diffstat (limited to 'testing/android')
-rw-r--r-- | testing/android/junit/java/src/org/chromium/testing/local/BackgroundShadowAsyncTask.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/testing/android/junit/java/src/org/chromium/testing/local/BackgroundShadowAsyncTask.java b/testing/android/junit/java/src/org/chromium/testing/local/BackgroundShadowAsyncTask.java new file mode 100644 index 0000000..e542128 --- /dev/null +++ b/testing/android/junit/java/src/org/chromium/testing/local/BackgroundShadowAsyncTask.java @@ -0,0 +1,58 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.testing.local; + +import static org.junit.Assert.fail; + +import android.os.AsyncTask; + +import org.robolectric.Robolectric; +import org.robolectric.annotation.Implementation; +import org.robolectric.annotation.Implements; +import org.robolectric.shadows.ShadowAsyncTask; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * Executes async tasks on a background thread and waits on the result on the main thread. + * This is useful for users of AsyncTask on Roboelectric who check if the code is actually being + * run on a background thread (i.e. through the use of {@link ThreadUtils#runningOnUiThread()}). + * @param <Params> type for execute function parameters + * @param <Progress> type for reporting Progress + * @param <Result> type for reporting result + */ +@Implements(AsyncTask.class) +public class BackgroundShadowAsyncTask<Params, Progress, Result> extends + ShadowAsyncTask<Params, Progress, Result> { + + private static final ExecutorService sExecutorService = Executors.newSingleThreadExecutor(); + + @Implementation + @SafeVarargs + public final AsyncTask<Params, Progress, Result> execute(final Params... params) { + try { + return sExecutorService.submit(new Callable<AsyncTask<Params, Progress, Result>>() { + @Override + public AsyncTask<Params, Progress, Result> call() throws Exception { + return BackgroundShadowAsyncTask.super.execute(params); + } + }).get(); + } catch (Exception ex) { + fail(ex.getMessage()); + return null; + } + } + + public static void runBackgroundTasks() throws Exception { + sExecutorService.submit(new Runnable() { + @Override + public void run() { + Robolectric.runBackgroundTasks(); + } + }).get(); + } +}
\ No newline at end of file |