Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java

Issue 2573173002: 📰 Split TreeNode#init into SetParent and SetChildren (Closed)
Patch Set: revert getChildren() change Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
index 2143c590c1b5ea768d29bf718f04b28ba84f0b89..5ac8614dbf72c08f4eb1c7afb0d7a4ecc7acd6d5 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.ntp.cards;
import org.chromium.base.Log;
+import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
@@ -15,7 +16,6 @@
import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
-import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -29,37 +29,23 @@
/** Maps suggestion categories to sections, with stable iteration ordering. */
private final Map<Integer, SuggestionsSection> mSections = new LinkedHashMap<>();
- private final List<TreeNode> mChildren = new ArrayList<>();
private final NewTabPageManager mNewTabPageManager;
private final OfflinePageBridge mOfflinePageBridge;
- public SectionList(NodeParent parent, NewTabPageManager newTabPageManager,
- OfflinePageBridge offlinePageBridge) {
- super(parent);
+ public SectionList(NewTabPageManager newTabPageManager, OfflinePageBridge offlinePageBridge) {
mNewTabPageManager = newTabPageManager;
mNewTabPageManager.getSuggestionsSource().setObserver(this);
mOfflinePageBridge = offlinePageBridge;
- }
-
- @Override
- public void init() {
- super.init();
resetSections(/* alwaysAllowEmptySections = */ false);
}
- @Override
- protected List<TreeNode> getChildren() {
- return mChildren;
- }
-
/**
* Resets the sections, reloading the whole new tab page content.
* @param alwaysAllowEmptySections Whether sections are always allowed to be displayed when
* they are empty, even when they are normally not.
*/
public void resetSections(boolean alwaysAllowEmptySections) {
- mSections.clear();
- mChildren.clear();
+ removeAllSections();
SuggestionsSource suggestionsSource = mNewTabPageManager.getSuggestionsSource();
int[] categories = suggestionsSource.getCategories();
@@ -105,10 +91,9 @@ private int resetSection(@CategoryInt int category, @CategoryStatusEnum int cate
// Create the section if needed.
if (section == null) {
- section = new SuggestionsSection(this, mNewTabPageManager, mOfflinePageBridge, info);
+ section = new SuggestionsSection(mNewTabPageManager, mOfflinePageBridge, info);
mSections.put(category, section);
- mChildren.add(section);
- didAddChild(section);
+ addChild(section);
}
// Add the new suggestions.
@@ -229,10 +214,15 @@ public void dismissSection(SuggestionsSection section) {
removeSection(section);
}
- private void removeSection(SuggestionsSection section) {
+ @VisibleForTesting
+ void removeSection(SuggestionsSection section) {
mSections.remove(section.getCategory());
- willRemoveChild(section);
- mChildren.remove(section);
+ removeChild(section);
+ }
+
+ private void removeAllSections() {
+ mSections.clear();
+ removeChildren();
}
/**

Powered by Google App Engine
This is Rietveld 408576698