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

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

Issue 2220623002: DialogSurfaceHolder implementation. Base URL: https://chromium.googlesource.com/chromium/src.git@just_surface_manager
Patch Set: panel => media dialog type Created 4 years, 4 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
« no previous file with comments | « media/base/android/BUILD.gn ('k') | media/base/android/dialog_surface_callback.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ab132e1c55e05172a3dccd37167c36e94deddd8c
--- /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_holder.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 DialogSurfaceHolder::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,
+ DialogSurfaceHolder::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 DialogSurface 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_;
+
+ DialogSurfaceHolder::Callback callback_;
+
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(DialogSurfaceCallback);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_
« no previous file with comments | « media/base/android/BUILD.gn ('k') | media/base/android/dialog_surface_callback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698