Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProvider.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProvider.java b/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProvider.java |
| index d4cc4db8c07307cb8885a90d8cb5e540e66aa653..ceb104d013f09cf91564d507eb8e7860f952a9f3 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProvider.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/media/router/cast/CastMediaRouteProvider.java |
| @@ -112,17 +112,11 @@ public class CastMediaRouteProvider |
| } |
| @Override |
| - public void onRouteClosed(String routeId) { |
| - mLastRemovedRouteRecord = getClientRecordByRouteId(routeId); |
| - mClientRecords.remove(mLastRemovedRouteRecord); |
| - |
| - mManager.onRouteClosed(routeId); |
| - if (mSession != null) { |
| - for (String sessionRouteId : mSession.routeIds) { |
| - if (sessionRouteId.equals(routeId)) continue; |
| + public void onSessionClosed() { |
| + if (mSession == null) return; |
| - mManager.onRouteClosed(routeId); |
| - } |
| + for (String sessionRouteId : mSession.routeIds) { |
| + onRouteClosed(sessionRouteId); |
| } |
| mSession = null; |
| @@ -141,8 +135,11 @@ public class CastMediaRouteProvider |
| } |
| @Override |
| - public void onMessage(String routeId, String message) { |
| - mManager.onMessage(routeId, message); |
| + public void onMessage(String clientId, String message) { |
| + ClientRecord clientRecord = getClientRecordByClientId(clientId); |
| + if (clientRecord == null) return; |
| + |
| + mManager.onMessage(clientRecord.routeId, message); |
| } |
| /** |
| @@ -292,14 +289,14 @@ public class CastMediaRouteProvider |
| MediaRoute route = mRoutes.get(routeId); |
| if (route == null) { |
| - onRouteClosed(routeId); |
| + onSessionClosed(); |
| return; |
| } |
| if (mSession == null || !mSession.routeIds.contains(routeId)) { |
| mRoutes.remove(routeId); |
| - onRouteClosed(routeId); |
| + onSessionClosed(); |
| return; |
| } |
| @@ -320,6 +317,7 @@ public class CastMediaRouteProvider |
| ClientRecord client = mClientRecords.get(i); |
| if (client.routeId.equals(routeId)) mClientRecords.remove(i); |
| if (mSession != null) mSession.clientIds.remove(client.clientId); |
| + mLastRemovedRouteRecord = client; |
|
mlamouri (slow - plz ping)
2015/12/16 14:53:04
You might end up listing a `client` that doesn't m
|
| } |
| } |
| @@ -351,6 +349,8 @@ public class CastMediaRouteProvider |
| @Nullable |
| private boolean canAutoJoin(MediaSource source, String origin, int tabId) { |
| + if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_PAGE_SCOPED)) return false; |
| + |
| MediaSource currentSource = MediaSource.from(mSession.session.getSourceId()); |
| if (!currentSource.getApplicationId().equals(source.getApplicationId())) return false; |
| @@ -365,9 +365,7 @@ public class CastMediaRouteProvider |
| if (client == null) return false; |
| - if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_PAGE_SCOPED)) { |
| - return false; |
| - } else if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_ORIGIN_SCOPED)) { |
| + if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_ORIGIN_SCOPED)) { |
| return origin.equals(client.origin); |
| } else if (source.getAutoJoinPolicy().equals(MediaSource.AUTOJOIN_TAB_AND_ORIGIN_SCOPED)) { |
| return origin.equals(client.origin) && tabId == client.tabId; |
| @@ -393,6 +391,12 @@ public class CastMediaRouteProvider |
| return false; |
| } |
| + private void onRouteClosed(String routeId) { |
| + mManager.onRouteClosed(routeId); |
| + mLastRemovedRouteRecord = getClientRecordByRouteId(routeId); |
| + mClientRecords.remove(mLastRemovedRouteRecord); |
| + } |
| + |
| @Nullable |
| private ClientRecord getClientRecordByClientId(String clientId) { |
| for (ClientRecord record : mClientRecords) { |