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

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

Issue 1406013003: [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mfoltz's comments Created 5 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 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/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "chrome/browser/media/android/router/media_router_android.h" 9 #include "chrome/browser/media/android/router/media_router_android.h"
10 #include "chrome/browser/media/router/media_router.h" 10 #include "chrome/browser/media/router/media_router.h"
11 #include "chrome/browser/media/router/media_router_factory.h" 11 #include "chrome/browser/media/router/media_router_factory.h"
12 #include "chrome/browser/media/router/media_source.h" 12 #include "chrome/browser/media/router/media_source.h"
13 #include "chrome/browser/media/router/media_source_helper.h"
14 #include "chrome/browser/media/router/presentation_request.h"
13 #include "chrome/browser/sessions/session_tab_helper.h" 15 #include "chrome/browser/sessions/session_tab_helper.h"
14 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h" 18 #include "content/public/browser/web_contents_delegate.h"
17 #include "jni/ChromeMediaRouterDialogController_jni.h" 19 #include "jni/ChromeMediaRouterDialogController_jni.h"
18 20
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
20 media_router::MediaRouterDialogControllerAndroid); 22 media_router::MediaRouterDialogControllerAndroid);
21 23
22 using base::android::ConvertJavaStringToUTF8; 24 using base::android::ConvertJavaStringToUTF8;
23 using content::WebContents; 25 using content::WebContents;
24 26
25 namespace media_router { 27 namespace media_router {
26 28
27 // static 29 // static
28 MediaRouterDialogControllerAndroid* 30 MediaRouterDialogControllerAndroid*
29 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( 31 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents(
30 WebContents* web_contents) { 32 WebContents* web_contents) {
31 DCHECK(web_contents); 33 DCHECK(web_contents);
32 // This call does nothing if the controller already exists. 34 // This call does nothing if the controller already exists.
33 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents); 35 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents);
34 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents); 36 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents);
35 } 37 }
36 38
37 void MediaRouterDialogControllerAndroid::OnSinkSelected( 39 void MediaRouterDialogControllerAndroid::OnSinkSelected(
38 JNIEnv* env, jobject obj, jstring jsink_id) { 40 JNIEnv* env, jobject obj, jstring jsink_id) {
39 scoped_ptr<CreatePresentationSessionRequest> 41 scoped_ptr<CreatePresentationSessionRequest> create_session_request(
40 request(TakePresentationRequest()); 42 TakePresentationRequest());
mlamouri (slow - plz ping) 2015/10/27 18:42:51 I think the name |create_session_request| is very
imcheng 2015/10/27 20:50:14 Why is it confusing? It is an object that represen
41 43
42 const std::string& source_id = request->media_source().id(); 44 const MediaSource::Id source_id(
43 const GURL& origin = request->frame_url().GetOrigin(); 45 create_session_request->presentation_request().GetMediaSource()).id());
46 const GURL origin(presentation_request.frame_url().GetOrigin());
44 47
45 std::vector<MediaRouteResponseCallback> route_response_callbacks; 48 std::vector<MediaRouteResponseCallback> route_response_callbacks;
46 route_response_callbacks.push_back( 49 route_response_callbacks.push_back(
47 base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse, 50 base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse,
48 base::Passed(&request))); 51 base::Passed(&create_session_request)));
49 52
50 MediaRouter* router = MediaRouterFactory::GetApiForBrowserContext( 53 MediaRouter* router = MediaRouterFactory::GetApiForBrowserContext(
51 initiator()->GetBrowserContext()); 54 initiator()->GetBrowserContext());
52 router->CreateRoute(source_id, ConvertJavaStringToUTF8(env, jsink_id), origin, 55 router->CreateRoute(source_id, ConvertJavaStringToUTF8(env, jsink_id), origin,
53 SessionTabHelper::IdForTab(initiator()), 56 SessionTabHelper::IdForTab(initiator()),
54 route_response_callbacks); 57 route_response_callbacks);
55 } 58 }
56 59
57 void MediaRouterDialogControllerAndroid::OnRouteClosed( 60 void MediaRouterDialogControllerAndroid::OnRouteClosed(
58 JNIEnv* env, 61 JNIEnv* env,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 return RegisterNativesImpl(env); 104 return RegisterNativesImpl(env);
102 } 105 }
103 106
104 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { 107 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() {
105 } 108 }
106 109
107 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { 110 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() {
108 JNIEnv* env = base::android::AttachCurrentThread(); 111 JNIEnv* env = base::android::AttachCurrentThread();
109 112
110 const MediaSource::Id& media_source_id = 113 const MediaSource::Id& media_source_id =
111 presentation_request()->media_source().id(); 114 create_session_request()->presentation_request()->GetMediaSource().id();
112 ScopedJavaLocalRef<jstring> jsource_urn = 115 ScopedJavaLocalRef<jstring> jsource_urn =
113 base::android::ConvertUTF8ToJavaString(env, media_source_id); 116 base::android::ConvertUTF8ToJavaString(env, media_source_id);
114 117
115 // If it's a single route with the same source, show the controller dialog 118 // If it's a single route with the same source, show the controller dialog
116 // instead of the device picker. 119 // instead of the device picker.
117 // TODO(avayvod): maybe this logic should be in 120 // TODO(avayvod): maybe this logic should be in
118 // PresentationServiceDelegateImpl: if the route exists for the same frame 121 // PresentationServiceDelegateImpl: if the route exists for the same frame
119 // and tab, show the route controller dialog, if not, show the device picker. 122 // and tab, show the route controller dialog, if not, show the device picker.
120 if (single_existing_route_.get() && 123 if (single_existing_route_.get() &&
121 single_existing_route_->media_source().id() == media_source_id) { 124 single_existing_route_->media_source().id() == media_source_id) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (single_existing_route_.get() && 159 if (single_existing_route_.get() &&
157 single_existing_route_->media_route_id() == routes[0].media_route_id()) { 160 single_existing_route_->media_route_id() == routes[0].media_route_id()) {
158 return; 161 return;
159 } 162 }
160 163
161 single_existing_route_.reset(new MediaRoute(routes[0])); 164 single_existing_route_.reset(new MediaRoute(routes[0]));
162 } 165 }
163 166
164 } // namespace media_router 167 } // namespace media_router
165 168
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698