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

Side by Side Diff: components/cronet/android/api/src/org/chromium/net/HttpUrlRequestFactory.java

Issue 2339223002: Cronet API Refactoring (Closed)
Patch Set: Moved CronetSampleApp to AppCompat 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.net;
6
7 import android.content.Context;
8 import android.util.Log;
9
10 import java.lang.reflect.Constructor;
11 import java.nio.channels.WritableByteChannel;
12 import java.util.Map;
13
14 /**
15 * A factory for {@link HttpUrlRequest}'s, which uses the best HTTP stack
16 * available on the current platform.
17 * @deprecated Use {@link CronetEngine} instead.
18 * {@hide as it's deprecated}
19 */
20 @Deprecated
21 public abstract class HttpUrlRequestFactory {
22 private static final String TAG = "HttpUrlRequestFactory";
23
24 private static final String CHROMIUM_URL_REQUEST_FACTORY =
25 "org.chromium.net.impl.ChromiumUrlRequestFactory";
26
27 public static HttpUrlRequestFactory createFactory(
28 Context context, CronetEngine.Builder config) {
29 HttpUrlRequestFactory factory = null;
30 if (!config.legacyMode()) {
31 factory = createChromiumFactory(context, config);
32 }
33 if (factory == null) {
34 // Default to HttpUrlConnection-based networking.
35 factory = new HttpUrlConnectionUrlRequestFactory(context, config);
36 }
37 Log.i(TAG, "Using network stack: " + factory.getName());
38 return factory;
39 }
40
41 /**
42 * Returns true if the factory is enabled.
43 */
44 public abstract boolean isEnabled();
45
46 /**
47 * Returns a human-readable name of the factory.
48 */
49 public abstract String getName();
50
51 /**
52 * Creates a new request intended for full-response buffering.
53 */
54 public abstract HttpUrlRequest createRequest(String url,
55 int requestPriority, Map<String, String> headers,
56 HttpUrlRequestListener listener);
57
58 /**
59 * Creates a new request intended for streaming.
60 */
61 public abstract HttpUrlRequest createRequest(String url,
62 int requestPriority, Map<String, String> headers,
63 WritableByteChannel channel, HttpUrlRequestListener listener);
64
65 /**
66 * Starts NetLog logging to a file named |fileName| in the
67 * application temporary directory. |fileName| must not be empty. Log may
68 * contain user's personal information (PII). If the file exists it is
69 * truncated before starting. If actively logging the call is ignored.
70 * @param fileName The complete file path. It must not be empty. If file
71 * exists, it is truncated before starting.
72 * @param logAll {@code true} to also include all transferred bytes in the
73 * log.
74 */
75 public abstract void startNetLogToFile(String fileName, boolean logAll);
76
77 /**
78 * Stops NetLog logging and flushes file to disk. If a logging session is
79 * not in progress this call is ignored.
80 */
81 public abstract void stopNetLog();
82
83 private static HttpUrlRequestFactory createChromiumFactory(
84 Context context, CronetEngine.Builder config) {
85 HttpUrlRequestFactory factory = null;
86 try {
87 Class<? extends HttpUrlRequestFactory> factoryClass =
88 HttpUrlRequestFactory.class.getClassLoader()
89 .loadClass(CHROMIUM_URL_REQUEST_FACTORY)
90 .asSubclass(HttpUrlRequestFactory.class);
91 Constructor<? extends HttpUrlRequestFactory> constructor =
92 factoryClass.getConstructor(Context.class, CronetEngine.Buil der.class);
93 HttpUrlRequestFactory chromiumFactory =
94 constructor.newInstance(context, config);
95 if (chromiumFactory.isEnabled()) {
96 factory = chromiumFactory;
97 }
98 } catch (ClassNotFoundException e) {
99 // Leave as null
100 } catch (Exception e) {
101 throw new IllegalStateException(
102 "Cannot instantiate: " + CHROMIUM_URL_REQUEST_FACTORY,
103 e);
104 }
105 return factory;
106 }
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698