Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsTabPersistencePolicy.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsTabPersistencePolicy.java b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsTabPersistencePolicy.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cacf47462dc99d857197febe1a6ed2cd0f1d2c92 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsTabPersistencePolicy.java |
| @@ -0,0 +1,109 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.browseractions; |
| + |
| +import android.os.StrictMode; |
| + |
| +import org.chromium.base.Callback; |
| +import org.chromium.base.Log; |
| +import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; |
| +import org.chromium.chrome.browser.tabmodel.TabPersistencePolicy; |
| +import org.chromium.chrome.browser.tabmodel.TabPersistentStore; |
| + |
| +import java.io.File; |
| +import java.util.List; |
| +import java.util.concurrent.Executor; |
| + |
| +import javax.annotation.Nullable; |
| + |
| +/** |
| + * Handles the Browser Actions Tab specific behaviors of tab persistence. |
| + */ |
| +public class BrowserActionsTabPersistencePolicy implements TabPersistencePolicy { |
| + static final String SAVED_STATE_DIRECTORY = "browser_actions"; |
| + |
| + private static final String TAG = "tabmodel"; |
| + |
| + /** Prevents two state directories from getting created simultaneously. */ |
| + private static final Object DIR_CREATION_LOCK = new Object(); |
| + |
| + private static File sStateDirectory; |
| + |
| + @Override |
| + public File getOrCreateStateDirectory() { |
|
Yusuf
2017/07/18 22:59:47
so the only current behavior change from the paren
ltian
2017/08/07 23:24:11
To merge the Browser Actions tabs into normal Chro
|
| + return getOrCreateBrowserActionsModeStateDirectory(); |
| + } |
| + |
| + @Override |
| + public String getStateFileName() { |
| + return TabPersistentStore.getStateFileName("0"); |
| + } |
| + |
| + @Override |
| + public boolean shouldMergeOnStartup() { |
|
Yusuf
2017/07/18 22:59:47
so we are not merging the tabs back in yet? What h
ltian
2017/08/07 23:24:11
Yes, this CL does not deal with tab merging. So if
|
| + return false; |
| + } |
| + |
| + @Override |
| + @Nullable |
| + public String getStateToBeMergedFileName() { |
| + return null; |
| + } |
| + |
| + @Override |
| + public boolean performInitialization(Executor executor) { |
| + return true; |
| + } |
| + |
| + @Override |
| + public void waitForInitializationToFinish() {} |
| + |
| + @Override |
| + public boolean isMergeInProgress() { |
| + return false; |
| + } |
| + |
| + @Override |
| + public void setMergeInProgress(boolean isStarted) { |
| + assert false : "Merge not supported in Browser Actions"; |
| + } |
| + |
| + @Override |
| + public void cancelCleanupInProgress() {} |
| + |
| + @Override |
| + public void cleanupUnusedFiles(Callback<List<String>> filesToDelete) {} |
| + |
| + @Override |
| + public void setTabContentManager(TabContentManager cache) {} |
| + |
| + @Override |
| + public void notifyStateLoaded(int tabCountAtStartup) {} |
| + |
| + @Override |
| + public void destroy() {} |
| + |
| + /** |
| + * The folder where the state should be saved to. |
| + * @return A file representing the directory that contains TabModelSelector states. |
| + */ |
| + public static File getOrCreateBrowserActionsModeStateDirectory() { |
| + synchronized (DIR_CREATION_LOCK) { |
| + if (sStateDirectory == null) { |
| + sStateDirectory = new File( |
| + TabPersistentStore.getOrCreateBaseStateDirectory(), SAVED_STATE_DIRECTORY); |
| + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); |
| + try { |
| + if (!sStateDirectory.exists() && !sStateDirectory.mkdirs()) { |
| + Log.e(TAG, "Failed to create state folder: " + sStateDirectory); |
| + } |
| + } finally { |
| + StrictMode.setThreadPolicy(oldPolicy); |
| + } |
| + } |
| + } |
| + return sStateDirectory; |
| + } |
| +} |