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

Side by Side Diff: content/browser/android/content_video_view.cc

Issue 2353063005: Refactor ContentViewClient (1/6) (Closed)
Patch Set: fix tests Created 4 years, 2 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/android/content_video_view.h" 5 #include "content/browser/android/content_video_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "content/browser/android/content_view_core_impl.h" 10 #include "content/browser/android/content_view_core_impl.h"
11 #include "content/browser/media/android/browser_media_player_manager.h" 11 #include "content/browser/media/android/browser_media_player_manager.h"
12 #include "content/public/browser/user_metrics.h" 12 #include "content/public/browser/user_metrics.h"
13 #include "content/public/common/content_switches.h" 13 #include "content/public/common/content_switches.h"
14 #include "jni/ContentVideoView_jni.h" 14 #include "jni/ContentVideoView_jni.h"
15 15
16 using base::android::AttachCurrentThread; 16 using base::android::AttachCurrentThread;
17 using base::android::CheckException; 17 using base::android::CheckException;
18 using base::android::JavaParamRef; 18 using base::android::JavaParamRef;
19 using base::android::JavaRef;
19 using base::android::ScopedJavaGlobalRef; 20 using base::android::ScopedJavaGlobalRef;
20 using base::android::ScopedJavaLocalRef; 21 using base::android::ScopedJavaLocalRef;
21 using base::UserMetricsAction; 22 using base::UserMetricsAction;
22 using content::RecordAction; 23 using content::RecordAction;
23 24
24 namespace content { 25 namespace content {
25 26
26 namespace { 27 namespace {
27 // There can only be one content video view at a time, this holds onto that 28 // There can only be one content video view at a time, this holds onto that
28 // singleton instance. 29 // singleton instance.
(...skipping 13 matching lines...) Expand all
42 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) { 43 bool ContentVideoView::RegisterContentVideoView(JNIEnv* env) {
43 return RegisterNativesImpl(env); 44 return RegisterNativesImpl(env);
44 } 45 }
45 46
46 ContentVideoView* ContentVideoView::GetInstance() { 47 ContentVideoView* ContentVideoView::GetInstance() {
47 return g_content_video_view; 48 return g_content_video_view;
48 } 49 }
49 50
50 ContentVideoView::ContentVideoView(Client* client, 51 ContentVideoView::ContentVideoView(Client* client,
51 ContentViewCore* content_view_core, 52 ContentViewCore* content_view_core,
53 const JavaRef<jobject>& video_embedder,
52 const gfx::Size& video_natural_size) 54 const gfx::Size& video_natural_size)
53 : client_(client), weak_factory_(this) { 55 : client_(client), weak_factory_(this) {
54 DCHECK(!g_content_video_view); 56 DCHECK(!g_content_video_view);
55 j_content_video_view_ = 57 j_content_video_view_ =
56 CreateJavaObject(content_view_core, video_natural_size); 58 CreateJavaObject(content_view_core, video_embedder, video_natural_size);
57 g_content_video_view = this; 59 g_content_video_view = this;
58 } 60 }
59 61
60 ContentVideoView::~ContentVideoView() { 62 ContentVideoView::~ContentVideoView() {
61 DCHECK(g_content_video_view); 63 DCHECK(g_content_video_view);
62 JNIEnv* env = AttachCurrentThread(); 64 JNIEnv* env = AttachCurrentThread();
63 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env); 65 ScopedJavaLocalRef<jobject> content_video_view = GetJavaObject(env);
64 if (!content_video_view.is_null()) { 66 if (!content_video_view.is_null()) {
65 Java_ContentVideoView_destroyContentVideoView(env, content_video_view, 67 Java_ContentVideoView_destroyContentVideoView(env, content_video_view,
66 true); 68 true);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 155 }
154 } else { 156 } else {
155 UMA_HISTOGRAM_COUNTS( 157 UMA_HISTOGRAM_COUNTS(
156 "MobileFullscreenVideo.LandscapeDuration", 158 "MobileFullscreenVideo.LandscapeDuration",
157 playback_duration_in_milliseconds_before_orientation_change); 159 playback_duration_in_milliseconds_before_orientation_change);
158 UMA_HISTOGRAM_COUNTS( 160 UMA_HISTOGRAM_COUNTS(
159 "MobileFullscreenVideo.LandscapeRotation", orientation_changed); 161 "MobileFullscreenVideo.LandscapeRotation", orientation_changed);
160 } 162 }
161 } 163 }
162 164
163 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject( 165 JavaObjectWeakGlobalRef ContentVideoView::CreateJavaObject(
boliu 2016/09/26 21:25:24 issue with existing code, so doesn't need to be fi
Jinsuk Kim 2016/09/27 10:08:58 Acknowledged. I'll leave a TODO for a reminder bef
164 ContentViewCore* content_view_core, 166 ContentViewCore* content_view_core,
167 const JavaRef<jobject>& j_content_video_view_embedder,
165 const gfx::Size& video_natural_size) { 168 const gfx::Size& video_natural_size) {
166 JNIEnv* env = AttachCurrentThread(); 169 JNIEnv* env = AttachCurrentThread();
167 base::android::ScopedJavaLocalRef<jobject> j_content_view_core = 170 base::android::ScopedJavaLocalRef<jobject> j_content_view_core =
168 content_view_core->GetJavaObject(); 171 content_view_core->GetJavaObject();
169 if (j_content_view_core.is_null()) 172
173 if (j_content_view_core.is_null() || j_content_video_view_embedder.is_null())
170 return JavaObjectWeakGlobalRef(env, nullptr); 174 return JavaObjectWeakGlobalRef(env, nullptr);
171 175
172 return JavaObjectWeakGlobalRef( 176 return JavaObjectWeakGlobalRef(
173 env, Java_ContentVideoView_createContentVideoView( 177 env, Java_ContentVideoView_createContentVideoView(
174 env, j_content_view_core, reinterpret_cast<intptr_t>(this), 178 env, j_content_view_core, j_content_video_view_embedder,
179 reinterpret_cast<intptr_t>(this),
175 video_natural_size.width(), video_natural_size.height()) 180 video_natural_size.width(), video_natural_size.height())
176 .obj()); 181 .obj());
177 } 182 }
178 } // namespace content 183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698