OLD | NEW |
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; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.support.annotation.IntDef; | 8 import android.support.annotation.IntDef; |
9 import android.util.Log; | 9 import android.util.Log; |
10 | 10 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 mConfig = new JSONObject(); | 46 mConfig = new JSONObject(); |
47 mContext = context; | 47 mContext = context; |
48 enableLegacyMode(false); | 48 enableLegacyMode(false); |
49 enableQUIC(false); | 49 enableQUIC(false); |
50 enableHTTP2(true); | 50 enableHTTP2(true); |
51 enableSDCH(false); | 51 enableSDCH(false); |
52 enableHttpCache(HTTP_CACHE_DISABLED, 0); | 52 enableHttpCache(HTTP_CACHE_DISABLED, 0); |
53 } | 53 } |
54 | 54 |
55 /** | 55 /** |
56 * Creates a config from a JSON string, which was serialized using | |
57 * {@link #toString}. | |
58 * | |
59 * @param context Android {@link Context} for engine to use. | |
60 * @param json JSON string of configuration parameters, which was | |
61 * serialized using {@link #toString}. | |
62 */ | |
63 public Builder(Context context, String json) throws JSONException { | |
64 mConfig = new JSONObject(json); | |
65 mContext = context; | |
66 } | |
67 | |
68 /** | |
69 * Constructs a User-Agent string including Cronet version, and | 56 * Constructs a User-Agent string including Cronet version, and |
70 * application name and version. | 57 * application name and version. |
71 * | 58 * |
72 * @return User-Agent string. | 59 * @return User-Agent string. |
73 */ | 60 */ |
74 public String getDefaultUserAgent() { | 61 public String getDefaultUserAgent() { |
75 return UserAgent.from(mContext); | 62 return UserAgent.from(mContext); |
76 } | 63 } |
77 | 64 |
78 /** | 65 /** |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 314 |
328 /** | 315 /** |
329 * Sets a native MockCertVerifier for testing. | 316 * Sets a native MockCertVerifier for testing. |
330 */ | 317 */ |
331 Builder setMockCertVerifierForTesting(long mockCertVerifier) { | 318 Builder setMockCertVerifierForTesting(long mockCertVerifier) { |
332 return putString( | 319 return putString( |
333 CronetEngineBuilderList.MOCK_CERT_VERIFIER, String.valueOf(m
ockCertVerifier)); | 320 CronetEngineBuilderList.MOCK_CERT_VERIFIER, String.valueOf(m
ockCertVerifier)); |
334 } | 321 } |
335 | 322 |
336 /** | 323 /** |
337 * Get JSON string representation of the builder. | 324 * Gets a JSON string representation of the builder. |
338 */ | 325 */ |
339 @Override | 326 String toJSONString() { |
340 public String toString() { | |
341 return mConfig.toString(); | 327 return mConfig.toString(); |
342 } | 328 } |
343 | 329 |
344 /** | 330 /** |
345 * Returns {@link Context} for builder. | 331 * Returns {@link Context} for builder. |
346 * | 332 * |
347 * @return {@link Context} for builder. | 333 * @return {@link Context} for builder. |
348 */ | 334 */ |
349 Context getContext() { | 335 Context getContext() { |
350 return mContext; | 336 return mContext; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 cronetEngine = possibleEngine; | 661 cronetEngine = possibleEngine; |
676 } | 662 } |
677 } catch (ClassNotFoundException e) { | 663 } catch (ClassNotFoundException e) { |
678 // Leave as null. | 664 // Leave as null. |
679 } catch (Exception e) { | 665 } catch (Exception e) { |
680 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_
REQUEST_CONTEXT, e); | 666 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_
REQUEST_CONTEXT, e); |
681 } | 667 } |
682 return cronetEngine; | 668 return cronetEngine; |
683 } | 669 } |
684 } | 670 } |
OLD | NEW |