OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_ |
| 6 #define MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_ |
| 7 |
| 8 #include <jni.h> |
| 9 #include <stddef.h> |
| 10 #include <stdint.h> |
| 11 |
| 12 #include <set> |
| 13 #include <string> |
| 14 |
| 15 #include "base/android/scoped_java_ref.h" |
| 16 #include "base/lazy_instance.h" |
| 17 #include "base/macros.h" |
| 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/task_runner.h" |
| 20 #include "base/threading/thread_checker.h" |
| 21 #include "base/time/time.h" |
| 22 #include "media/base/android/dialog_surface_controller.h" |
| 23 #include "media/base/media_export.h" |
| 24 #include "ui/gfx/geometry/point.h" |
| 25 #include "ui/gfx/geometry/size.h" |
| 26 |
| 27 namespace media { |
| 28 |
| 29 // This class implements the C++ wrapper around the java DialogSurfaceCallback. |
| 30 // It handles threading and object lifecycle issues. |
| 31 class MEDIA_EXPORT DialogSurfaceCallback { |
| 32 public: |
| 33 // |callback| will be called on the same thread that we're created on, |
| 34 // regardless of the thread that's used to call from java. |
| 35 DialogSurfaceCallback(const DialogSurfaceController::Callback& callback); |
| 36 ~DialogSurfaceCallback(); |
| 37 |
| 38 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const; |
| 39 bool CalledOnValidThread() const; |
| 40 |
| 41 jobject obj() const { return j_surface_callback_.obj(); } |
| 42 |
| 43 // Called on the proper thread for the callback for |id|, though |id| might |
| 44 // no longer refer to a valid callback. |
| 45 static void OnCallbackProperThread(long id, |
| 46 DialogSurfaceController::CallbackOp what, |
| 47 base::WaitableEvent* event); |
| 48 |
| 49 // Process a callback from java. |
| 50 // It would be nice if this didn't have to be static, but the multi-threaded |
| 51 // nature of DialogSurfaceController makes it very hard to do safely. |
| 52 // This may be called on any thread. |
| 53 static void OnCallback(JNIEnv* env, |
| 54 const base::android::JavaParamRef<jobject>& obj, |
| 55 long id, |
| 56 int what); |
| 57 |
| 58 static bool RegisterDialogSurfaceCallback(JNIEnv* env); |
| 59 |
| 60 private: |
| 61 // Java callback instance. |
| 62 base::android::ScopedJavaGlobalRef<jobject> j_surface_callback_; |
| 63 |
| 64 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 65 |
| 66 // |id_| must be non-repeating. We can't use |this| directly because of race |
| 67 // conditions with destruction and re-allocation. |
| 68 long id_; |
| 69 |
| 70 DialogSurfaceController::Callback callback_; |
| 71 |
| 72 base::ThreadChecker thread_checker_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(DialogSurfaceCallback); |
| 75 }; |
| 76 |
| 77 } // namespace media |
| 78 |
| 79 #endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_ |
OLD | NEW |