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

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

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Javadoc + rebase 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.NetworkQualityRttListener;
14 import org.chromium.net.NetworkQualityThroughputListener;
15 import org.chromium.net.RequestFinishedInfo;
16 import org.chromium.net.UrlRequest;
17
10 import java.io.IOException; 18 import java.io.IOException;
11 import java.net.Proxy; 19 import java.net.Proxy;
12 import java.net.URL; 20 import java.net.URL;
13 import java.net.URLConnection; 21 import java.net.URLConnection;
14 import java.net.URLStreamHandler; 22 import java.net.URLStreamHandler;
15 import java.net.URLStreamHandlerFactory; 23 import java.net.URLStreamHandlerFactory;
16 import java.util.Collection; 24 import java.util.Collection;
17 import java.util.List; 25 import java.util.List;
18 import java.util.Map; 26 import java.util.Map;
19 import java.util.concurrent.Executor; 27 import java.util.concurrent.Executor;
20 import java.util.concurrent.ExecutorService; 28 import java.util.concurrent.ExecutorService;
21 import java.util.concurrent.Executors; 29 import java.util.concurrent.Executors;
22 import java.util.concurrent.ThreadFactory; 30 import java.util.concurrent.ThreadFactory;
23 31
24 /** 32 /**
25 * {@link java.net.HttpURLConnection} backed CronetEngine. 33 * {@link java.net.HttpURLConnection} backed CronetEngine.
26 * 34 *
27 * <p>Does not support netlogs, transferred data measurement, bidistream, cache, or priority. 35 * <p>Does not support netlogs, transferred data measurement, bidistream, cache, or priority.
28 */ 36 */
29 final class JavaCronetEngine extends CronetEngine { 37 public final class JavaCronetEngine extends CronetEngineBase {
30 private final String mUserAgent; 38 private final String mUserAgent;
31 39
32 private final ExecutorService mExecutorService = 40 private final ExecutorService mExecutorService =
33 Executors.newCachedThreadPool(new ThreadFactory() { 41 Executors.newCachedThreadPool(new ThreadFactory() {
34 @Override 42 @Override
35 public Thread newThread(final Runnable r) { 43 public Thread newThread(final Runnable r) {
36 return Executors.defaultThreadFactory().newThread(new Runnab le() { 44 return Executors.defaultThreadFactory().newThread(new Runnab le() {
37 @Override 45 @Override
38 public void run() { 46 public void run() {
39 Thread.currentThread().setName("JavaCronetEngine"); 47 Thread.currentThread().setName("JavaCronetEngine");
40 // On android, all background threads (and all threa ds that are part 48 // 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 49 // 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 50 // 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 51 // 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. 52 // background applications for a slice of CPU doesn' t make much sense.
45 // We want to hurry up and get idle. 53 // We want to hurry up and get idle.
46 android.os.Process.setThreadPriority( 54 android.os.Process.setThreadPriority(
47 THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY _MORE_FAVORABLE); 55 THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY _MORE_FAVORABLE);
48 r.run(); 56 r.run();
49 } 57 }
50 }); 58 });
51 } 59 }
52 }); 60 });
53 61
54 JavaCronetEngine(String userAgent) { 62 public JavaCronetEngine(String userAgent) {
55 this.mUserAgent = userAgent; 63 this.mUserAgent = userAgent;
56 } 64 }
57 65
58 @Override 66 @Override
59 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex ecutor executor, 67 public UrlRequestBase createRequest(String url, UrlRequest.Callback callback , Executor executor,
60 int priority, Collection<Object> connectionAnnotations, boolean disa bleCache, 68 int priority, Collection<Object> connectionAnnotations, boolean disa bleCache,
61 boolean disableConnectionMigration, boolean allowDirectExecutor) { 69 boolean disableConnectionMigration, boolean allowDirectExecutor) {
62 return new JavaUrlRequest( 70 return new JavaUrlRequest(
63 callback, mExecutorService, executor, url, mUserAgent, allowDire ctExecutor); 71 callback, mExecutorService, executor, url, mUserAgent, allowDire ctExecutor);
64 } 72 }
65 73
66 @Override 74 @Override
67 public BidirectionalStream createBidirectionalStream(String url, 75 public BidirectionalStream createBidirectionalStream(String url,
68 BidirectionalStream.Callback callback, Executor executor, String htt pMethod, 76 BidirectionalStream.Callback callback, Executor executor, String htt pMethod,
69 List<Map.Entry<String, String>> requestHeaders, 77 List<Map.Entry<String, String>> requestHeaders,
70 @BidirectionalStream.Builder.StreamPriority int priority, 78 @BidirectionalStreamBuilderImpl.StreamPriority int priority,
71 boolean delayRequestHeadersUntilFirstFlush) { 79 boolean delayRequestHeadersUntilFirstFlush) {
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
85 public BidirectionalStream.Builder newBidirectionalStreamBuilder(
86 String url, BidirectionalStream.Callback callback, Executor executor ) {
87 throw new UnsupportedOperationException(
88 "The bidirectional stream is not supported by the Java implement ation "
89 + "of Cronet Engine");
90 }
91
92 @Override
77 public boolean isEnabled() { 93 public boolean isEnabled() {
78 return true; 94 return true;
79 } 95 }
80 96
81 @Override 97 @Override
82 public String getVersionString() { 98 public String getVersionString() {
83 return "CronetHttpURLConnection/" + ApiVersion.getVersion(); 99 return "CronetHttpURLConnection/" + ApiVersion.getVersion();
84 } 100 }
85 101
86 @Override 102 @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 165 // Returning null causes this factory to pass though, which ends up usin g the platform's
150 // implementation. 166 // implementation.
151 return new URLStreamHandlerFactory() { 167 return new URLStreamHandlerFactory() {
152 @Override 168 @Override
153 public URLStreamHandler createURLStreamHandler(String protocol) { 169 public URLStreamHandler createURLStreamHandler(String protocol) {
154 return null; 170 return null;
155 } 171 }
156 }; 172 };
157 } 173 }
158 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698