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

Side by Side Diff: media/base/android/android_overlay_callback.h

Issue 2178973004: DialogSurfaceManager implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(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_ANDROID_OVERLAY_CALLBACK_H_
6 #define MEDIA_BASE_ANDROID_ANDROID_OVERLAY_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/android_overlay_proxy.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 AndroidOverlayCallback.
30 // Callbacks will happen on the thread that it's created on.
31 // It handles threading and object lifecycle issues. In particular, it's safe
32 // to delete this object on the same thread as it was created on at any time,
33 // even during a callback. Future callbacks from java will be cancelled
34 // automatically, regardless of java threading.
35 class MEDIA_EXPORT AndroidOverlayCallback {
36 public:
37 // |callback| will be called on the same thread that we're created on,
38 // regardless of the thread that's used to call from java.
39 explicit AndroidOverlayCallback(
40 const AndroidOverlayProxy::Callback& callback);
41 ~AndroidOverlayCallback();
42
43 // Callback that we should use to send the java surface when it arrives.
44 using AndroidSurfaceCB =
45 base::Callback<void(const base::android::JavaRef<jobject>& jsurface)>;
46
47 // Sets the callback that we'll use to provide the surface to AndroidOverlay.
48 void SetAndroidSurfaceCB(const AndroidSurfaceCB& cb);
49
50 static scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner();
51 bool CalledOnValidThread() const;
52
53 jobject obj() const { return j_surface_callback_.obj(); }
54
55 // Called on the proper thread for the callback for |id|, though |id| might
56 // no longer refer to a valid callback. |jsurface_opt| is an optional object
57 // that goes with the callback. For OP_CREATED, it is the Android Surface.
58 // |jcompletion_opt| is an optional IAndroidSurfaceCompletion that we'll
59 // signal when done.
60 static void OnCallbackProperThread(
61 long id,
62 AndroidOverlayProxy::CallbackOp what,
63 base::android::ScopedJavaGlobalRef<jobject> jobject_opt,
64 base::android::ScopedJavaGlobalRef<jobject> jcompletion_opt);
65
66 static bool RegisterAndroidOverlayCallback(JNIEnv* env);
67
68 private:
69 // Java callback instance.
70 base::android::ScopedJavaGlobalRef<jobject> j_surface_callback_;
71
72 // |id_| must be non-repeating. We can't use |this| directly because of race
73 // conditions with destruction and re-allocation.
74 long id_;
75
76 AndroidOverlayProxy::Callback callback_;
77
78 base::ThreadChecker thread_checker_;
79
80 AndroidSurfaceCB android_surface_cb_;
81
82 // Task runner of the first callback that uses us. We'll use this for all
83 // callbacks on all task runners.
84 static scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
85
86 DISALLOW_COPY_AND_ASSIGN(AndroidOverlayCallback);
87 };
88
89 } // namespace media
90
91 #endif // MEDIA_BASE_ANDROID_ANDROID_OVERLAY_CALLBACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698