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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java

Issue 2132163002: Add BlimpClientContext and factory with real and dummy implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-blimp-client-core-public-to-blimp-client
Patch Set: git merge origin/master before CQ for good measure Created 4 years, 5 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/blimp/ChromeBlimpClientContextDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java
new file mode 100644
index 0000000000000000000000000000000000000000..d01e1fb108e1ea64b378bcff755e394692c44991
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/blimp/ChromeBlimpClientContextDelegate.java
@@ -0,0 +1,56 @@
+// Copyright 2016 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.blimp;
+
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.chrome.browser.profiles.Profile;
+
+/**
+ * The ChromeBlimpClientContextDelegate for //chrome which provides the necessary functionality
+ * required to run Blimp. This is the Java counterparty to the C++
+ * ChromeBlimpClientContextDelegateAndroid.
+ *
+ * There can only be a single delegate for any given BlimpClientContext. To create one and attach
+ * it, call {@link ChromeBlimpClientContextDelegate#createAndSetDelegateForContext(Profile)}.
+ * When the delegate should be deleted, a call to {@link #destroy} is required.
+ */
+public class ChromeBlimpClientContextDelegate {
+ /**
+ * Creates a new ChromeBlimpClientContextDelegate that is owned by the caller. It automatically
+ * attaches itself as the sole delegate for the BlimpClientContext attached to the given
+ * profile. When the delegate should be deleted, the caller of this method must call
+ * {@link #destroy()} to ensure that the native counterparts are cleaned up. The call to
+ * {@link #destroy()} also removes the delegate from the BlimpClientContext by clearing the
+ * pointer for the delegate by calling BlimpClientContext::SetDelegate(nullptr).
+ *
+ * @param profile The profile to use to look for the BlimpClientContext.
+ * @return The newly created delegate, owned by the caller.
+ */
+ public static ChromeBlimpClientContextDelegate createAndSetDelegateForContext(Profile profile) {
+ return new ChromeBlimpClientContextDelegate(profile);
+ }
+
+ /**
+ * The pointer to the ChromeBlimpClientContextDelegateAndroid JNI bridge.
+ */
+ private long mNativeChromeBlimpClientContextDelegateAndroid;
+
+ private ChromeBlimpClientContextDelegate(Profile profile) {
+ mNativeChromeBlimpClientContextDelegateAndroid = nativeInit(profile);
+ }
+
+ @CalledByNative
+ private void clearNativePtr() {
+ mNativeChromeBlimpClientContextDelegateAndroid = 0;
+ }
+
+ public void destroy() {
+ assert mNativeChromeBlimpClientContextDelegateAndroid != 0;
+ nativeDestroy(mNativeChromeBlimpClientContextDelegateAndroid);
+ }
+
+ private native long nativeInit(Profile profile);
+ private native void nativeDestroy(long nativeChromeBlimpClientContextDelegateAndroid);
+}

Powered by Google App Engine
This is Rietveld 408576698