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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/media/router/ChromeMediaRouter.java

Issue 2800833003: Revert of Android: Remove GetApplicationContext part 2 (Closed)
Patch Set: Created 3 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
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 package org.chromium.chrome.browser.media.router; 5 package org.chromium.chrome.browser.media.router;
6 6
7 import android.content.Context;
7 import android.support.v7.media.MediaRouter; 8 import android.support.v7.media.MediaRouter;
8 9
9 import org.chromium.base.ContextUtils;
10 import org.chromium.base.SysUtils; 10 import org.chromium.base.SysUtils;
11 import org.chromium.base.VisibleForTesting; 11 import org.chromium.base.VisibleForTesting;
12 import org.chromium.base.annotations.CalledByNative; 12 import org.chromium.base.annotations.CalledByNative;
13 import org.chromium.base.annotations.JNINamespace; 13 import org.chromium.base.annotations.JNINamespace;
14 import org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider; 14 import org.chromium.chrome.browser.media.router.cast.CastMediaRouteProvider;
15 import org.chromium.chrome.browser.media.router.cast.MediaSink; 15 import org.chromium.chrome.browser.media.router.cast.MediaSink;
16 import org.chromium.chrome.browser.media.router.cast.MediaSource; 16 import org.chromium.chrome.browser.media.router.cast.MediaSource;
17 17
18 import java.util.ArrayList; 18 import java.util.ArrayList;
19 import java.util.HashMap; 19 import java.util.HashMap;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return mSinksPerSourcePerProvider; 65 return mSinksPerSourcePerProvider;
66 } 66 }
67 67
68 @VisibleForTesting 68 @VisibleForTesting
69 protected Map<String, List<MediaSink>> getSinksPerSourceForTest() { 69 protected Map<String, List<MediaSink>> getSinksPerSourceForTest() {
70 return mSinksPerSource; 70 return mSinksPerSource;
71 } 71 }
72 72
73 /** 73 /**
74 * Obtains the {@link MediaRouter} instance given the application context. 74 * Obtains the {@link MediaRouter} instance given the application context.
75 * @param applicationContext The context to get the Android media router ser vice for.
75 * @return Null if the media router API is not supported, the service instan ce otherwise. 76 * @return Null if the media router API is not supported, the service instan ce otherwise.
76 */ 77 */
77 @Nullable 78 @Nullable
78 public static MediaRouter getAndroidMediaRouter() { 79 public static MediaRouter getAndroidMediaRouter(Context applicationContext) {
79 try { 80 try {
80 // Pre-MR1 versions of JB do not have the complete MediaRouter APIs, 81 // Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
81 // so getting the MediaRouter instance will throw an exception. 82 // so getting the MediaRouter instance will throw an exception.
82 return MediaRouter.getInstance(ContextUtils.getApplicationContext()) ; 83 return MediaRouter.getInstance(applicationContext);
83 } catch (NoSuchMethodError e) { 84 } catch (NoSuchMethodError e) {
84 return null; 85 return null;
85 } catch (NoClassDefFoundError e) { 86 } catch (NoClassDefFoundError e) {
86 // TODO(mlamouri): happens with Robolectric. 87 // TODO(mlamouri): happens with Robolectric.
87 return null; 88 return null;
88 } 89 }
89 } 90 }
90 91
91 @Override 92 @Override
92 public void onSinksReceived( 93 public void onSinksReceived(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 151 }
151 152
152 @Override 153 @Override
153 public void onMessage(String mediaRouteId, String message) { 154 public void onMessage(String mediaRouteId, String message) {
154 nativeOnMessage(mNativeMediaRouterAndroid, mediaRouteId, message); 155 nativeOnMessage(mNativeMediaRouterAndroid, mediaRouteId, message);
155 } 156 }
156 157
157 /** 158 /**
158 * Initializes the media router and its providers. 159 * Initializes the media router and its providers.
159 * @param nativeMediaRouterAndroid the handler for the native counterpart of this instance 160 * @param nativeMediaRouterAndroid the handler for the native counterpart of this instance
161 * @param applicationContext the application context to use to obtain system APIs
160 * @return an initialized {@link ChromeMediaRouter} instance 162 * @return an initialized {@link ChromeMediaRouter} instance
161 */ 163 */
162 @CalledByNative 164 @CalledByNative
163 public static ChromeMediaRouter create(long nativeMediaRouterAndroid) { 165 public static ChromeMediaRouter create(long nativeMediaRouterAndroid,
166 Context applicationContext) {
164 ChromeMediaRouter router = new ChromeMediaRouter(nativeMediaRouterAndroi d); 167 ChromeMediaRouter router = new ChromeMediaRouter(nativeMediaRouterAndroi d);
165 MediaRouteProvider provider = sRouteProviderBuilder.create(router); 168 MediaRouteProvider provider = sRouteProviderBuilder.create(applicationCo ntext, router);
166 if (provider != null) router.addMediaRouteProvider(provider); 169 if (provider != null) router.addMediaRouteProvider(provider);
167 170
168 return router; 171 return router;
169 } 172 }
170 173
171 /** 174 /**
172 * Starts background monitoring for available media sinks compatible with th e given 175 * Starts background monitoring for available media sinks compatible with th e given
173 * |sourceUrn| if the device is in a state that allows it. 176 * |sourceUrn| if the device is in a state that allows it.
174 * @param sourceId a URL to use for filtering of the available media sinks 177 * @param sourceId a URL to use for filtering of the available media sinks
175 * @return whether the monitoring started (ie. was allowed). 178 * @return whether the monitoring started (ie. was allowed).
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 boolean wasLaunched); 359 boolean wasLaunched);
357 native void nativeOnRouteRequestError( 360 native void nativeOnRouteRequestError(
358 long nativeMediaRouterAndroid, String errorText, int createRouteRequ estId); 361 long nativeMediaRouterAndroid, String errorText, int createRouteRequ estId);
359 native void nativeOnRouteClosed(long nativeMediaRouterAndroid, String mediaR outeId); 362 native void nativeOnRouteClosed(long nativeMediaRouterAndroid, String mediaR outeId);
360 native void nativeOnRouteClosedWithError( 363 native void nativeOnRouteClosedWithError(
361 long nativeMediaRouterAndroid, String mediaRouteId, String message); 364 long nativeMediaRouterAndroid, String mediaRouteId, String message);
362 native void nativeOnMessageSentResult( 365 native void nativeOnMessageSentResult(
363 long nativeMediaRouterAndroid, boolean success, int callbackId); 366 long nativeMediaRouterAndroid, boolean success, int callbackId);
364 native void nativeOnMessage(long nativeMediaRouterAndroid, String mediaRoute Id, String message); 367 native void nativeOnMessage(long nativeMediaRouterAndroid, String mediaRoute Id, String message);
365 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698