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

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

Issue 1967553002: DO NOT COMMIT - DialogSurface initial implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup 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 unified diff | Download patch
« no previous file with comments | « media/base/android/dialog_surface.cc ('k') | media/base/android/dialog_surface_callback.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 DialogSurface::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 DialogSurface::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 DialogSurface 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 DialogSurface::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_
OLDNEW
« no previous file with comments | « media/base/android/dialog_surface.cc ('k') | media/base/android/dialog_surface_callback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698