diff --git a/Parse/src/main/java/com/parse/Parse.java b/Parse/src/main/java/com/parse/Parse.java index 62fd165d5..d8ef78db5 100644 --- a/Parse/src/main/java/com/parse/Parse.java +++ b/Parse/src/main/java/com/parse/Parse.java @@ -193,7 +193,6 @@ public static void initialize(Context context, String applicationId, String clie ParseHttpClient.setKeepAlive(true); ParseHttpClient.setMaxConnections(20); - ParseRequest.setDefaultClient(ParsePlugins.get().restClient()); // If we have interceptors in list, we have to initialize all http clients and add interceptors if (interceptors != null) { initializeParseHttpClientsWithParseNetworkInterceptors(); @@ -414,15 +413,16 @@ static void checkCacheApplicationId() { || (isLocalDatastoreEnabled && eventuallyQueue instanceof ParseCommandCache) || (!isLocalDatastoreEnabled && eventuallyQueue instanceof ParsePinningEventuallyQueue)) { checkContext(); + ParseHttpClient httpClient = ParsePlugins.get().restClient(); eventuallyQueue = isLocalDatastoreEnabled - ? new ParsePinningEventuallyQueue(context) - : new ParseCommandCache(context); + ? new ParsePinningEventuallyQueue(context, httpClient) + : new ParseCommandCache(context, httpClient); // We still need to clear out the old command cache even if we're using Pinning in case // anything is left over when the user upgraded. Checking number of pending and then // initializing should be enough. if (isLocalDatastoreEnabled && ParseCommandCache.getPendingCount() > 0) { - new ParseCommandCache(context); + new ParseCommandCache(context, httpClient); } } return eventuallyQueue; diff --git a/Parse/src/main/java/com/parse/ParseCommandCache.java b/Parse/src/main/java/com/parse/ParseCommandCache.java index 2ca798839..354d43fd8 100644 --- a/Parse/src/main/java/com/parse/ParseCommandCache.java +++ b/Parse/src/main/java/com/parse/ParseCommandCache.java @@ -90,6 +90,8 @@ public static int getPendingCount() { private Logger log; // Why is there a custom logger? To prevent Mockito deadlock! + private final ParseHttpClient httpClient; + ConnectivityNotifier notifier; ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() { @Override @@ -121,12 +123,14 @@ public Void call() throws Exception { } }; - public ParseCommandCache(Context context) { + public ParseCommandCache(Context context, ParseHttpClient client) { setConnected(false); + shouldStop = false; running = false; runningLock = new Object(); + httpClient = client; log = Logger.getLogger(TAG); @@ -526,7 +530,7 @@ private void maybeRunAllCommandsNow(int retriesRemaining) { } notifyTestHelper(TestHelper.COMMAND_OLD_FORMAT_DISCARDED); } else { - commandTask = command.executeAsync().continueWithTask(new Continuation>() { + commandTask = command.executeAsync(httpClient).continueWithTask(new Continuation>() { @Override public Task then(Task task) throws Exception { String localId = command.getLocalId(); diff --git a/Parse/src/main/java/com/parse/ParseObject.java b/Parse/src/main/java/com/parse/ParseObject.java index 6da443aa8..0ca102c0a 100644 --- a/Parse/src/main/java/com/parse/ParseObject.java +++ b/Parse/src/main/java/com/parse/ParseObject.java @@ -1660,11 +1660,13 @@ public Task then(Task task) throws Exception { // Currently only used by ParsePinningEventuallyQueue for saveEventually due to the limitation in // ParseCommandCache that it can only return JSONObject result. - /* package */ Task saveAsync(final ParseOperationSet operationSet, String sessionToken) - throws ParseException { + /* package */ Task saveAsync( + ParseHttpClient client, + final ParseOperationSet operationSet, + String sessionToken) throws ParseException { final ParseRESTCommand command = currentSaveEventuallyCommand(operationSet, PointerEncoder.get(), sessionToken); - return command.executeAsync(); + return command.executeAsync(client); } /** diff --git a/Parse/src/main/java/com/parse/ParsePinningEventuallyQueue.java b/Parse/src/main/java/com/parse/ParsePinningEventuallyQueue.java index 956f527af..d6bc90d74 100644 --- a/Parse/src/main/java/com/parse/ParsePinningEventuallyQueue.java +++ b/Parse/src/main/java/com/parse/ParsePinningEventuallyQueue.java @@ -69,6 +69,7 @@ */ private Task.TaskCompletionSource connectionTaskCompletionSource = Task.create(); private final Object connectionLock = new Object(); + private final ParseHttpClient httpClient; private ConnectivityNotifier notifier; private ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() { @@ -84,9 +85,11 @@ public void networkConnectivityStatusChanged(Context context, Intent intent) { } }; - public ParsePinningEventuallyQueue(Context context) { + public ParsePinningEventuallyQueue(Context context, ParseHttpClient client) { setConnected(ConnectivityNotifier.isConnected(context)); + httpClient = client; + notifier = ConnectivityNotifier.getNotifier(context); notifier.addListener(listener); @@ -492,7 +495,7 @@ public Task then(Task task) throws Exception { Task executeTask; if (type == EventuallyPin.TYPE_SAVE) { - executeTask = object.saveAsync(operationSet, sessionToken); + executeTask = object.saveAsync(httpClient, operationSet, sessionToken); } else if (type == EventuallyPin.TYPE_DELETE) { executeTask = object.deleteAsync(sessionToken).cast(); } else { // else if (type == EventuallyPin.TYPE_COMMAND) { @@ -501,7 +504,7 @@ public Task then(Task task) throws Exception { executeTask = Task.forResult(null); notifyTestHelper(TestHelper.COMMAND_OLD_FORMAT_DISCARDED); } else { - executeTask = command.executeAsync(); + executeTask = command.executeAsync(httpClient); } } diff --git a/Parse/src/main/java/com/parse/ParseRequest.java b/Parse/src/main/java/com/parse/ParseRequest.java index b1fef304b..68bf5e4af 100644 --- a/Parse/src/main/java/com/parse/ParseRequest.java +++ b/Parse/src/main/java/com/parse/ParseRequest.java @@ -70,21 +70,6 @@ private static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int ma private static long defaultInitialRetryDelay = DEFAULT_INITIAL_RETRY_DELAY; - // TODO(grantland): Remove once we're able to inject a http client into all of our controllers - // and we don't need this for mocking anymore. - private static ParseHttpClient defaultClient = null; - @Deprecated - public static void setDefaultClient(ParseHttpClient client) { - defaultClient = client; - } - @Deprecated - public static ParseHttpClient getDefaultClient() { - if (defaultClient == null) { - throw new IllegalStateException("Can't send Parse HTTPS request before Parse.initialize()"); - } - return defaultClient; - } - public static void setDefaultInitialRetryDelay(long delay) { defaultInitialRetryDelay = delay; } @@ -167,23 +152,6 @@ public Task then(Task task) throws Exception { protected abstract Task onResponseAsync(ParseHttpResponse response, ProgressCallback downloadProgressCallback); - @Deprecated - public Task executeAsync() { - return executeAsync(getDefaultClient()); - } - - @Deprecated - public Task executeAsync( - ProgressCallback uploadProgressCallback, - ProgressCallback downloadProgressCallback, - Task cancellationToken) { - return executeAsync( - getDefaultClient(), - uploadProgressCallback, - downloadProgressCallback, - cancellationToken); - } - /* * Starts retrying the block. */