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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net.impl; 5 package org.chromium.net.impl;
6 6
7 import static android.os.Process.THREAD_PRIORITY_BACKGROUND; 7 import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
8 import static android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE; 8 import static android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE;
9 9
10 import org.chromium.net.BidirectionalStream; 10 import org.chromium.net.BidirectionalStream;
(...skipping 17 matching lines...) Expand all
28 import java.util.concurrent.Executors; 28 import java.util.concurrent.Executors;
29 import java.util.concurrent.ThreadFactory; 29 import java.util.concurrent.ThreadFactory;
30 30
31 /** 31 /**
32 * {@link java.net.HttpURLConnection} backed CronetEngine. 32 * {@link java.net.HttpURLConnection} backed CronetEngine.
33 * 33 *
34 * <p>Does not support netlogs, transferred data measurement, bidistream, cache, or priority. 34 * <p>Does not support netlogs, transferred data measurement, bidistream, cache, or priority.
35 */ 35 */
36 public final class JavaCronetEngine extends CronetEngineBase { 36 public final class JavaCronetEngine extends CronetEngineBase {
37 private final String mUserAgent; 37 private final String mUserAgent;
38 private final ExecutorService mExecutorService;
38 39
39 private final ExecutorService mExecutorService = 40 public JavaCronetEngine(CronetEngineBuilderImpl builder) {
40 Executors.newCachedThreadPool(new ThreadFactory() { 41 // On android, all background threads (and all threads that are part
41 @Override 42 // of background processes) are put in a cgroup that is allowed to
42 public Thread newThread(final Runnable r) { 43 // consume up to 5% of CPU - these worker threads spend the vast
43 return Executors.defaultThreadFactory().newThread(new Runnab le() { 44 // majority of their time waiting on I/O, so making them contend with
44 @Override 45 // background applications for a slice of CPU doesn't make much sense.
45 public void run() { 46 // We want to hurry up and get idle.
46 Thread.currentThread().setName("JavaCronetEngine"); 47 final int threadPriority =
47 // On android, all background threads (and all threa ds that are part 48 builder.threadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIOR ITY_MORE_FAVORABLE);
48 // of background processes) are put in a cgroup that is allowed to 49 this.mUserAgent = builder.getUserAgent();
49 // consume up to 5% of CPU - these worker threads sp end the vast 50 this.mExecutorService = Executors.newCachedThreadPool(new ThreadFactory( ) {
50 // majority of their time waiting on I/O, so making them contend with 51 @Override
51 // background applications for a slice of CPU doesn' t make much sense. 52 public Thread newThread(final Runnable r) {
52 // We want to hurry up and get idle. 53 return Executors.defaultThreadFactory().newThread(new Runnable() {
53 android.os.Process.setThreadPriority( 54 @Override
54 THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY _MORE_FAVORABLE); 55 public void run() {
55 r.run(); 56 Thread.currentThread().setName("JavaCronetEngine");
56 } 57 android.os.Process.setThreadPriority(threadPriority);
57 }); 58 r.run();
58 } 59 }
59 }); 60 });
60 61 }
61 public JavaCronetEngine(String userAgent) { 62 });
62 this.mUserAgent = userAgent;
63 } 63 }
64 64
65 @Override 65 @Override
66 public UrlRequestBase createRequest(String url, UrlRequest.Callback callback , Executor executor, 66 public UrlRequestBase createRequest(String url, UrlRequest.Callback callback , Executor executor,
67 int priority, Collection<Object> connectionAnnotations, boolean disa bleCache, 67 int priority, Collection<Object> connectionAnnotations, boolean disa bleCache,
68 boolean disableConnectionMigration, boolean allowDirectExecutor) { 68 boolean disableConnectionMigration, boolean allowDirectExecutor) {
69 return new JavaUrlRequest( 69 return new JavaUrlRequest(
70 callback, mExecutorService, executor, url, mUserAgent, allowDire ctExecutor); 70 callback, mExecutorService, executor, url, mUserAgent, allowDire ctExecutor);
71 } 71 }
72 72
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Returning null causes this factory to pass though, which ends up usin g the platform's 173 // Returning null causes this factory to pass though, which ends up usin g the platform's
174 // implementation. 174 // implementation.
175 return new URLStreamHandlerFactory() { 175 return new URLStreamHandlerFactory() {
176 @Override 176 @Override
177 public URLStreamHandler createURLStreamHandler(String protocol) { 177 public URLStreamHandler createURLStreamHandler(String protocol) {
178 return null; 178 return null;
179 } 179 }
180 }; 180 };
181 } 181 }
182 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698