| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 org.chromium.base.ObserverList; | 7 import org.chromium.base.ObserverList; |
| 8 import org.chromium.base.ThreadUtils; | 8 import org.chromium.base.ThreadUtils; |
| 9 import org.chromium.chrome.browser.incognito.IncognitoNotificationManager; | 9 import org.chromium.chrome.browser.incognito.IncognitoNotificationManager; |
| 10 import org.chromium.chrome.browser.profiles.Profile; | 10 import org.chromium.chrome.browser.profiles.Profile; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 TabModel createTabModel(); | 29 TabModel createTabModel(); |
| 30 | 30 |
| 31 /** @return Whether Incognito Tabs exist. */ | 31 /** @return Whether Incognito Tabs exist. */ |
| 32 boolean doIncognitoTabsExist(); | 32 boolean doIncognitoTabsExist(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 private final IncognitoTabModelDelegate mDelegate; | 35 private final IncognitoTabModelDelegate mDelegate; |
| 36 private final ObserverList<TabModelObserver> mObservers = new ObserverList<T
abModelObserver>(); | 36 private final ObserverList<TabModelObserver> mObservers = new ObserverList<T
abModelObserver>(); |
| 37 private TabModel mDelegateModel; | 37 private TabModel mDelegateModel; |
| 38 private boolean mIsAddingTab; | 38 private boolean mIsAddingTab; |
| 39 private boolean mIsPendingTabAdd; |
| 39 | 40 |
| 40 /** | 41 /** |
| 41 * Constructor for IncognitoTabModel. | 42 * Constructor for IncognitoTabModel. |
| 42 */ | 43 */ |
| 43 public IncognitoTabModel(IncognitoTabModelDelegate tabModelCreator) { | 44 public IncognitoTabModel(IncognitoTabModelDelegate tabModelCreator) { |
| 44 mDelegate = tabModelCreator; | 45 mDelegate = tabModelCreator; |
| 45 mDelegateModel = EmptyTabModel.getInstance(); | 46 mDelegateModel = EmptyTabModel.getInstance(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 /** | 49 /** |
| (...skipping 16 matching lines...) Expand all Loading... |
| 65 protected TabModel getDelegateModel() { | 66 protected TabModel getDelegateModel() { |
| 66 return mDelegateModel; | 67 return mDelegateModel; |
| 67 } | 68 } |
| 68 | 69 |
| 69 /** | 70 /** |
| 70 * Destroys the Incognito profile when all Incognito tabs have been closed.
Also resets the | 71 * Destroys the Incognito profile when all Incognito tabs have been closed.
Also resets the |
| 71 * delegate TabModel to be a stub EmptyTabModel. | 72 * delegate TabModel to be a stub EmptyTabModel. |
| 72 */ | 73 */ |
| 73 protected void destroyIncognitoIfNecessary() { | 74 protected void destroyIncognitoIfNecessary() { |
| 74 ThreadUtils.assertOnUiThread(); | 75 ThreadUtils.assertOnUiThread(); |
| 75 if (!isEmpty() || mDelegateModel instanceof EmptyTabModel || mIsAddingTa
b) { | 76 if (!isEmpty() || mDelegateModel instanceof EmptyTabModel || mIsAddingTa
b |
| 77 || mIsPendingTabAdd) { |
| 76 return; | 78 return; |
| 77 } | 79 } |
| 78 | 80 |
| 79 Profile profile = getProfile(); | 81 Profile profile = getProfile(); |
| 80 mDelegateModel.destroy(); | 82 mDelegateModel.destroy(); |
| 81 | 83 |
| 82 // Only delete the incognito profile if there are no incognito tabs open
in any tab | 84 // Only delete the incognito profile if there are no incognito tabs open
in any tab |
| 83 // model selector as the profile is shared between them. | 85 // model selector as the profile is shared between them. |
| 84 if (profile != null && !mDelegate.doIncognitoTabsExist()) { | 86 if (profile != null && !mDelegate.doIncognitoTabsExist()) { |
| 85 IncognitoNotificationManager.dismissIncognitoNotification(); | 87 IncognitoNotificationManager.dismissIncognitoNotification(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 207 } |
| 206 | 208 |
| 207 @Override | 209 @Override |
| 208 public void cancelTabClosure(int tabId) { | 210 public void cancelTabClosure(int tabId) { |
| 209 mDelegateModel.cancelTabClosure(tabId); | 211 mDelegateModel.cancelTabClosure(tabId); |
| 210 } | 212 } |
| 211 | 213 |
| 212 @Override | 214 @Override |
| 213 public void addTab(Tab tab, int index, TabLaunchType type) { | 215 public void addTab(Tab tab, int index, TabLaunchType type) { |
| 214 mIsAddingTab = true; | 216 mIsAddingTab = true; |
| 217 mIsPendingTabAdd = false; |
| 215 ensureTabModelImpl(); | 218 ensureTabModelImpl(); |
| 216 mDelegateModel.addTab(tab, index, type); | 219 mDelegateModel.addTab(tab, index, type); |
| 217 mIsAddingTab = false; | 220 mIsAddingTab = false; |
| 218 } | 221 } |
| 219 | 222 |
| 220 @Override | 223 @Override |
| 221 public void addObserver(TabModelObserver observer) { | 224 public void addObserver(TabModelObserver observer) { |
| 222 mObservers.addObserver(observer); | 225 mObservers.addObserver(observer); |
| 223 mDelegateModel.addObserver(observer); | 226 mDelegateModel.addObserver(observer); |
| 224 } | 227 } |
| 225 | 228 |
| 226 @Override | 229 @Override |
| 227 public void removeObserver(TabModelObserver observer) { | 230 public void removeObserver(TabModelObserver observer) { |
| 228 mObservers.removeObserver(observer); | 231 mObservers.removeObserver(observer); |
| 229 mDelegateModel.removeObserver(observer); | 232 mDelegateModel.removeObserver(observer); |
| 230 } | 233 } |
| 231 | 234 |
| 232 @Override | 235 @Override |
| 233 public void removeTab(Tab tab) { | 236 public void removeTab(Tab tab) { |
| 234 mDelegateModel.removeTab(tab); | 237 mDelegateModel.removeTab(tab); |
| 235 // Call destroyIncognitoIfNecessary() in case the last incognito tab in
this model is | 238 // Call destroyIncognitoIfNecessary() in case the last incognito tab in
this model is |
| 236 // reparented to a different activity. See crbug.com/611806. | 239 // reparented to a different activity. See crbug.com/611806. |
| 237 destroyIncognitoIfNecessary(); | 240 destroyIncognitoIfNecessary(); |
| 238 } | 241 } |
| 239 | 242 |
| 240 @Override | 243 @Override |
| 241 public void openMostRecentlyClosedTab() { | 244 public void openMostRecentlyClosedTab() { |
| 242 } | 245 } |
| 243 | 246 |
| 247 @Override |
| 248 public void setIsPendingTabAdd(boolean isPendingTabAdd) { |
| 249 mIsPendingTabAdd = isPendingTabAdd; |
| 250 if (mIsPendingTabAdd) { |
| 251 ensureTabModelImpl(); |
| 252 } else { |
| 253 destroyIncognitoIfNecessary(); |
| 254 } |
| 255 } |
| 256 |
| 257 @Override |
| 258 public boolean isPendingTabAdd() { |
| 259 return mIsPendingTabAdd; |
| 260 } |
| 244 } | 261 } |
| OLD | NEW |