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

Unified Diff: media/base/android/dialog_surface_callback.h

Issue 2178973004: DialogSurfaceManager implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed IDialogSurfaceActivityMapper from common.aidl Created 4 years 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: media/base/android/dialog_surface_callback.h
diff --git a/media/base/android/dialog_surface_callback.h b/media/base/android/dialog_surface_callback.h
new file mode 100644
index 0000000000000000000000000000000000000000..c2fb2c70357200cabc7f262fa545bd06858b263c
--- /dev/null
+++ b/media/base/android/dialog_surface_callback.h
@@ -0,0 +1,90 @@
+// 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.
+
+#ifndef MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_
+#define MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_
+
+#include <jni.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <set>
+#include <string>
+
+#include "base/android/scoped_java_ref.h"
+#include "base/lazy_instance.h"
+#include "base/macros.h"
+#include "base/single_thread_task_runner.h"
+#include "base/task_runner.h"
+#include "base/threading/thread_checker.h"
+#include "base/time/time.h"
+#include "media/base/android/dialog_surface.h"
+#include "media/base/media_export.h"
+#include "ui/gfx/geometry/point.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace base {
+class WaitableEvent;
+}
+
+namespace media {
+
+// This class implements the C++ wrapper around the java DialogSurfaceCallback.
+// Callbacks will happen on the thread that it's created on.
+// It handles threading and object lifecycle issues. In particular, it's safe
+// to delete this object on the same thread as it was created on at any time,
+// even during a callback. Future callbacks from java will be cancelled
+// automatically, regardless of java threading.
+class MEDIA_EXPORT DialogSurfaceCallback {
+ public:
+ // |callback| will be called on the same thread that we're created on,
+ // regardless of the thread that's used to call from java.
+ DialogSurfaceCallback(const DialogSurface::Callback& callback);
boliu 2017/01/04 01:48:44 explicit
liberato (no reviews please) 2017/01/11 22:17:57 Done.
+ ~DialogSurfaceCallback();
+
+ // Callback that we should use to send the java surface when it arrives.
+ using AndroidSurfaceCB =
+ base::Callback<void(const base::android::JavaRef<jobject>& jsurface)>;
+
+ // Sets the callback that we'll use to provide the surface to DialogSurface.
+ void SetAndroidSurfaceCB(const AndroidSurfaceCB& cb);
+
+ scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const;
+ bool CalledOnValidThread() const;
+
+ jobject obj() const { return j_surface_callback_.obj(); }
boliu 2017/01/04 01:48:44 hmm, having an obj() method is generally a red fla
liberato (no reviews please) 2017/01/11 22:17:56 Acknowledged.
+
+ // Called on the proper thread for the callback for |id|, though |id| might
+ // no longer refer to a valid callback. |jsurface_opt| is an optional object
+ // that goes with the callback. For OP_CREATED, it is the Android Surface.
+ static void OnCallbackProperThread(
+ long id,
+ DialogSurface::CallbackOp what,
+ base::android::ScopedJavaGlobalRef<jobject> jobject_opt,
+ base::WaitableEvent* event);
+
+ static bool RegisterDialogSurfaceCallback(JNIEnv* env);
+
+ private:
+ // Java callback instance.
+ base::android::ScopedJavaGlobalRef<jobject> j_surface_callback_;
+
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ // |id_| must be non-repeating. We can't use |this| directly because of race
+ // conditions with destruction and re-allocation.
+ long id_;
+
+ DialogSurface::Callback callback_;
+
+ base::ThreadChecker thread_checker_;
+
+ AndroidSurfaceCB android_surface_cb_;
+
+ DISALLOW_COPY_AND_ASSIGN(DialogSurfaceCallback);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_

Powered by Google App Engine
This is Rietveld 408576698