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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/androidoverlay/ThreadHoppingHost.java

Issue 2765443004: AndroidOverlay implementation using Dialog. (Closed)
Patch Set: fixed test Created 3 years, 7 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 2017 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 package org.chromium.content.browser.androidoverlay;
6
7 import android.os.Handler;
8 import android.view.Surface;
9
10 import java.util.concurrent.Semaphore;
11
12 /**
13 * DialogOverlayCore::Host implementation that transfers messages to the thread on which it was
14 * constructed. Due to threading concerns, waitForCleanup is not forwarded.
15 */
16 class ThreadHoppingHost implements DialogOverlayCore.Host {
17 // Handler for the host we're proxying to. Typically Browser::UI.
18 private Handler mHandler;
19
20 // Host impl that we're proxying to.
21 private final DialogOverlayCore.Host mHost;
22
23 // Semaphore to keep track of whether cleanup has started yet.
24 private final Semaphore mSemaphore = new Semaphore(0);
25
26 // We will forward to |host| on whatever thread we're constructed on.
27 public ThreadHoppingHost(DialogOverlayCore.Host host) {
28 mHandler = new Handler();
29 mHost = host;
30 }
31
32 @Override
33 public void onSurfaceReady(final Surface surface) {
34 mHandler.post(new Runnable() {
35 @Override
36 public void run() {
37 mHost.onSurfaceReady(surface);
38 }
39 });
40 }
41
42 @Override
43 public void onOverlayDestroyed() {
44 mHandler.post(new Runnable() {
45 @Override
46 public void run() {
47 mHost.onOverlayDestroyed();
48 }
49 });
50 }
51
52 // We don't forward via to |mHandler|, since it should be asynchronous. Els e, the |mHandler|
53 // thread would block. Instead, we wait here and somebody must call onClean up() to let us know
54 // that cleanup has started, and that we may return.
55 @Override
56 public void waitForCleanup() {
57 while (true) {
58 try {
59 mSemaphore.acquire();
60 break;
61 } catch (InterruptedException e) {
62 }
63 }
64 }
65
66 // Notify us that cleanup has started. This is called on |mHandler|'s threa d.
67 public void onCleanup() {
68 mSemaphore.release(1);
69 }
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698