Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.incognito; | 5 package org.chromium.chrome.browser.incognito; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.app.ActivityManager; | 9 import android.app.ActivityManager; |
| 10 import android.app.ActivityManager.AppTask; | 10 import android.app.ActivityManager.AppTask; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 import org.chromium.chrome.browser.ChromeTabbedActivity; | 27 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 28 import org.chromium.chrome.browser.TabState; | 28 import org.chromium.chrome.browser.TabState; |
| 29 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | 29 import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| 30 import org.chromium.chrome.browser.document.DocumentUtils; | 30 import org.chromium.chrome.browser.document.DocumentUtils; |
| 31 import org.chromium.chrome.browser.tabmodel.TabPersistentStore; | 31 import org.chromium.chrome.browser.tabmodel.TabPersistentStore; |
| 32 import org.chromium.chrome.browser.tabmodel.TabWindowManager; | 32 import org.chromium.chrome.browser.tabmodel.TabWindowManager; |
| 33 import org.chromium.chrome.browser.util.FeatureUtilities; | 33 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 34 | 34 |
| 35 import java.io.File; | 35 import java.io.File; |
| 36 import java.lang.ref.WeakReference; | 36 import java.lang.ref.WeakReference; |
| 37 import java.util.ArrayList; | |
| 38 import java.util.HashSet; | 37 import java.util.HashSet; |
| 39 import java.util.List; | 38 import java.util.List; |
| 40 import java.util.Set; | 39 import java.util.Set; |
| 41 import java.util.concurrent.Callable; | 40 import java.util.concurrent.Callable; |
| 42 | 41 |
| 43 /** | 42 /** |
| 44 * Service that handles the action of clicking on the incognito notification. | 43 * Service that handles the action of clicking on the incognito notification. |
| 45 */ | 44 */ |
| 46 public class IncognitoNotificationService extends IntentService { | 45 public class IncognitoNotificationService extends IntentService { |
| 47 | 46 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 75 boolean clearedIncognito = true; | 74 boolean clearedIncognito = true; |
| 76 if (isDocumentMode) { | 75 if (isDocumentMode) { |
| 77 // TODO(dfalcantara): Delete this when document mode goes away. | 76 // TODO(dfalcantara): Delete this when document mode goes away. |
| 78 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 77 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 79 @Override | 78 @Override |
| 80 public void run() { | 79 public void run() { |
| 81 ChromeApplication.getDocumentTabModelSelector().getModel(tru e).closeAllTabs(); | 80 ChromeApplication.getDocumentTabModelSelector().getModel(tru e).closeAllTabs(); |
| 82 } | 81 } |
| 83 }); | 82 }); |
| 84 } else { | 83 } else { |
| 85 List<Integer> processedSelectors = closeIncognitoTabsInRunningTabbed Activities(); | 84 closeIncognitoTabsInRunningTabbedActivities(); |
| 86 | 85 |
| 87 for (int i = 0; i < TabWindowManager.MAX_SIMULTANEOUS_SELECTORS; i++ ) { | 86 clearedIncognito &= deleteIncognitoStateFilesInDirectory( |
|
Ted C
2016/06/29 23:47:23
this can just be = instead of &= since there are n
Theresa
2016/06/30 00:02:51
Done.
| |
| 88 if (processedSelectors.contains(i)) continue; | 87 TabPersistentStore.getOrCreateStateDirectory()); |
| 89 clearedIncognito &= deleteIncognitoStateFilesInDirectory( | |
| 90 TabPersistentStore.getOrCreateSelectorStateDirectory(i)) ; | |
| 91 } | |
| 92 } | 88 } |
| 93 | 89 |
| 94 // If we failed clearing all of the incognito tabs, then do not dismiss the notification. | 90 // If we failed clearing all of the incognito tabs, then do not dismiss the notification. |
| 95 if (!clearedIncognito) return; | 91 if (!clearedIncognito) return; |
| 96 | 92 |
| 97 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 93 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 98 @Override | 94 @Override |
| 99 public void run() { | 95 public void run() { |
| 100 int incognitoCount = TabWindowManager.getInstance().getIncognito TabCount(); | 96 int incognitoCount = TabWindowManager.getInstance().getIncognito TabCount(); |
| 101 assert incognitoCount == 0; | 97 assert incognitoCount == 0; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 visibleTaskIds.add(activity.getTaskId()); | 182 visibleTaskIds.add(activity.getTaskId()); |
| 187 } | 183 } |
| 188 } | 184 } |
| 189 return visibleTaskIds; | 185 return visibleTaskIds; |
| 190 } | 186 } |
| 191 | 187 |
| 192 /** | 188 /** |
| 193 * Iterate across the running activities and for any running tabbed mode act ivities close their | 189 * Iterate across the running activities and for any running tabbed mode act ivities close their |
| 194 * incognito tabs. | 190 * incognito tabs. |
| 195 * | 191 * |
| 196 * @return The list of window indexes that were processed. | |
| 197 * | |
| 198 * @see TabWindowManager#getIndexForWindow(Activity) | 192 * @see TabWindowManager#getIndexForWindow(Activity) |
| 199 */ | 193 */ |
| 200 private List<Integer> closeIncognitoTabsInRunningTabbedActivities() { | 194 private Void closeIncognitoTabsInRunningTabbedActivities() { |
|
Ted C
2016/06/29 23:47:23
this should be lowercase void now
Theresa
2016/06/30 00:02:51
Done.
| |
| 201 return ThreadUtils.runOnUiThreadBlockingNoException( | 195 return ThreadUtils.runOnUiThreadBlockingNoException( |
|
Ted C
2016/06/29 23:47:23
remove the return and instead of Callable, use a R
Theresa
2016/06/30 00:02:52
Done.
| |
| 202 new Callable<List<Integer>>() { | 196 new Callable<Void>() { |
| 203 @Override | 197 @Override |
| 204 public List<Integer> call() { | 198 public Void call() { |
| 205 List<Integer> selectorIndexes = new ArrayList<>(); | |
| 206 | |
| 207 List<WeakReference<Activity>> runningActivities = | 199 List<WeakReference<Activity>> runningActivities = |
| 208 ApplicationStatus.getRunningActivities(); | 200 ApplicationStatus.getRunningActivities(); |
| 209 for (int i = 0; i < runningActivities.size(); i++) { | 201 for (int i = 0; i < runningActivities.size(); i++) { |
| 210 Activity activity = runningActivities.get(i).get(); | 202 Activity activity = runningActivities.get(i).get(); |
| 211 if (activity == null) continue; | 203 if (activity == null) continue; |
| 212 if (!(activity instanceof ChromeTabbedActivity)) con tinue; | 204 if (!(activity instanceof ChromeTabbedActivity)) con tinue; |
| 213 | 205 |
| 214 ChromeTabbedActivity tabbedActivity = (ChromeTabbedA ctivity) activity; | 206 ChromeTabbedActivity tabbedActivity = (ChromeTabbedA ctivity) activity; |
| 215 if (tabbedActivity.isActivityDestroyed()) continue; | 207 if (tabbedActivity.isActivityDestroyed()) continue; |
| 216 | 208 |
| 217 tabbedActivity.getTabModelSelector().getModel(true). closeAllTabs( | 209 tabbedActivity.getTabModelSelector().getModel(true). closeAllTabs( |
| 218 false, false); | 210 false, false); |
| 219 selectorIndexes.add(TabWindowManager.getInstance().g etIndexForWindow( | |
| 220 tabbedActivity)); | |
| 221 } | 211 } |
| 222 | 212 |
| 223 return selectorIndexes; | 213 return null; |
| 224 } | 214 } |
| 225 }); | 215 }); |
| 226 } | 216 } |
| 227 | 217 |
| 228 /** | 218 /** |
| 229 * @return Whether deleting all the incognito files was successful. | 219 * @return Whether deleting all the incognito files was successful. |
| 230 */ | 220 */ |
| 231 private boolean deleteIncognitoStateFilesInDirectory(File directory) { | 221 private boolean deleteIncognitoStateFilesInDirectory(File directory) { |
| 232 File[] allTabStates = directory.listFiles(); | 222 File[] allTabStates = directory.listFiles(); |
| 233 if (allTabStates == null) return true; | 223 if (allTabStates == null) return true; |
| 234 | 224 |
| 235 boolean deletionSuccessful = true; | 225 boolean deletionSuccessful = true; |
| 236 for (int i = 0; i < allTabStates.length; i++) { | 226 for (int i = 0; i < allTabStates.length; i++) { |
| 237 String fileName = allTabStates[i].getName(); | 227 String fileName = allTabStates[i].getName(); |
| 238 Pair<Integer, Boolean> tabInfo = TabState.parseInfoFromFilename(file Name); | 228 Pair<Integer, Boolean> tabInfo = TabState.parseInfoFromFilename(file Name); |
| 239 if (tabInfo == null || !tabInfo.second) continue; | 229 if (tabInfo == null || !tabInfo.second) continue; |
| 240 deletionSuccessful &= allTabStates[i].delete(); | 230 deletionSuccessful &= allTabStates[i].delete(); |
| 241 } | 231 } |
| 242 return deletionSuccessful; | 232 return deletionSuccessful; |
| 243 } | 233 } |
| 244 | 234 |
| 245 } | 235 } |
| OLD | NEW |