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

Side by Side Diff: services/native_viewport/platform_viewport_android.cc

Issue 1081443005: Make the C++ PlatformViewportAndroid's dtor call the Java PVA's destroy() method. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: use a weak ref instead Created 5 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 unified diff | Download patch
« no previous file with comments | « services/native_viewport/platform_viewport_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/native_viewport/platform_viewport_android.h" 5 #include "services/native_viewport/platform_viewport_android.h"
6 6
7 #include <android/input.h> 7 #include <android/input.h>
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate) 54 PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate)
55 : delegate_(delegate), 55 : delegate_(delegate),
56 window_(NULL), 56 window_(NULL),
57 id_generator_(0), 57 id_generator_(0),
58 weak_factory_(this) { 58 weak_factory_(this) {
59 } 59 }
60 60
61 PlatformViewportAndroid::~PlatformViewportAndroid() { 61 PlatformViewportAndroid::~PlatformViewportAndroid() {
62 if (window_) 62 if (window_)
63 ReleaseWindow(); 63 ReleaseWindow();
64 if (!java_platform_viewport_android_.is_empty()) {
65 JNIEnv* env = base::android::AttachCurrentThread();
66 Java_PlatformViewportAndroid_detach(
67 env, java_platform_viewport_android_.get(env).obj());
68 }
64 } 69 }
65 70
66 void PlatformViewportAndroid::Destroy(JNIEnv* env, jobject obj) { 71 void PlatformViewportAndroid::Destroy(JNIEnv* env, jobject obj) {
67 delegate_->OnDestroyed(); 72 delegate_->OnDestroyed();
68 } 73 }
69 74
70 void PlatformViewportAndroid::SurfaceCreated(JNIEnv* env, 75 void PlatformViewportAndroid::SurfaceCreated(JNIEnv* env,
71 jobject obj, 76 jobject obj,
72 jobject jsurface) { 77 jobject jsurface) {
73 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); 78 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 delegate_->OnEvent(mojo::Event::From(char_event)); 159 delegate_->OnEvent(mojo::Event::From(char_event));
155 } 160 }
156 return true; 161 return true;
157 } 162 }
158 163
159 //////////////////////////////////////////////////////////////////////////////// 164 ////////////////////////////////////////////////////////////////////////////////
160 // PlatformViewportAndroid, PlatformViewport implementation: 165 // PlatformViewportAndroid, PlatformViewport implementation:
161 166
162 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { 167 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) {
163 JNIEnv* env = base::android::AttachCurrentThread(); 168 JNIEnv* env = base::android::AttachCurrentThread();
164 Java_PlatformViewportAndroid_createForActivity( 169 java_platform_viewport_android_ = JavaObjectWeakGlobalRef(
165 env, 170 env, Java_PlatformViewportAndroid_createForActivity(
166 base::android::GetApplicationContext(), 171 env, base::android::GetApplicationContext(),
167 reinterpret_cast<jlong>(this)); 172 reinterpret_cast<jlong>(this)).obj());
168 } 173 }
169 174
170 void PlatformViewportAndroid::Show() { 175 void PlatformViewportAndroid::Show() {
171 // Nothing to do. View is created visible. 176 // Nothing to do. View is created visible.
172 } 177 }
173 178
174 void PlatformViewportAndroid::Hide() { 179 void PlatformViewportAndroid::Hide() {
175 // Nothing to do. View is always visible. 180 // Nothing to do. View is always visible.
176 } 181 }
177 182
(...skipping 23 matching lines...) Expand all
201 //////////////////////////////////////////////////////////////////////////////// 206 ////////////////////////////////////////////////////////////////////////////////
202 // PlatformViewport, public: 207 // PlatformViewport, public:
203 208
204 // static 209 // static
205 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { 210 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) {
206 return scoped_ptr<PlatformViewport>( 211 return scoped_ptr<PlatformViewport>(
207 new PlatformViewportAndroid(delegate)).Pass(); 212 new PlatformViewportAndroid(delegate)).Pass();
208 } 213 }
209 214
210 } // namespace native_viewport 215 } // namespace native_viewport
OLDNEW
« no previous file with comments | « services/native_viewport/platform_viewport_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698