OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.tabmodel; | 5 package org.chromium.chrome.browser.tabmodel; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.util.SparseArray; | 8 import android.util.SparseArray; |
9 | 9 |
10 import org.chromium.base.ActivityState; | 10 import org.chromium.base.ActivityState; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 if (tab != null && tab.isIncognito()) count++; | 151 if (tab != null && tab.isIncognito()) count++; |
152 } | 152 } |
153 return count; | 153 return count; |
154 } | 154 } |
155 | 155 |
156 /** | 156 /** |
157 * @param tabId The ID of the tab in question. | 157 * @param tabId The ID of the tab in question. |
158 * @return Whether the given tab exists in any currently loaded selector. | 158 * @return Whether the given tab exists in any currently loaded selector. |
159 */ | 159 */ |
160 public boolean tabExistsInAnySelector(int tabId) { | 160 public boolean tabExistsInAnySelector(int tabId) { |
| 161 return getTabById(tabId) != null; |
| 162 } |
| 163 |
| 164 /** |
| 165 * @param tabId The ID of the tab in question. |
| 166 * @return Specified {@link Tab} or {@code null} if the {@link Tab} is not f
ound. |
| 167 */ |
| 168 public Tab getTabById(int tabId) { |
161 for (int i = 0; i < mSelectors.size(); i++) { | 169 for (int i = 0; i < mSelectors.size(); i++) { |
162 TabModelSelector selector = mSelectors.get(i); | 170 TabModelSelector selector = mSelectors.get(i); |
163 if (selector != null) { | 171 if (selector != null) { |
164 if (TabModelUtils.getTabById(selector.getModel(false), tabId) !=
null | 172 final Tab tab = selector.getTabById(tabId); |
165 || TabModelUtils.getTabById(selector.getModel(true), tab
Id) != null) { | 173 if (tab != null) return tab; |
166 return true; | |
167 } | |
168 } | 174 } |
169 } | 175 } |
170 | 176 |
171 // Account for tabs that were recently reparented and haven't been attac
hed to new | 177 if (AsyncTabParamsManager.hasParamsForTabId(tabId)) { |
172 // activities yet. | 178 return AsyncTabParamsManager.getAsyncTabParams().get(tabId).getTabTo
Reparent(); |
173 return AsyncTabParamsManager.hasParamsForTabId(tabId); | 179 } |
| 180 |
| 181 return null; |
174 } | 182 } |
175 | 183 |
176 @Override | 184 @Override |
177 public void onActivityStateChange(Activity activity, int newState) { | 185 public void onActivityStateChange(Activity activity, int newState) { |
178 if (newState == ActivityState.DESTROYED && mAssignments.containsKey(acti
vity)) { | 186 if (newState == ActivityState.DESTROYED && mAssignments.containsKey(acti
vity)) { |
179 int index = mSelectors.indexOf(mAssignments.remove(activity)); | 187 int index = mSelectors.indexOf(mAssignments.remove(activity)); |
180 if (index >= 0) mSelectors.set(index, null); | 188 if (index >= 0) mSelectors.set(index, null); |
181 // TODO(dtrainor): Move TabModelSelector#destroy() calls here. | 189 // TODO(dtrainor): Move TabModelSelector#destroy() calls here. |
182 } | 190 } |
183 } | 191 } |
(...skipping 18 matching lines...) Expand all Loading... |
202 @Override | 210 @Override |
203 public TabModelSelector buildSelector(ChromeActivity activity, WindowAnd
roid windowAndroid, | 211 public TabModelSelector buildSelector(ChromeActivity activity, WindowAnd
roid windowAndroid, |
204 int selectorIndex) { | 212 int selectorIndex) { |
205 assert activity == windowAndroid.getActivity().get(); | 213 assert activity == windowAndroid.getActivity().get(); |
206 TabPersistencePolicy persistencePolicy = new TabbedModeTabPersistenc
ePolicy( | 214 TabPersistencePolicy persistencePolicy = new TabbedModeTabPersistenc
ePolicy( |
207 activity, selectorIndex); | 215 activity, selectorIndex); |
208 return new TabModelSelectorImpl(activity, persistencePolicy, windowA
ndroid, true); | 216 return new TabModelSelectorImpl(activity, persistencePolicy, windowA
ndroid, true); |
209 } | 217 } |
210 } | 218 } |
211 } | 219 } |
OLD | NEW |