Bug 1251362 - Part 11 - Directly notify the RecentTabsAdapter when clearing history. r=liuche

Sessionstore.bak is only read when we are initialising the home panels, so after clearing all history from the button in the Combined History panel, the "Tabs from last time" section would still linger around until the home panels have been closed and reopened. To prevent this, we now directly notify the RecentTabsAdapter when all history has been deleted, so it can immediately clear its own copy of the last session's tabs.

MozReview-Commit-ID: 3EFY2WbWqzh

--HG--
extra : transplant_source : %C1%3FyzYZ%81F%5E%F9%98%FE%DC%B0%3F%0D%D3%18%7Bt
This commit is contained in:
Jan Henning 2016-05-14 21:27:23 +02:00
parent 6b24235a53
commit c442f23a2f
2 changed files with 29 additions and 0 deletions

View File

@ -415,6 +415,7 @@ public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsD
}
GeckoAppShell.notifyObservers("Sanitize:ClearData", json.toString());
mRecentTabsAdapter.clearLastSessionData();
Telemetry.sendUIEvent(TelemetryContract.Event.SANITIZE, TelemetryContract.Method.BUTTON, "history");
}
});

View File

@ -174,6 +174,34 @@ public class RecentTabsAdapter extends RecyclerView.Adapter<CombinedHistoryItem>
});
}
public void clearLastSessionData() {
final ClosedTab[] emptyLastSessionTabs = new ClosedTab[0];
// Only modify mLastSessionTabs on the UI thread.
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
// Save some data about the old panel state, so we can be
// smarter about notifying the recycler view which bits changed.
int prevClosedTabsCount = lastSessionTabs.length;
boolean prevSectionHeaderVisibility = isSectionHeaderVisible();
int prevSectionHeaderIndex = getSectionHeaderIndex();
lastSessionTabs = emptyLastSessionTabs;
recentTabsUpdateHandler.onRecentTabsCountUpdated(getClosedTabsCount());
panelStateUpdateHandler.onPanelStateUpdated();
// Handle the section header hiding.
updateHeaderVisibility(prevSectionHeaderVisibility, prevSectionHeaderIndex);
// Handle the "tabs from last time" being cleared.
if (prevClosedTabsCount > 0) {
notifyItemRangeRemoved(getFirstLastSessionTabIndex(), prevClosedTabsCount);
}
}
});
}
private void updateHeaderVisibility(boolean prevSectionHeaderVisibility, int prevSectionHeaderIndex) {
if (prevSectionHeaderVisibility && !isSectionHeaderVisible()) {
notifyItemRemoved(prevSectionHeaderIndex);