Index: content/public/android/java/src/org/chromium/content/browser/androidoverlay/AndroidOverlayProviderImpl.java |
diff --git a/content/public/android/java/src/org/chromium/content/browser/androidoverlay/AndroidOverlayProviderImpl.java b/content/public/android/java/src/org/chromium/content/browser/androidoverlay/AndroidOverlayProviderImpl.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..742a562ed7dfd937f482cac7ee2658cd924e5d33 |
--- /dev/null |
+++ b/content/public/android/java/src/org/chromium/content/browser/androidoverlay/AndroidOverlayProviderImpl.java |
@@ -0,0 +1,67 @@ |
+// 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.content.browser.androidoverlay; |
+ |
+import android.content.Context; |
+ |
+import org.chromium.media.mojom.AndroidOverlayClient; |
+import org.chromium.media.mojom.AndroidOverlayConfig; |
+import org.chromium.media.mojom.AndroidOverlayProvider; |
+import org.chromium.mojo.system.MojoException; |
+import org.chromium.services.service_manager.InterfaceFactory; |
+ |
+/** |
+ * Default impl of AndroidOverlayProvider. Creates AndroidOverlayImpls. |
+ */ |
+public class AndroidOverlayProviderImpl implements AndroidOverlayProvider { |
+ private static final String TAG = "AndroidOverlayProvider"; |
+ |
+ // Count of outstanding overlays. |
+ private static int sOverlayCount; |
+ |
+ /** |
+ * Create an overlay matching |config| and send it to |client|. Remember that potentially many |
+ * providers are created. That's why we use statics. Yes, our factory might provide a |
+ * singleton to the 'real' factory or state, but right now we keep very little state. |
+ */ |
+ public void createOverlay(AndroidOverlayClient client, AndroidOverlayConfig config) { |
+ // Limit the number of overlays. |
+ if (sOverlayCount > 0) { |
+ client.onDestroyed(); |
+ return; |
+ } |
+ |
+ sOverlayCount++; |
+ AndroidOverlayImpl overlay = new AndroidOverlayImpl(client, config); |
+ client.onInitialized(overlay); |
+ } |
+ |
+ @Override |
+ public void close() {} |
+ |
+ @Override |
+ public void onConnectionError(MojoException e) {} |
+ |
+ /** |
+ * Called when an overlay that we've created is destroyed. Remember than an overlay may |
+ * outlive the provider that created it. |
+ */ |
+ public static void onOverlayClosed(AndroidOverlayImpl overlay) { |
+ sOverlayCount--; |
+ } |
+ |
+ /** |
+ * Mojo factory. |
+ */ |
+ public static class Factory implements InterfaceFactory<AndroidOverlayProvider> { |
+ public Factory(Context context) {} |
+ |
+ @Override |
+ public AndroidOverlayProvider createImpl() { |
+ // TODO(liberato): Replace statics with singleton. |
+ return new AndroidOverlayProviderImpl(); |
+ } |
+ } |
+} |