summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordfalcantara@chromium.org <dfalcantara@chromium.org>2015-03-03 10:37:29 -0800
committerdfalcantara@chromium.org <dfalcantara@chromium.org>2015-03-03 18:40:52 +0000
commitb5a284a7d4f63544d18283162ed5bf83c43b36e5 (patch)
treeb88b95c901ffe2d91e1b7cb3e0651d4ed1c58937
parent388eaccdd4d60d78b6955f437a27917be0bb4c34 (diff)
downloadchromium_src-b5a284a7d4f63544d18283162ed5bf83c43b36e5.zip
chromium_src-b5a284a7d4f63544d18283162ed5bf83c43b36e5.tar.gz
chromium_src-b5a284a7d4f63544d18283162ed5bf83c43b36e5.tar.bz2
[Document mode] Keep tab ID list in sync with Tab entries
It is possible to have one DocumentActivity create a Tab and add its ID to the DocumentTabModel, but get interrupted (somehow) before the Tab Entry is added to the DocumentTabModel. This results in getCount() returning the correct number of Tabs that exist but fail to have any information about the new Tab, resulting in getTabAt() returning |null|. We should instead keep the ID list and the Entry list be as in sync as possible, adding the Entry directly to the DocumentTabModel as soon as we let the DocumentTabModel know about the Tab's existence. Add new methods to tie the addTabId and updateEntry functions together via addTab, deprecate the old ones, and assert that we should never get into a bad state. Deprecated methods will be culled when the downstream patch lands. BUG=457427 Original commit: https://crrev.com/7710ef5ff57f581f66dbbaad2dffe8c4a9048add Original review: https://codereview.chromium.org/969443003 TBR=mariakhomenko@chromium.org Review URL: https://codereview.chromium.org/973123002 Cr-Commit-Position: refs/branch-heads/2311@{#101} Cr-Branched-From: 09b7de5dd7254947cd4306de907274fa63373d48-refs/heads/master@{#317474}
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModel.java7
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java13
-rw-r--r--chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModel.java6
3 files changed, 24 insertions, 2 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModel.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModel.java
index 85f58b6..ff7e1e6 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModel.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModel.java
@@ -168,6 +168,13 @@ public interface DocumentTabModel extends TabModel {
void addTab(Tab tab);
/**
+ * Adds the given Tab to this TabModel.
+ * @param intent Intent of the DocumentActivity.
+ * @param tab Tab to add.
+ */
+ void addTab(Intent intent, Tab tab);
+
+ /**
* @return The stage of initialization that the DocumentTabModel is currently going through.
*/
int getCurrentInitializationStage();
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java
index 2eda870..1d70e46 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/DocumentTabModelImpl.java
@@ -266,7 +266,7 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT
// Try to create a Tab that will hold the Tab's info.
Entry entry = mEntryMap.get(tabId);
- if (entry == null) return null;
+ assert entry != null;
// If a tab has already been initialized, use that.
if (entry.placeholderTab != null && entry.placeholderTab.isInitialized()) {
@@ -351,6 +351,7 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT
* @param tabId ID to add.
*/
private void addTabId(int index, int tabId) {
+ assert tabId != Tab.INVALID_TAB_ID;
if (mTabIdList.contains(tabId)) return;
mTabIdList.add(index, tabId);
}
@@ -430,7 +431,7 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT
@Override
public void updateEntry(Intent intent, Tab tab) {
- if (!mActivityDelegate.isValidActivity(isIncognito(), intent)) return;
+ assert mActivityDelegate.isValidActivity(isIncognito(), intent);
int id = ActivityDelegate.getTabIdFromIntent(intent);
if (id == Tab.INVALID_TAB_ID) return;
@@ -870,6 +871,14 @@ public class DocumentTabModelImpl extends TabModelJniBridge implements DocumentT
}
@Override
+ public void addTab(Intent intent, Tab tab) {
+ int parentIndex = indexOf(tab.getParentId());
+ int index = parentIndex == -1 ? getCount() : parentIndex + 1;
+ addTab(tab, index, tab.getLaunchType());
+ updateEntry(intent, tab);
+ }
+
+ @Override
public void addTab(Tab tab, int index, TabLaunchType type) {
for (TabModelObserver obs : mObservers) obs.willAddTab(tab, type);
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModel.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModel.java
index ab51905..a85fc7e 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModel.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/OffTheRecordDocumentTabModel.java
@@ -114,6 +114,12 @@ public class OffTheRecordDocumentTabModel extends OffTheRecordTabModel implement
}
@Override
+ public void addTab(Intent intent, Tab tab) {
+ ensureTabModelImpl();
+ getDelegateDocumentTabModel().addTab(intent, tab);
+ }
+
+ @Override
public boolean closeTabAt(int index) {
boolean success = false;
if (isDocumentTabModelImplCreated()) {