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

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

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Rebase & Conflict Resolution Created 4 years, 1 month 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; 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;
11 import org.chromium.net.EffectiveConnectionType;
12 import org.chromium.net.ExperimentalBidirectionalStream;
13 import org.chromium.net.NetworkQualityRttListener;
14 import org.chromium.net.NetworkQualityThroughputListener;
15 import org.chromium.net.RequestFinishedInfo;
16 import org.chromium.net.RttThroughputValues;
17 import org.chromium.net.UrlRequest;
18
10 import java.io.IOException; 19 import java.io.IOException;
11 import java.net.Proxy; 20 import java.net.Proxy;
12 import java.net.URL; 21 import java.net.URL;
13 import java.net.URLConnection; 22 import java.net.URLConnection;
14 import java.net.URLStreamHandler; 23 import java.net.URLStreamHandler;
15 import java.net.URLStreamHandlerFactory; 24 import java.net.URLStreamHandlerFactory;
16 import java.util.Collection; 25 import java.util.Collection;
17 import java.util.List; 26 import java.util.List;
18 import java.util.Map; 27 import java.util.Map;
19 import java.util.concurrent.Executor; 28 import java.util.concurrent.Executor;
20 import java.util.concurrent.ExecutorService; 29 import java.util.concurrent.ExecutorService;
21 import java.util.concurrent.Executors; 30 import java.util.concurrent.Executors;
22 import java.util.concurrent.ThreadFactory; 31 import java.util.concurrent.ThreadFactory;
23 32
24 /** 33 /**
25 * {@link java.net.HttpURLConnection} backed CronetEngine. 34 * {@link java.net.HttpURLConnection} backed CronetEngine.
26 * 35 *
27 * <p>Does not support netlogs, transferred data measurement, bidistream, cache, or priority. 36 * <p>Does not support netlogs, transferred data measurement, bidistream, cache, or priority.
28 */ 37 */
29 final class JavaCronetEngine extends CronetEngine { 38 public final class JavaCronetEngine extends CronetEngineBase {
30 private final String mUserAgent; 39 private final String mUserAgent;
31 40
32 private final ExecutorService mExecutorService = 41 private final ExecutorService mExecutorService =
33 Executors.newCachedThreadPool(new ThreadFactory() { 42 Executors.newCachedThreadPool(new ThreadFactory() {
34 @Override 43 @Override
35 public Thread newThread(final Runnable r) { 44 public Thread newThread(final Runnable r) {
36 return Executors.defaultThreadFactory().newThread(new Runnab le() { 45 return Executors.defaultThreadFactory().newThread(new Runnab le() {
37 @Override 46 @Override
38 public void run() { 47 public void run() {
39 Thread.currentThread().setName("JavaCronetEngine"); 48 Thread.currentThread().setName("JavaCronetEngine");
40 // On android, all background threads (and all threa ds that are part 49 // On android, all background threads (and all threa ds that are part
41 // of background processes) are put in a cgroup that is allowed to 50 // of background processes) are put in a cgroup that is allowed to
42 // consume up to 5% of CPU - these worker threads sp end the vast 51 // consume up to 5% of CPU - these worker threads sp end the vast
43 // majority of their time waiting on I/O, so making them contend with 52 // majority of their time waiting on I/O, so making them contend with
44 // background applications for a slice of CPU doesn' t make much sense. 53 // background applications for a slice of CPU doesn' t make much sense.
45 // We want to hurry up and get idle. 54 // We want to hurry up and get idle.
46 android.os.Process.setThreadPriority( 55 android.os.Process.setThreadPriority(
47 THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY _MORE_FAVORABLE); 56 THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY _MORE_FAVORABLE);
48 r.run(); 57 r.run();
49 } 58 }
50 }); 59 });
51 } 60 }
52 }); 61 });
53 62
54 JavaCronetEngine(String userAgent) { 63 public JavaCronetEngine(String userAgent) {
55 this.mUserAgent = userAgent; 64 this.mUserAgent = userAgent;
56 } 65 }
57 66
58 @Override 67 @Override
59 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex ecutor executor, 68 public UrlRequestBase createRequest(String url, UrlRequest.Callback callback , Executor executor,
60 int priority, Collection<Object> connectionAnnotations, boolean disa bleCache, 69 int priority, Collection<Object> connectionAnnotations, boolean disa bleCache,
61 boolean disableConnectionMigration, boolean allowDirectExecutor) { 70 boolean disableConnectionMigration, boolean allowDirectExecutor) {
62 return new JavaUrlRequest( 71 return new JavaUrlRequest(
63 callback, mExecutorService, executor, url, mUserAgent, allowDire ctExecutor); 72 callback, mExecutorService, executor, url, mUserAgent, allowDire ctExecutor);
64 } 73 }
65 74
66 @Override 75 @Override
67 public BidirectionalStream createBidirectionalStream(String url, 76 protected ExperimentalBidirectionalStream createBidirectionalStream(String u rl,
68 BidirectionalStream.Callback callback, Executor executor, String htt pMethod, 77 BidirectionalStream.Callback callback, Executor executor, String htt pMethod,
69 List<Map.Entry<String, String>> requestHeaders, 78 List<Map.Entry<String, String>> requestHeaders, @StreamPriority int priority,
70 @BidirectionalStream.Builder.StreamPriority int priority,
71 boolean delayRequestHeadersUntilFirstFlush, Collection<Object> conne ctionAnnotations) { 79 boolean delayRequestHeadersUntilFirstFlush, Collection<Object> conne ctionAnnotations) {
72 throw new UnsupportedOperationException( 80 throw new UnsupportedOperationException(
73 "Can't create a bidi stream - httpurlconnection doesn't have tho se APIs"); 81 "Can't create a bidi stream - httpurlconnection doesn't have tho se APIs");
74 } 82 }
75 83
76 @Override 84 @Override
77 public boolean isEnabled() { 85 public ExperimentalBidirectionalStream.Builder newBidirectionalStreamBuilder (
78 return true; 86 String url, BidirectionalStream.Callback callback, Executor executor ) {
87 throw new UnsupportedOperationException(
88 "The bidirectional stream API is not supported by the Java imple mentation "
89 + "of Cronet Engine");
79 } 90 }
80 91
81 @Override 92 @Override
82 public String getVersionString() { 93 public String getVersionString() {
83 return "CronetHttpURLConnection/" + ApiVersion.getVersion(); 94 return "CronetHttpURLConnection/" + ImplVersion.getVersion();
84 } 95 }
85 96
86 @Override 97 @Override
87 public void shutdown() { 98 public void shutdown() {
88 mExecutorService.shutdown(); 99 mExecutorService.shutdown();
89 } 100 }
90 101
91 @Override 102 @Override
92 public void startNetLogToFile(String fileName, boolean logAll) {} 103 public void startNetLogToFile(String fileName, boolean logAll) {}
93 104
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // Returning null causes this factory to pass though, which ends up usin g the platform's 175 // Returning null causes this factory to pass though, which ends up usin g the platform's
165 // implementation. 176 // implementation.
166 return new URLStreamHandlerFactory() { 177 return new URLStreamHandlerFactory() {
167 @Override 178 @Override
168 public URLStreamHandler createURLStreamHandler(String protocol) { 179 public URLStreamHandler createURLStreamHandler(String protocol) {
169 return null; 180 return null;
170 } 181 }
171 }; 182 };
172 } 183 }
173 } 184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698