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

Unified Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java

Issue 1813053007: Update CPU Monitor to report CPU frequency and battery level. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comment Created 4 years, 9 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 | « webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
index 1563e26ddbd200213f1e522f8490e8229a77eb78..731630405a0d1f279ae76e32935cd8e6ce96d8d5 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/util/LooperExecutor.java
@@ -14,6 +14,8 @@ import android.os.Handler;
import android.os.Looper;
import android.util.Log;
+import java.util.LinkedList;
+import java.util.List;
import java.util.concurrent.Executor;
/**
@@ -24,6 +26,7 @@ public class LooperExecutor extends Thread implements Executor {
// Object used to signal that looper thread has started and Handler instance
// associated with looper thread has been allocated.
private final Object looperStartedEvent = new Object();
+ private final List<Runnable> scheduledPeriodicRunnables = new LinkedList<Runnable>();
private Handler handler = null;
private boolean running = false;
private long threadId;
@@ -79,6 +82,41 @@ public class LooperExecutor extends Thread implements Executor {
return (Thread.currentThread().getId() == threadId);
}
+ public synchronized void scheduleAtFixedRate(final Runnable command, final long periodMillis) {
+ if (!running) {
+ Log.w(TAG, "Trying to schedule task for non running executor");
+ return;
+ }
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ if (running) {
+ command.run();
+ if (!handler.postDelayed(this, periodMillis)) {
+ Log.e(TAG, "Failed to post a delayed runnable in the chain.");
+ }
+ }
+ }
+ };
+ scheduledPeriodicRunnables.add(runnable);
+ if (!handler.postDelayed(runnable, periodMillis)) {
+ Log.e(TAG, "Failed to post a delayed runnable.");
+ }
+ }
+
+ public synchronized void cancelScheduledTasks() {
+ if (!running) {
+ Log.w(TAG, "Trying to cancel schedule tasks for non running executor");
+ return;
+ }
+
+ // Stop scheduled periodic tasks.
+ for (Runnable r : scheduledPeriodicRunnables) {
+ handler.removeCallbacks(r);
+ }
+ scheduledPeriodicRunnables.clear();
+ }
+
@Override
public synchronized void execute(final Runnable runnable) {
if (!running) {
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698