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

Side by Side 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 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_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.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 base {
28 class WaitableEvent;
29 }
30
31 namespace media {
32
33 // This class implements the C++ wrapper around the java DialogSurfaceCallback.
34 // Callbacks will happen on the thread that it's created on.
35 // It handles threading and object lifecycle issues. In particular, it's safe
36 // to delete this object on the same thread as it was created on at any time,
37 // even during a callback. Future callbacks from java will be cancelled
38 // automatically, regardless of java threading.
39 class MEDIA_EXPORT DialogSurfaceCallback {
40 public:
41 // |callback| will be called on the same thread that we're created on,
42 // regardless of the thread that's used to call from java.
43 DialogSurfaceCallback(const DialogSurface::Callback& callback);
boliu 2017/01/04 01:48:44 explicit
liberato (no reviews please) 2017/01/11 22:17:57 Done.
44 ~DialogSurfaceCallback();
45
46 // Callback that we should use to send the java surface when it arrives.
47 using AndroidSurfaceCB =
48 base::Callback<void(const base::android::JavaRef<jobject>& jsurface)>;
49
50 // Sets the callback that we'll use to provide the surface to DialogSurface.
51 void SetAndroidSurfaceCB(const AndroidSurfaceCB& cb);
52
53 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const;
54 bool CalledOnValidThread() const;
55
56 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.
57
58 // Called on the proper thread for the callback for |id|, though |id| might
59 // no longer refer to a valid callback. |jsurface_opt| is an optional object
60 // that goes with the callback. For OP_CREATED, it is the Android Surface.
61 static void OnCallbackProperThread(
62 long id,
63 DialogSurface::CallbackOp what,
64 base::android::ScopedJavaGlobalRef<jobject> jobject_opt,
65 base::WaitableEvent* event);
66
67 static bool RegisterDialogSurfaceCallback(JNIEnv* env);
68
69 private:
70 // Java callback instance.
71 base::android::ScopedJavaGlobalRef<jobject> j_surface_callback_;
72
73 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
74
75 // |id_| must be non-repeating. We can't use |this| directly because of race
76 // conditions with destruction and re-allocation.
77 long id_;
78
79 DialogSurface::Callback callback_;
80
81 base::ThreadChecker thread_checker_;
82
83 AndroidSurfaceCB android_surface_cb_;
84
85 DISALLOW_COPY_AND_ASSIGN(DialogSurfaceCallback);
86 };
87
88 } // namespace media
89
90 #endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_CALLBACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698