Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.incognito; | |
| 6 | |
| 7 import android.app.Activity; | |
| 8 import android.app.IntentService; | |
| 9 import android.app.PendingIntent; | |
| 10 import android.content.Context; | |
| 11 import android.content.Intent; | |
| 12 import android.util.Pair; | |
| 13 | |
| 14 import org.chromium.base.ApplicationStatus; | |
| 15 import org.chromium.base.ThreadUtils; | |
| 16 import org.chromium.base.VisibleForTesting; | |
| 17 import org.chromium.chrome.browser.ChromeApplication; | |
| 18 import org.chromium.chrome.browser.ChromeTabbedActivity; | |
| 19 import org.chromium.chrome.browser.TabState; | |
| 20 import org.chromium.chrome.browser.tabmodel.TabPersistentStore; | |
| 21 import org.chromium.chrome.browser.tabmodel.TabWindowManager; | |
| 22 import org.chromium.chrome.browser.util.FeatureUtilities; | |
| 23 | |
| 24 import java.io.File; | |
| 25 import java.lang.ref.WeakReference; | |
| 26 import java.util.ArrayList; | |
| 27 import java.util.List; | |
| 28 import java.util.concurrent.Callable; | |
| 29 | |
| 30 /** | |
| 31 * Service that handles the action of clicking on the incognito notification. | |
| 32 */ | |
| 33 public class IncognitoNotificationService extends IntentService { | |
| 34 | |
| 35 private static final String TAG = "incognito_notification"; | |
| 36 | |
| 37 private static final String ACTION_CLOSE_ALL_INCOGNITO = | |
| 38 "com.google.android.apps.chrome.document.CLOSE_ALL_INCOGNITO"; | |
|
gone
2016/04/01 17:35:22
Assuming that the notification goes away on upgrad
Ted C
2016/04/01 22:13:31
It dismissed with an overinstall using install -r,
| |
| 39 | |
| 40 @VisibleForTesting | |
| 41 public static PendingIntent getRemoveAllIncognitoTabsIntent(Context context) { | |
| 42 Intent intent = new Intent(context, IncognitoNotificationService.class); | |
| 43 intent.setAction(ACTION_CLOSE_ALL_INCOGNITO); | |
| 44 return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_O NE_SHOT); | |
| 45 } | |
| 46 | |
| 47 /** Empty public constructor needed by Android. */ | |
| 48 public IncognitoNotificationService() { | |
| 49 super(TAG); | |
| 50 } | |
| 51 | |
| 52 @Override | |
| 53 protected void onHandleIntent(Intent intent) { | |
| 54 boolean isDocumentMode = ThreadUtils.runOnUiThreadBlockingNoException( | |
| 55 new Callable<Boolean>() { | |
| 56 @Override | |
| 57 public Boolean call() throws Exception { | |
| 58 return FeatureUtilities.isDocumentMode(IncognitoNotifica tionService.this); | |
| 59 } | |
| 60 }); | |
| 61 | |
| 62 if (isDocumentMode) { | |
| 63 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
|
gone
2016/04/01 17:35:22
TODO(dfalcantara): Delete this?
Ted C
2016/04/01 22:13:31
Done.
| |
| 64 @Override | |
| 65 public void run() { | |
| 66 ChromeApplication.getDocumentTabModelSelector().getModel(tru e).closeAllTabs(); | |
| 67 } | |
| 68 }); | |
| 69 } else { | |
| 70 List<Integer> processedSelectors = closeIncognitoTabsInRunningTabbed Activities(); | |
| 71 | |
| 72 for (int i = 0; i < TabWindowManager.MAX_SIMULTANEOUS_SELECTORS; i++ ) { | |
| 73 if (processedSelectors.contains(i)) continue; | |
| 74 deleteIncognitoStateFilesInDirectory(TabPersistentStore.getState Directory(this, i)); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 79 @Override | |
| 80 public void run() { | |
| 81 int incognitoCount = TabWindowManager.getInstance().getIncognito TabCount(); | |
| 82 assert incognitoCount == 0; | |
| 83 | |
| 84 if (incognitoCount == 0) { | |
| 85 IncognitoNotificationManager.dismissIncognitoNotification(); | |
| 86 } | |
| 87 } | |
| 88 }); | |
| 89 } | |
| 90 | |
| 91 /** | |
| 92 * Iterate across the running activities and for any running tabbed mode act ivities close their | |
| 93 * incognito tabs. | |
| 94 * | |
| 95 * @return The list of window indexes that were processed. | |
| 96 * | |
| 97 * @see TabWindowManager#getIndexForWindow(Activity) | |
| 98 */ | |
| 99 private List<Integer> closeIncognitoTabsInRunningTabbedActivities() { | |
| 100 return ThreadUtils.runOnUiThreadBlockingNoException( | |
| 101 new Callable<List<Integer>>() { | |
| 102 @Override | |
| 103 public List<Integer> call() { | |
| 104 List<Integer> selectorIndexes = new ArrayList<>(); | |
| 105 | |
| 106 List<WeakReference<Activity>> runningActivities = | |
| 107 ApplicationStatus.getRunningActivities(); | |
| 108 for (int i = 0; i < runningActivities.size(); i++) { | |
| 109 Activity activity = runningActivities.get(i).get(); | |
| 110 if (activity == null) continue; | |
| 111 if (!(activity instanceof ChromeTabbedActivity)) con tinue; | |
| 112 | |
| 113 ChromeTabbedActivity tabbedActivity = (ChromeTabbedA ctivity) activity; | |
| 114 if (tabbedActivity.isActivityDestroyed()) continue; | |
| 115 | |
| 116 tabbedActivity.getTabModelSelector().getModel(true). closeAllTabs(); | |
| 117 selectorIndexes.add(TabWindowManager.getInstance().g etIndexForWindow( | |
| 118 tabbedActivity)); | |
| 119 } | |
| 120 | |
| 121 return selectorIndexes; | |
| 122 } | |
| 123 }); | |
| 124 } | |
| 125 | |
| 126 private void deleteIncognitoStateFilesInDirectory(File directory) { | |
| 127 File[] allTabStates = directory.listFiles(); | |
| 128 if (allTabStates == null) return; | |
| 129 | |
| 130 for (int i = 0; i < allTabStates.length; i++) { | |
| 131 String fileName = allTabStates[i].getName(); | |
| 132 Pair<Integer, Boolean> tabInfo = TabState.parseInfoFromFilename(file Name); | |
| 133 if (tabInfo == null || !tabInfo.second) continue; | |
| 134 allTabStates[i].delete(); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 } | |
| OLD | NEW |