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..fda0f4255c8d823728a7bda949e9806ba9f8563b |
--- /dev/null |
+++ b/media/base/android/dialog_surface_callback.h |
@@ -0,0 +1,79 @@ |
+// 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_controller.h" |
+#include "media/base/media_export.h" |
+#include "ui/gfx/geometry/point.h" |
+#include "ui/gfx/geometry/size.h" |
+ |
+namespace media { |
+ |
+// This class implements the C++ wrapper around the java DialogSurfaceCallback. |
+// It handles threading and object lifecycle issues. |
+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 DialogSurfaceController::Callback& callback); |
+ ~DialogSurfaceCallback(); |
+ |
+ scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const; |
+ bool CalledOnValidThread() const; |
+ |
+ jobject obj() const { return j_surface_callback_.obj(); } |
+ |
+ // Called on the proper thread for the callback for |id|, though |id| might |
+ // no longer refer to a valid callback. |
+ static void OnCallbackProperThread(long id, |
+ DialogSurfaceController::CallbackOp what, |
+ base::WaitableEvent* event); |
+ |
+ // Process a callback from java. |
+ // It would be nice if this didn't have to be static, but the multi-threaded |
+ // nature of DialogSurfaceController makes it very hard to do safely. |
+ // This may be called on any thread. |
+ static void OnCallback(JNIEnv* env, |
+ const base::android::JavaParamRef<jobject>& obj, |
+ long id, |
+ int what); |
+ |
+ 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_; |
+ |
+ DialogSurfaceController::Callback callback_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DialogSurfaceCallback); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_ |