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

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

Issue 1294133002: [Presentation API, MediaRouter] Routing from media sink selection to route creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media-router-discovery-2
Patch Set: Added comments and DCHECKs for null presentation request Created 5 years, 4 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"
10 #include "chrome/browser/media/router/media_router.h"
11 #include "chrome/browser/media/router/media_router_factory.h"
9 #include "chrome/browser/media/router/media_source.h" 12 #include "chrome/browser/media/router/media_source.h"
13 #include "chrome/browser/sessions/session_tab_helper.h"
10 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_delegate.h" 16 #include "content/public/browser/web_contents_delegate.h"
13 #include "jni/ChromeMediaRouterDialogController_jni.h" 17 #include "jni/ChromeMediaRouterDialogController_jni.h"
14 18
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
16 media_router::MediaRouterDialogControllerAndroid); 20 media_router::MediaRouterDialogControllerAndroid);
17 21
22 using base::android::ConvertJavaStringToUTF8;
18 using content::WebContents; 23 using content::WebContents;
19 24
20 namespace media_router { 25 namespace media_router {
21 26
22 // static 27 // static
23 MediaRouterDialogControllerAndroid* 28 MediaRouterDialogControllerAndroid*
24 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents( 29 MediaRouterDialogControllerAndroid::GetOrCreateForWebContents(
25 WebContents* web_contents) { 30 WebContents* web_contents) {
26 DCHECK(web_contents); 31 DCHECK(web_contents);
27 // This call does nothing if the controller already exists. 32 // This call does nothing if the controller already exists.
28 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents); 33 MediaRouterDialogControllerAndroid::CreateForWebContents(web_contents);
29 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents); 34 return MediaRouterDialogControllerAndroid::FromWebContents(web_contents);
30 } 35 }
31 36
37 void MediaRouterDialogControllerAndroid::OnSinkSelected(
38 JNIEnv* env, jobject obj, jstring jsink_id) {
39 scoped_ptr<CreatePresentationSessionRequest>
40 request(PassPresentationRequest());
41 DCHECK(request);
Wez 2015/08/18 21:50:08 You're dereferencing |request| immediately after t
whywhat 2015/08/19 13:04:29 Done.
42
43 const std::string& source_id = request->media_source().id();
44 const GURL& origin = request->frame_url().GetOrigin();
45
46 std::vector<MediaRouteResponseCallback> route_response_callbacks;
47 route_response_callbacks.push_back(
48 base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse,
49 base::Passed(&request)));
50
51 MediaRouter* router = static_cast<MediaRouterAndroid*>(
Wez 2015/08/18 21:50:08 Why are you static-casting to MediaRouterAndroid*
52 MediaRouterFactory::GetApiForBrowserContext(
53 initiator()->GetBrowserContext()));
54 DCHECK(router);
Wez 2015/08/18 21:50:08 Same here.
whywhat 2015/08/19 13:04:29 Done.
55 router->CreateRoute(source_id,
56 ConvertJavaStringToUTF8(env, jsink_id),
57 origin,
58 SessionTabHelper::IdForTab(initiator()),
59 route_response_callbacks);
60 }
61
62 void MediaRouterDialogControllerAndroid::OnDialogDismissed(
63 JNIEnv* env, jobject obj) {
64 scoped_ptr<CreatePresentationSessionRequest> request(
65 PassPresentationRequest());
66
67 // If OnDialogDismissed is called after OnSinkSelected, do nothing.
68 if (!request)
69 return;
70
71 request->MaybeInvokeErrorCallback(content::PresentationError(
72 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
73 "The device picker dialog has been dismissed"));
Wez 2015/08/18 21:50:08 Shouldn't this be a localizable string?
whywhat 2015/08/19 13:04:29 This is an error message returned to the web devel
74 }
75
32 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid( 76 MediaRouterDialogControllerAndroid::MediaRouterDialogControllerAndroid(
33 WebContents* web_contents) 77 WebContents* web_contents)
34 : MediaRouterDialogController(web_contents) { 78 : MediaRouterDialogController(web_contents) {
35 JNIEnv* env = base::android::AttachCurrentThread(); 79 JNIEnv* env = base::android::AttachCurrentThread();
36 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create( 80 java_dialog_controller_.Reset(Java_ChromeMediaRouterDialogController_create(
37 env, 81 env,
38 reinterpret_cast<jlong>(this), 82 reinterpret_cast<jlong>(this),
39 base::android::GetApplicationContext())); 83 base::android::GetApplicationContext()));
40 } 84 }
41 85
42 // static 86 // static
43 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) { 87 bool MediaRouterDialogControllerAndroid::Register(JNIEnv* env) {
44 bool ret = RegisterNativesImpl(env); 88 bool ret = RegisterNativesImpl(env);
45 // No native calls to register yet. 89 DCHECK(g_ChromeMediaRouterDialogController_clazz);
Wez 2015/08/18 21:50:08 I searched about for some relationship between thi
whywhat 2015/08/19 13:04:29 It seems like noone is doing this check any longer
46 // DCHECK(g_ChromeMediaRouterDialogController_clazz);
47 return ret; 90 return ret;
48 } 91 }
49 92
50 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() { 93 MediaRouterDialogControllerAndroid::~MediaRouterDialogControllerAndroid() {
51 } 94 }
52 95
53 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() { 96 void MediaRouterDialogControllerAndroid::CreateMediaRouterDialog() {
54 JNIEnv* env = base::android::AttachCurrentThread(); 97 JNIEnv* env = base::android::AttachCurrentThread();
55 98
56 scoped_ptr<CreatePresentationSessionRequest> presentation_request(
57 PassPresentationRequest());
58
59 ScopedJavaLocalRef<jstring> jsource_urn = 99 ScopedJavaLocalRef<jstring> jsource_urn =
60 base::android::ConvertUTF8ToJavaString( 100 base::android::ConvertUTF8ToJavaString(
61 env, presentation_request->media_source().id()); 101 env, GetPresentationRequest()->media_source().id());
62 102
63 Java_ChromeMediaRouterDialogController_createDialog( 103 Java_ChromeMediaRouterDialogController_createDialog(
64 env, java_dialog_controller_.obj(), jsource_urn.obj()); 104 env, java_dialog_controller_.obj(), jsource_urn.obj());
65 } 105 }
66 106
67 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() { 107 void MediaRouterDialogControllerAndroid::CloseMediaRouterDialog() {
68 JNIEnv* env = base::android::AttachCurrentThread(); 108 JNIEnv* env = base::android::AttachCurrentThread();
69 109
70 Java_ChromeMediaRouterDialogController_closeDialog( 110 Java_ChromeMediaRouterDialogController_closeDialog(
71 env, java_dialog_controller_.obj()); 111 env, java_dialog_controller_.obj());
72 } 112 }
73 113
74 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const { 114 bool MediaRouterDialogControllerAndroid::IsShowingMediaRouterDialog() const {
75 JNIEnv* env = base::android::AttachCurrentThread(); 115 JNIEnv* env = base::android::AttachCurrentThread();
76 return Java_ChromeMediaRouterDialogController_isShowingDialog( 116 return Java_ChromeMediaRouterDialogController_isShowingDialog(
77 env, java_dialog_controller_.obj()); 117 env, java_dialog_controller_.obj());
78 } 118 }
79 119
80 } // namespace media_router 120 } // namespace media_router
81 121
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698