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

Side by Side Diff: chrome/browser/media/android/router/media_router_dialog_controller_android.cc

Issue 1534553002: [Cast, Android, Presentation API] Fix the logic for showing controller vs chooser dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix-join
Patch Set: Created 5 years 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 | « chrome/browser/media/android/router/media_router_dialog_controller_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/media/android/router/media_router_dialog_controller_and roid.h" 5 #include "chrome/browser/media/android/router/media_router_dialog_controller_and roid.h"
6 6
7 #include "base/android/context_utils.h" 7 #include "base/android/context_utils.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "chrome/browser/media/android/router/media_router_android.h" 10 #include "chrome/browser/media/android/router/media_router_android.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 TakeCreateConnectionRequest(); 86 TakeCreateConnectionRequest();
87 DCHECK(request); 87 DCHECK(request);
88 88
89 request->InvokeErrorCallback(content::PresentationError( 89 request->InvokeErrorCallback(content::PresentationError(
90 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, 90 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
91 "Dialog closed.")); 91 "Dialog closed."));
92 } 92 }
93 93
94 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( 94 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid(
95 WebContents* web_contents) 95 WebContents* web_contents)
96 : MediaRouterDialogController(web_contents), 96 : MediaRouterDialogController(web_contents) {
97 MediaRoutesObserver(MediaRouterFactory::GetApiForBrowserContext(
98 initiator()->GetBrowserContext())) {
99 JNIEnv* env = base::android::AttachCurrentThread(); 97 JNIEnv* env = base::android::AttachCurrentThread();
100 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create( 98 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create(
101 env, 99 env,
102 reinterpret_cast<jlong>(this), 100 reinterpret_cast<jlong>(this),
103 base::android::GetApplicationContext())); 101 base::android::GetApplicationContext()));
104 } 102 }
105 103
106 // static 104 // static
107 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { 105 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) {
108 return RegisterNativesImpl(env); 106 return RegisterNativesImpl(env);
109 } 107 }
110 108
111 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { 109 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() {
112 } 110 }
113 111
114 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { 112 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() {
115 JNIEnv* env = base::android::AttachCurrentThread(); 113 JNIEnv* env = base::android::AttachCurrentThread();
116 114
117 const MediaSource::Id source_id = 115 const MediaSource::Id source_id =
118 create_connection_request()->presentation_request().GetMediaSource().id(); 116 create_connection_request()->presentation_request().GetMediaSource().id();
119 ScopedJavaLocalRef<jstring> jsource_urn = 117 ScopedJavaLocalRef<jstring> jsource_urn =
120 base::android::ConvertUTF8ToJavaString(env, source_id); 118 base::android::ConvertUTF8ToJavaString(env, source_id);
121 119
122 // If it's a single route with the same source, show the controller dialog 120 // If it's a single route with the same source, show the controller dialog
123 // instead of the device picker. 121 // instead of the device picker.
124 // TODO(avayvod): maybe this logic should be in 122 // TODO(avayvod): maybe this logic should be in
125 // PresentationServiceDelegateImpl: if the route exists for the same frame 123 // PresentationServiceDelegateImpl: if the route exists for the same frame
126 // and tab, show the route controller dialog, if not, show the device picker. 124 // and tab, show the route controller dialog, if not, show the device picker.
127 if (single_existing_route_.get() && 125 MediaRouterAndroid* router = static_cast<MediaRouterAndroid*>(
128 single_existing_route_->media_source().id() == source_id) { 126 MediaRouterFactory::GetApiForBrowserContext(
127 initiator()->GetBrowserContext()));
128 const MediaRoute* matching_route = router->FindRouteBySource(source_id);
129 if (matching_route) {
129 ScopedJavaLocalRef<jstring> jmedia_route_id = 130 ScopedJavaLocalRef<jstring> jmedia_route_id =
130 base::android::ConvertUTF8ToJavaString( 131 base::android::ConvertUTF8ToJavaString(
131 env, single_existing_route_->media_route_id()); 132 env, matching_route->media_route_id());
132 133
133 Java_ChromeMediaRouterDialogController_openRouteControllerDialog( 134 Java_ChromeMediaRouterDialogController_openRouteControllerDialog(
134 env, java_dialog_controller_.obj(), jsource_urn.obj(), 135 env, java_dialog_controller_.obj(), jsource_urn.obj(),
135 jmedia_route_id.obj()); 136 jmedia_route_id.obj());
136 return; 137 return;
137 } 138 }
138 139
139 Java_ChromeMediaRouterDialogController_openRouteChooserDialog( 140 Java_ChromeMediaRouterDialogController_openRouteChooserDialog(
140 env, java_dialog_controller_.obj(), jsource_urn.obj()); 141 env, java_dialog_controller_.obj(), jsource_urn.obj());
141 } 142 }
142 143
143 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() { 144 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() {
144 JNIEnv* env = base::android::AttachCurrentThread(); 145 JNIEnv* env = base::android::AttachCurrentThread();
145 146
146 Java_ChromeMediaRouterDialogController_closeDialog( 147 Java_ChromeMediaRouterDialogController_closeDialog(
147 env, java_dialog_controller_.obj()); 148 env, java_dialog_controller_.obj());
148 } 149 }
149 150
150 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const { 151 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const {
151 JNIEnv* env = base::android::AttachCurrentThread(); 152 JNIEnv* env = base::android::AttachCurrentThread();
152 return Java_ChromeMediaRouterDialogController_isShowingDialog( 153 return Java_ChromeMediaRouterDialogController_isShowingDialog(
153 env, java_dialog_controller_.obj()); 154 env, java_dialog_controller_.obj());
154 } 155 }
155 156
156 void MediaRouterDialogControllerAndroid::OnRoutesUpdated(
157 const std::vector<MediaRoute>& routes) {
158 if (routes.size() != 1) {
159 single_existing_route_.reset();
160 return;
161 }
162
163 if (single_existing_route_.get() &&
164 single_existing_route_->media_route_id() == routes[0].media_route_id()) {
165 return;
166 }
167
168 single_existing_route_.reset(new MediaRoute(routes[0]));
169 }
170
171 } // namespace media_router 157 } // namespace media_router
172 158
OLDNEW
« no previous file with comments | « chrome/browser/media/android/router/media_router_dialog_controller_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698