mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 993885 - Refactor SendTabActivity to avoid a race condition. r=mcomella
This commit is contained in:
parent
a76b73760e
commit
038b77bb5f
@ -146,8 +146,7 @@ public class SendTabActivity extends LocaleAwareActivity {
|
||||
|
||||
enableSend(false);
|
||||
|
||||
// will enableSend if appropriate.
|
||||
updateClientList();
|
||||
// Sending will be enabled in onResume, if appropriate.
|
||||
}
|
||||
|
||||
protected static SendTabData getSendTabData(Intent intent) throws IllegalArgumentException {
|
||||
@ -184,14 +183,14 @@ public class SendTabActivity extends LocaleAwareActivity {
|
||||
* Ensure that the view's list of clients is backed by a recently populated
|
||||
* array adapter.
|
||||
*/
|
||||
protected synchronized void updateClientList() {
|
||||
protected synchronized void updateClientList(final TabSender sender, final ClientRecordArrayAdapter adapter) {
|
||||
// Fetching the client list hits the clients database, so we spin this onto
|
||||
// a background task.
|
||||
new AsyncTask<Void, Void, Collection<ClientRecord>>() {
|
||||
|
||||
@Override
|
||||
protected Collection<ClientRecord> doInBackground(Void... params) {
|
||||
return getOtherClients();
|
||||
return getOtherClients(sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -199,12 +198,12 @@ public class SendTabActivity extends LocaleAwareActivity {
|
||||
// We're allowed to update the UI from here.
|
||||
|
||||
Logger.debug(LOG_TAG, "Got " + clientArray.size() + " clients.");
|
||||
arrayAdapter.setClientRecordList(clientArray);
|
||||
adapter.setClientRecordList(clientArray);
|
||||
if (clientArray.size() == 1) {
|
||||
arrayAdapter.checkItem(0, true);
|
||||
adapter.checkItem(0, true);
|
||||
}
|
||||
|
||||
enableSend(arrayAdapter.getNumCheckedGUIDs() > 0);
|
||||
enableSend(adapter.getNumCheckedGUIDs() > 0);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
@ -235,6 +234,9 @@ public class SendTabActivity extends LocaleAwareActivity {
|
||||
|
||||
this.tabSender = new FxAccountTabSender(applicationContext, fxAccount);
|
||||
|
||||
// will enableSend if appropriate.
|
||||
updateClientList(tabSender, this.arrayAdapter);
|
||||
|
||||
Logger.info(LOG_TAG, "Allowing tab send for Firefox Account.");
|
||||
registerDisplayURICommand();
|
||||
return;
|
||||
@ -244,6 +246,9 @@ public class SendTabActivity extends LocaleAwareActivity {
|
||||
if (syncAccounts.length > 0) {
|
||||
this.tabSender = new Sync11TabSender(applicationContext, syncAccounts[0], accountManager);
|
||||
|
||||
// will enableSend if appropriate.
|
||||
updateClientList(tabSender, this.arrayAdapter);
|
||||
|
||||
Logger.info(LOG_TAG, "Allowing tab send for Sync account.");
|
||||
registerDisplayURICommand();
|
||||
return;
|
||||
@ -360,18 +365,18 @@ public class SendTabActivity extends LocaleAwareActivity {
|
||||
/**
|
||||
* @return a collection of client records, excluding our own.
|
||||
*/
|
||||
protected Collection<ClientRecord> getOtherClients() {
|
||||
protected Collection<ClientRecord> getOtherClients(final TabSender sender) {
|
||||
if (sender == null) {
|
||||
Logger.warn(LOG_TAG, "No tab sender when fetching other client IDs.");
|
||||
return new ArrayList<ClientRecord>(0);
|
||||
}
|
||||
|
||||
final Map<String, ClientRecord> all = getAllClients();
|
||||
if (all == null) {
|
||||
return new ArrayList<ClientRecord>(0);
|
||||
}
|
||||
|
||||
if (this.tabSender == null) {
|
||||
Logger.warn(LOG_TAG, "No tab sender when fetching other client IDs.");
|
||||
return new ArrayList<ClientRecord>(0);
|
||||
}
|
||||
|
||||
final String ourGUID = this.tabSender.getAccountGUID();
|
||||
final String ourGUID = sender.getAccountGUID();
|
||||
if (ourGUID == null) {
|
||||
return all.values();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user