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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/tabmodel/IncognitoTabModel.java

Issue 2899053004: [Home] Ensure incognito tab model is created when NTP opened (Closed)
Patch Set: [Home] Ensure incognito tab model is created when NTP opened Created 3 years, 7 months 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 unified diff | Download patch
OLDNEW
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
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
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()
87 && TabWindowManager.getInstance().canDestroyIncognitoProfile()) {
Ted C 2017/05/24 17:56:08 I think this should go into the delegate doIncogni
Theresa 2017/05/24 18:35:46 Done.
85 IncognitoNotificationManager.dismissIncognitoNotification(); 88 IncognitoNotificationManager.dismissIncognitoNotification();
86 89
87 profile.destroyWhenAppropriate(); 90 profile.destroyWhenAppropriate();
88 } 91 }
89 92
90 mDelegateModel = EmptyTabModel.getInstance(); 93 mDelegateModel = EmptyTabModel.getInstance();
91 } 94 }
92 95
93 private boolean isEmpty() { 96 private boolean isEmpty() {
94 return getComprehensiveModel().getCount() == 0; 97 return getComprehensiveModel().getCount() == 0;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 208 }
206 209
207 @Override 210 @Override
208 public void cancelTabClosure(int tabId) { 211 public void cancelTabClosure(int tabId) {
209 mDelegateModel.cancelTabClosure(tabId); 212 mDelegateModel.cancelTabClosure(tabId);
210 } 213 }
211 214
212 @Override 215 @Override
213 public void addTab(Tab tab, int index, TabLaunchType type) { 216 public void addTab(Tab tab, int index, TabLaunchType type) {
214 mIsAddingTab = true; 217 mIsAddingTab = true;
218 mIsPendingTabAdd = false;
215 ensureTabModelImpl(); 219 ensureTabModelImpl();
216 mDelegateModel.addTab(tab, index, type); 220 mDelegateModel.addTab(tab, index, type);
217 mIsAddingTab = false; 221 mIsAddingTab = false;
218 } 222 }
219 223
220 @Override 224 @Override
221 public void addObserver(TabModelObserver observer) { 225 public void addObserver(TabModelObserver observer) {
222 mObservers.addObserver(observer); 226 mObservers.addObserver(observer);
223 mDelegateModel.addObserver(observer); 227 mDelegateModel.addObserver(observer);
224 } 228 }
225 229
226 @Override 230 @Override
227 public void removeObserver(TabModelObserver observer) { 231 public void removeObserver(TabModelObserver observer) {
228 mObservers.removeObserver(observer); 232 mObservers.removeObserver(observer);
229 mDelegateModel.removeObserver(observer); 233 mDelegateModel.removeObserver(observer);
230 } 234 }
231 235
232 @Override 236 @Override
233 public void removeTab(Tab tab) { 237 public void removeTab(Tab tab) {
234 mDelegateModel.removeTab(tab); 238 mDelegateModel.removeTab(tab);
235 // Call destroyIncognitoIfNecessary() in case the last incognito tab in this model is 239 // Call destroyIncognitoIfNecessary() in case the last incognito tab in this model is
236 // reparented to a different activity. See crbug.com/611806. 240 // reparented to a different activity. See crbug.com/611806.
237 destroyIncognitoIfNecessary(); 241 destroyIncognitoIfNecessary();
238 } 242 }
239 243
240 @Override 244 @Override
241 public void openMostRecentlyClosedTab() { 245 public void openMostRecentlyClosedTab() {
242 } 246 }
243 247
248 @Override
249 public void setIsPendingTabAdd(boolean isPendingTabAdd) {
250 mIsPendingTabAdd = isPendingTabAdd;
251 if (mIsPendingTabAdd) {
252 ensureTabModelImpl();
253 } else {
254 destroyIncognitoIfNecessary();
255 }
256 }
257
258 @Override
259 public boolean isPendingTabAdd() {
260 return mIsPendingTabAdd;
Theresa 2017/05/24 16:52:08 Ted, should this also return true if mIsAddingTab
Ted C 2017/05/24 17:56:08 I don't think we need to. The mIsAddingTab is don
Theresa 2017/05/24 18:35:46 Excellent, thanks!
261 }
244 } 262 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698