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

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

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Rebased onto Charles change + Paul's Comments Created 4 years, 3 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; 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.ApiVersion;
11 import org.chromium.net.BidirectionalStream;
12 import org.chromium.net.EffectiveConnectionType;
13 import org.chromium.net.ExperimentalBidirectionalStream;
14 import org.chromium.net.NetworkQualityRttListener;
15 import org.chromium.net.NetworkQualityThroughputListener;
16 import org.chromium.net.RequestFinishedInfo;
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 {
pauljensen 2016/09/26 14:51:22 why public?
kapishnikov 2016/09/27 18:38:26 We are referencing it from the tests that are in a
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 public BidirectionalStream createBidirectionalStream(String url,
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,
70 @BidirectionalStream.Builder.StreamPriority int priority, 79 @BidirectionalStreamBuilderImpl.StreamPriority int priority,
71 boolean delayRequestHeadersUntilFirstFlush, Collection<Object> conne ctionAnnotations) { 80 boolean delayRequestHeadersUntilFirstFlush, Collection<Object> conne ctionAnnotations) {
72 throw new UnsupportedOperationException( 81 throw new UnsupportedOperationException(
73 "Can't create a bidi stream - httpurlconnection doesn't have tho se APIs"); 82 "Can't create a bidi stream - httpurlconnection doesn't have tho se APIs");
74 } 83 }
75 84
76 @Override 85 @Override
86 public ExperimentalBidirectionalStream.Builder newBidirectionalStreamBuilder (
87 String url, BidirectionalStream.Callback callback, Executor executor ) {
88 throw new UnsupportedOperationException(
89 "The bidirectional stream is not supported by the Java implement ation "
pauljensen 2016/09/26 14:51:22 stream->stream API
kapishnikov 2016/09/27 18:38:26 Done.
90 + "of Cronet Engine");
91 }
92
93 @Override
77 public boolean isEnabled() { 94 public boolean isEnabled() {
78 return true; 95 return true;
79 } 96 }
80 97
81 @Override 98 @Override
82 public String getVersionString() { 99 public String getVersionString() {
83 return "CronetHttpURLConnection/" + ApiVersion.getVersion(); 100 return "CronetHttpURLConnection/" + ApiVersion.getVersion();
84 } 101 }
85 102
86 @Override 103 @Override
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Returning null causes this factory to pass though, which ends up usin g the platform's 166 // Returning null causes this factory to pass though, which ends up usin g the platform's
150 // implementation. 167 // implementation.
151 return new URLStreamHandlerFactory() { 168 return new URLStreamHandlerFactory() {
152 @Override 169 @Override
153 public URLStreamHandler createURLStreamHandler(String protocol) { 170 public URLStreamHandler createURLStreamHandler(String protocol) {
154 return null; 171 return null;
155 } 172 }
156 }; 173 };
157 } 174 }
158 } 175 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698