Skip to content

Commit 1d917d5

Browse files
Shy-Yauer Lingrantland
Shy-Yauer Lin
authored andcommitted
Remove ParseRequest defaultClient
We do not need defaultClient as a global state in class ParseRequest anymore.
1 parent 350eece commit 1d917d5

File tree

5 files changed

+21
-44
lines changed

5 files changed

+21
-44
lines changed

Parse/src/main/java/com/parse/Parse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ public static void initialize(Context context, String applicationId, String clie
193193

194194
ParseHttpClient.setKeepAlive(true);
195195
ParseHttpClient.setMaxConnections(20);
196-
ParseRequest.setDefaultClient(ParsePlugins.get().restClient());
197196
// If we have interceptors in list, we have to initialize all http clients and add interceptors
198197
if (interceptors != null) {
199198
initializeParseHttpClientsWithParseNetworkInterceptors();
@@ -414,15 +413,16 @@ static void checkCacheApplicationId() {
414413
|| (isLocalDatastoreEnabled && eventuallyQueue instanceof ParseCommandCache)
415414
|| (!isLocalDatastoreEnabled && eventuallyQueue instanceof ParsePinningEventuallyQueue)) {
416415
checkContext();
416+
ParseHttpClient httpClient = ParsePlugins.get().restClient();
417417
eventuallyQueue = isLocalDatastoreEnabled
418-
? new ParsePinningEventuallyQueue(context)
419-
: new ParseCommandCache(context);
418+
? new ParsePinningEventuallyQueue(context, httpClient)
419+
: new ParseCommandCache(context, httpClient);
420420

421421
// We still need to clear out the old command cache even if we're using Pinning in case
422422
// anything is left over when the user upgraded. Checking number of pending and then
423423
// initializing should be enough.
424424
if (isLocalDatastoreEnabled && ParseCommandCache.getPendingCount() > 0) {
425-
new ParseCommandCache(context);
425+
new ParseCommandCache(context, httpClient);
426426
}
427427
}
428428
return eventuallyQueue;

Parse/src/main/java/com/parse/ParseCommandCache.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public static int getPendingCount() {
9090

9191
private Logger log; // Why is there a custom logger? To prevent Mockito deadlock!
9292

93+
private final ParseHttpClient httpClient;
94+
9395
ConnectivityNotifier notifier;
9496
ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() {
9597
@Override
@@ -121,12 +123,14 @@ public Void call() throws Exception {
121123
}
122124
};
123125

124-
public ParseCommandCache(Context context) {
126+
public ParseCommandCache(Context context, ParseHttpClient client) {
125127
setConnected(false);
128+
126129
shouldStop = false;
127130
running = false;
128131

129132
runningLock = new Object();
133+
httpClient = client;
130134

131135
log = Logger.getLogger(TAG);
132136

@@ -526,7 +530,7 @@ private void maybeRunAllCommandsNow(int retriesRemaining) {
526530
}
527531
notifyTestHelper(TestHelper.COMMAND_OLD_FORMAT_DISCARDED);
528532
} else {
529-
commandTask = command.executeAsync().continueWithTask(new Continuation<JSONObject, Task<JSONObject>>() {
533+
commandTask = command.executeAsync(httpClient).continueWithTask(new Continuation<JSONObject, Task<JSONObject>>() {
530534
@Override
531535
public Task<JSONObject> then(Task<JSONObject> task) throws Exception {
532536
String localId = command.getLocalId();

Parse/src/main/java/com/parse/ParseObject.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,11 +1660,13 @@ public Task<Void> then(Task<Void> task) throws Exception {
16601660

16611661
// Currently only used by ParsePinningEventuallyQueue for saveEventually due to the limitation in
16621662
// ParseCommandCache that it can only return JSONObject result.
1663-
/* package */ Task<JSONObject> saveAsync(final ParseOperationSet operationSet, String sessionToken)
1664-
throws ParseException {
1663+
/* package */ Task<JSONObject> saveAsync(
1664+
ParseHttpClient client,
1665+
final ParseOperationSet operationSet,
1666+
String sessionToken) throws ParseException {
16651667
final ParseRESTCommand command =
16661668
currentSaveEventuallyCommand(operationSet, PointerEncoder.get(), sessionToken);
1667-
return command.executeAsync();
1669+
return command.executeAsync(client);
16681670
}
16691671

16701672
/**

Parse/src/main/java/com/parse/ParsePinningEventuallyQueue.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
*/
7070
private Task<Void>.TaskCompletionSource connectionTaskCompletionSource = Task.create();
7171
private final Object connectionLock = new Object();
72+
private final ParseHttpClient httpClient;
7273

7374
private ConnectivityNotifier notifier;
7475
private ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() {
@@ -84,9 +85,11 @@ public void networkConnectivityStatusChanged(Context context, Intent intent) {
8485
}
8586
};
8687

87-
public ParsePinningEventuallyQueue(Context context) {
88+
public ParsePinningEventuallyQueue(Context context, ParseHttpClient client) {
8889
setConnected(ConnectivityNotifier.isConnected(context));
8990

91+
httpClient = client;
92+
9093
notifier = ConnectivityNotifier.getNotifier(context);
9194
notifier.addListener(listener);
9295

@@ -492,7 +495,7 @@ public Task<JSONObject> then(Task<Void> task) throws Exception {
492495

493496
Task<JSONObject> executeTask;
494497
if (type == EventuallyPin.TYPE_SAVE) {
495-
executeTask = object.saveAsync(operationSet, sessionToken);
498+
executeTask = object.saveAsync(httpClient, operationSet, sessionToken);
496499
} else if (type == EventuallyPin.TYPE_DELETE) {
497500
executeTask = object.deleteAsync(sessionToken).cast();
498501
} else { // else if (type == EventuallyPin.TYPE_COMMAND) {
@@ -501,7 +504,7 @@ public Task<JSONObject> then(Task<Void> task) throws Exception {
501504
executeTask = Task.forResult(null);
502505
notifyTestHelper(TestHelper.COMMAND_OLD_FORMAT_DISCARDED);
503506
} else {
504-
executeTask = command.executeAsync();
507+
executeTask = command.executeAsync(httpClient);
505508
}
506509
}
507510

Parse/src/main/java/com/parse/ParseRequest.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,6 @@ private static ThreadPoolExecutor newThreadPoolExecutor(int corePoolSize, int ma
7070

7171
private static long defaultInitialRetryDelay = DEFAULT_INITIAL_RETRY_DELAY;
7272

73-
// TODO(grantland): Remove once we're able to inject a http client into all of our controllers
74-
// and we don't need this for mocking anymore.
75-
private static ParseHttpClient defaultClient = null;
76-
@Deprecated
77-
public static void setDefaultClient(ParseHttpClient client) {
78-
defaultClient = client;
79-
}
80-
@Deprecated
81-
public static ParseHttpClient getDefaultClient() {
82-
if (defaultClient == null) {
83-
throw new IllegalStateException("Can't send Parse HTTPS request before Parse.initialize()");
84-
}
85-
return defaultClient;
86-
}
87-
8873
public static void setDefaultInitialRetryDelay(long delay) {
8974
defaultInitialRetryDelay = delay;
9075
}
@@ -167,23 +152,6 @@ public Task<Response> then(Task<Response> task) throws Exception {
167152
protected abstract Task<Response> onResponseAsync(ParseHttpResponse response,
168153
ProgressCallback downloadProgressCallback);
169154

170-
@Deprecated
171-
public Task<Response> executeAsync() {
172-
return executeAsync(getDefaultClient());
173-
}
174-
175-
@Deprecated
176-
public Task<Response> executeAsync(
177-
ProgressCallback uploadProgressCallback,
178-
ProgressCallback downloadProgressCallback,
179-
Task<Void> cancellationToken) {
180-
return executeAsync(
181-
getDefaultClient(),
182-
uploadProgressCallback,
183-
downloadProgressCallback,
184-
cancellationToken);
185-
}
186-
187155
/*
188156
* Starts retrying the block.
189157
*/

0 commit comments

Comments
 (0)