| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 | |
| 9 import java.lang.reflect.Constructor; | |
| 10 | |
| 11 /** | |
| 12 * Replaceable class providing ability to load Cronet implementation. | |
| 13 */ | |
| 14 final class ImplLoader { | |
| 15 // The class name of the Cronet Engine Builder implementation. | |
| 16 private static final String CRONET_ENGINE_BUILDER_IMPL = | |
| 17 "org.chromium.net.impl.CronetEngineBuilderImpl"; | |
| 18 | |
| 19 /** | |
| 20 * Load implementation of {@link ICronetEngineBuilder}. | |
| 21 * @param context Android {@link Context} to use for loading. | |
| 22 * @return {@link ICronetEngineBuilder} implementation. | |
| 23 */ | |
| 24 static ICronetEngineBuilder load(Context context) { | |
| 25 try { | |
| 26 Class<? extends ICronetEngineBuilder> delegateImplClass = | |
| 27 Class.forName(CRONET_ENGINE_BUILDER_IMPL) | |
| 28 .asSubclass(ICronetEngineBuilder.class); | |
| 29 Constructor<? extends ICronetEngineBuilder> ctor = | |
| 30 delegateImplClass.getConstructor(Context.class); | |
| 31 return ctor.newInstance(context); | |
| 32 } catch (Exception e) { | |
| 33 throw new RuntimeException( | |
| 34 "Unable to construct the implementation of the Cronet Engine
Builder: " | |
| 35 + CRONET_ENGINE_BUILDER_IMPL, | |
| 36 e); | |
| 37 } | |
| 38 } | |
| 39 } | |
| OLD | NEW |