This source file includes following definitions.
- CalledByNative
- onUpdated
- pushSession
- pushWindow
- pushTab
- destroy
- finalize
- isTabSyncEnabled
- setOnForeignSessionCallback
- getForeignSessions
- openForeignSessionTab
- deleteForeignSession
- nativeInit
- nativeDestroy
- nativeIsTabSyncEnabled
- nativeSetOnForeignSessionCallback
- nativeGetForeignSessions
- nativeOpenForeignSessionTab
- nativeDeleteForeignSession
package org.chromium.chrome.browser;
import org.chromium.base.CalledByNative;
import org.chromium.chrome.browser.profiles.Profile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ForeignSessionHelper {
private long mNativeForeignSessionHelper;
public interface ForeignSessionCallback {
@CalledByNative("ForeignSessionCallback")
public void onUpdated();
}
public static class ForeignSession {
public static final int DEVICE_TYPE_UNSET = 0;
public static final int DEVICE_TYPE_WIN = 1;
public static final int DEVICE_TYPE_MACOSX = 2;
public static final int DEVICE_TYPE_LINUX = 3;
public static final int DEVICE_TYPE_CHROMEOS = 4;
public static final int DEVICE_TYPE_OTHER = 5;
public static final int DEVICE_TYPE_PHONE = 6;
public static final int DEVICE_TYPE_TABLET = 7;
public final String tag;
public final String name;
public final int deviceType;
public final long modifiedTime;
public final List<ForeignSessionWindow> windows = new ArrayList<ForeignSessionWindow>();
private ForeignSession(String tag, String name, int deviceType, long modifiedTime) {
this.tag = tag;
this.name = name;
this.deviceType = deviceType;
this.modifiedTime = modifiedTime;
}
}
public static class ForeignSessionWindow {
public final long timestamp;
public final int sessionId;
public final List<ForeignSessionTab> tabs = new ArrayList<ForeignSessionTab>();
private ForeignSessionWindow(long timestamp, int sessionId) {
this.timestamp = timestamp;
this.sessionId = sessionId;
}
}
public static class ForeignSessionTab {
public final String url;
public final String title;
public final long timestamp;
public final int id;
private ForeignSessionTab(String url, String title, long timestamp, int id) {
this.url = url;
this.title = title;
this.timestamp = timestamp;
this.id = id;
}
}
@CalledByNative
private static ForeignSession pushSession(
List<ForeignSession> sessions, String tag, String name, int deviceType,
long modifiedTime) {
ForeignSession session = new ForeignSession(tag, name, deviceType, modifiedTime);
sessions.add(session);
return session;
}
@CalledByNative
private static ForeignSessionWindow pushWindow(
ForeignSession session, long timestamp, int sessionId) {
ForeignSessionWindow window = new ForeignSessionWindow(timestamp, sessionId);
session.windows.add(window);
return window;
}
@CalledByNative
private static void pushTab(
ForeignSessionWindow window, String url, String title, long timestamp, int sessionId) {
ForeignSessionTab tab = new ForeignSessionTab(url, title, timestamp, sessionId);
window.tabs.add(tab);
}
public ForeignSessionHelper(Profile profile) {
mNativeForeignSessionHelper = nativeInit(profile);
}
public void destroy() {
assert mNativeForeignSessionHelper != 0;
nativeDestroy(mNativeForeignSessionHelper);
mNativeForeignSessionHelper = 0;
}
@Override
protected void finalize() {
assert mNativeForeignSessionHelper == 0;
}
public boolean isTabSyncEnabled() {
return nativeIsTabSyncEnabled(mNativeForeignSessionHelper);
}
public void setOnForeignSessionCallback(ForeignSessionCallback callback) {
nativeSetOnForeignSessionCallback(mNativeForeignSessionHelper, callback);
}
public List<ForeignSession> getForeignSessions() {
List<ForeignSession> result = new ArrayList<ForeignSession>();
boolean received = nativeGetForeignSessions(mNativeForeignSessionHelper, result);
if (received) {
Collections.sort(result, new Comparator<ForeignSession>() {
@Override
public int compare(ForeignSession lhs, ForeignSession rhs) {
return lhs.modifiedTime < rhs.modifiedTime ? 1 :
(lhs.modifiedTime == rhs.modifiedTime ? 0 : -1);
}
});
} else {
result = null;
}
return result;
}
public boolean openForeignSessionTab(Tab tab, ForeignSession session,
ForeignSessionTab foreignTab, int windowOpenDisposition) {
return nativeOpenForeignSessionTab(mNativeForeignSessionHelper, tab, session.tag,
foreignTab.id, windowOpenDisposition);
}
public void deleteForeignSession(ForeignSession session) {
nativeDeleteForeignSession(mNativeForeignSessionHelper, session.tag);
}
private static native long nativeInit(Profile profile);
private static native void nativeDestroy(long nativeForeignSessionHelper);
private static native boolean nativeIsTabSyncEnabled(long nativeForeignSessionHelper);
private static native void nativeSetOnForeignSessionCallback(
long nativeForeignSessionHelper, ForeignSessionCallback callback);
private static native boolean nativeGetForeignSessions(long nativeForeignSessionHelper,
List<ForeignSession> resultSessions);
private static native boolean nativeOpenForeignSessionTab(
long nativeForeignSessionHelper, Tab tab, String sessionTag, int tabId,
int disposition);
private static native void nativeDeleteForeignSession(
long nativeForeignSessionHelper, String sessionTag);
}