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

Unified Diff: components/cronet/android/java/src/org/chromium/net/impl/JavaCronetEngine.java

Issue 2876253002: [Cronet] Add ExperimentalCronetEngine.Builder.setThreadPriority() API (Closed)
Patch Set: shutdown CronetEngines in test Created 3 years, 7 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
Index: components/cronet/android/java/src/org/chromium/net/impl/JavaCronetEngine.java
diff --git a/components/cronet/android/java/src/org/chromium/net/impl/JavaCronetEngine.java b/components/cronet/android/java/src/org/chromium/net/impl/JavaCronetEngine.java
index 4d3736e86a60946b3f419d1f96b83aaa20ec1276..a8fdfc6a743fbc72e960c68c839f8bf2278afc35 100644
--- a/components/cronet/android/java/src/org/chromium/net/impl/JavaCronetEngine.java
+++ b/components/cronet/android/java/src/org/chromium/net/impl/JavaCronetEngine.java
@@ -35,31 +35,31 @@ import java.util.concurrent.ThreadFactory;
*/
public final class JavaCronetEngine extends CronetEngineBase {
private final String mUserAgent;
-
- private final ExecutorService mExecutorService =
- Executors.newCachedThreadPool(new ThreadFactory() {
- @Override
- public Thread newThread(final Runnable r) {
- return Executors.defaultThreadFactory().newThread(new Runnable() {
- @Override
- public void run() {
- Thread.currentThread().setName("JavaCronetEngine");
- // On android, all background threads (and all threads that are part
- // of background processes) are put in a cgroup that is allowed to
- // consume up to 5% of CPU - these worker threads spend the vast
- // majority of their time waiting on I/O, so making them contend with
- // background applications for a slice of CPU doesn't make much sense.
- // We want to hurry up and get idle.
- android.os.Process.setThreadPriority(
- THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE);
- r.run();
- }
- });
- }
- });
-
- public JavaCronetEngine(String userAgent) {
- this.mUserAgent = userAgent;
+ private final ExecutorService mExecutorService;
+
+ public JavaCronetEngine(CronetEngineBuilderImpl builder) {
+ // On android, all background threads (and all threads that are part
+ // of background processes) are put in a cgroup that is allowed to
+ // consume up to 5% of CPU - these worker threads spend the vast
+ // majority of their time waiting on I/O, so making them contend with
+ // background applications for a slice of CPU doesn't make much sense.
+ // We want to hurry up and get idle.
+ final int threadPriority =
+ builder.threadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE);
+ this.mUserAgent = builder.getUserAgent();
+ this.mExecutorService = Executors.newCachedThreadPool(new ThreadFactory() {
+ @Override
+ public Thread newThread(final Runnable r) {
+ return Executors.defaultThreadFactory().newThread(new Runnable() {
+ @Override
+ public void run() {
+ Thread.currentThread().setName("JavaCronetEngine");
+ android.os.Process.setThreadPriority(threadPriority);
+ r.run();
+ }
+ });
+ }
+ });
}
@Override

Powered by Google App Engine
This is Rietveld 408576698