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

Unified Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 14017019: browser: Fix null ANativeWindow reference. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make SetSurface more robust. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/compositor_impl_android.cc
diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc
index 78d6834a5ed77ad6b162d679dc31ab91d1cb29bd..7d70649e7228f39eef914f06c81a8cad42b83c5e 100644
--- a/content/browser/renderer_host/compositor_impl_android.cc
+++ b/content/browser/renderer_host/compositor_impl_android.cc
@@ -126,6 +126,8 @@ CompositorImpl::CompositorImpl(Compositor::Client* client)
}
CompositorImpl::~CompositorImpl() {
+ // Clean-up any surface references.
+ SetSurface(NULL);
}
void CompositorImpl::Composite() {
@@ -163,20 +165,27 @@ void CompositorImpl::SetWindowSurface(ANativeWindow* window) {
void CompositorImpl::SetSurface(jobject surface) {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobject> j_surface(env, surface);
- if (surface) {
- ANativeWindow* window = ANativeWindow_fromSurface(env, surface);
+
+ // First, cleanup any existing surface references.
+ if (surface_id_) {
+ DCHECK(g_surface_map.Get().find(surface_id_) !=
+ g_surface_map.Get().end());
+ base::AutoLock lock(g_surface_map_lock.Get());
+ g_surface_map.Get().erase(surface_id_);
+ }
+ SetWindowSurface(NULL);
+
+ // Now, set the new surface if we have one.
+ ANativeWindow* window = NULL;
+ if (surface)
+ window = ANativeWindow_fromSurface(env, surface);
+ if (window) {
SetWindowSurface(window);
ANativeWindow_release(window);
{
base::AutoLock lock(g_surface_map_lock.Get());
g_surface_map.Get().insert(std::make_pair(surface_id_, j_surface));
}
- } else {
- {
- base::AutoLock lock(g_surface_map_lock.Get());
- g_surface_map.Get().erase(surface_id_);
- }
- SetWindowSurface(NULL);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698