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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelJniBridge.java

Issue 583373002: Break apart the TabModelBase's JNI calls into its own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Breaking apart the bridge Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelJniBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelJniBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelJniBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..768f09ef77b526382d99b449f560037766592835
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabModelJniBridge.java
@@ -0,0 +1,103 @@
+// Copyright 2014 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.tabmodel;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.chrome.browser.Tab;
+import org.chromium.chrome.browser.profiles.Profile;
+
+/**
+ * Bridges between the C++ and Java {@link TabModel} interfaces.
+ */
+public abstract class TabModelJniBridge implements TabModel {
+ private final boolean mIsIncognito;
+
+ /** Native TabModelJniBridge pointer, which will be set by {@link #setNativePtr(long)}. */
+ private long mNativeTabModelJniBridge;
+
+ public TabModelJniBridge(boolean isIncognito) {
+ mIsIncognito = isIncognito;
+ }
+
+ @CalledByNative
+ private void clearNativePtr() {
+ assert mNativeTabModelJniBridge != 0;
+ mNativeTabModelJniBridge = 0;
+ }
+
+ @CalledByNative
+ private void setNativePtr(long nativePointer) {
+ assert mNativeTabModelJniBridge == 0;
+ mNativeTabModelJniBridge = nativePointer;
+ }
+
+ @Override
+ public void destroy() {
David Trainor- moved to gerrit 2014/10/09 20:43:42 Maybe add a comment here about how this will inval
gone 2014/10/10 22:39:19 Done.
+ if (mNativeTabModelJniBridge != 0) {
+ nativeDestroy(mNativeTabModelJniBridge);
+ mNativeTabModelJniBridge = 0;
+ }
+ }
+
+ @Override
+ public boolean isIncognito() {
+ return mIsIncognito;
+ }
+
+ @Override
+ public Profile getProfile() {
+ return nativeGetProfileAndroid(mNativeTabModelJniBridge);
+ }
+
+ /** Broadcast a native-side notification that all tabs are now loaded from storage. */
+ public void broadcastSessionRestoreComplete() {
+ assert mNativeTabModelJniBridge != 0;
+ nativeBroadcastSessionRestoreComplete(mNativeTabModelJniBridge);
+ }
+
+ /**
+ * Called by subclasses when a Tab is added to the TabModel.
+ * @param tab Tab being added to the model.
+ */
+ protected void tabAddedToModel(Tab tab) {
+ if (mNativeTabModelJniBridge != 0) nativeTabAddedToModel(mNativeTabModelJniBridge, tab);
+ }
+
+ /**
+ * Sets the TabModel's index.
+ * @param index Index of the Tab to select.
+ */
+ @CalledByNative
+ protected void setIndex(int index) {
David Trainor- moved to gerrit 2014/10/09 20:43:42 Can this be private?
gone 2014/10/10 22:39:19 This is called by TabModelBase.cancelTabClosure, s
+ TabModelUtils.setIndex(this, index);
+ }
+
+ /**
+ * Creates a Tab with the given WebContents.
+ * @param incognito Whether or not the tab is incognito.
+ * @param nativeWebContents Pointer to the native WebContents.
+ * @param parentId ID of the parent.
+ */
+ @CalledByNative
+ protected abstract Tab createTabWithNativeContents(
+ boolean incognito, long nativeWebContents, int parentId);
+
+ @Override
+ @CalledByNative
+ public abstract int getCount();
+
+ @Override
+ @CalledByNative
+ public abstract int index();
+
+ /** @return Whether or not a sync session is currently being restored. */
+ @CalledByNative
+ protected abstract boolean isSessionRestoreInProgress();
+
+ private native Profile nativeGetProfileAndroid(long nativeTabModelJniBridge);
+ private native void nativeBroadcastSessionRestoreComplete(long nativeTabModelJniBridge);
+ private native void nativeDestroy(long nativeTabModelJniBridge);
+ private native void nativeTabAddedToModel(long nativeTabModelJniBridge, Tab tab);
+}

Powered by Google App Engine
This is Rietveld 408576698