Chromium Code Reviews| Index: chrome/browser/media/android/router/media_router_android.cc |
| diff --git a/chrome/browser/media/android/router/media_router_android.cc b/chrome/browser/media/android/router/media_router_android.cc |
| index 218cec24451098e392533e2099622c152d43e0cf..0d01937b888964884a329c04c55c07deb57d2fe9 100644 |
| --- a/chrome/browser/media/android/router/media_router_android.cc |
| +++ b/chrome/browser/media/android/router/media_router_android.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/android/jni_string.h" |
| #include "base/guid.h" |
| #include "base/logging.h" |
| +#include "chrome/browser/media/router/media_routes_observer.h" |
| #include "chrome/browser/media/router/media_sinks_observer.h" |
| #include "jni/ChromeMediaRouter_jni.h" |
| @@ -167,12 +168,15 @@ void MediaRouterAndroid::UnregisterMediaSinksObserver( |
| void MediaRouterAndroid::RegisterMediaRoutesObserver( |
| MediaRoutesObserver* observer) { |
| - NOTIMPLEMENTED(); |
| + DVLOG(2) << "Added MediaRoutesObserver: " << observer; |
| + routes_observers_.AddObserver(observer); |
| } |
| void MediaRouterAndroid::UnregisterMediaRoutesObserver( |
| MediaRoutesObserver* observer) { |
| - NOTIMPLEMENTED(); |
| + if (!routes_observers_.HasObserver(observer)) |
|
mlamouri (slow - plz ping)
2015/08/18 22:39:37
nit: I don't think this check is necessary.
whywhat
2015/08/19 00:26:43
I copied it from the desktop implementation :) Not
|
| + return; |
| + routes_observers_.RemoveObserver(observer); |
| } |
| void MediaRouterAndroid::RegisterIssuesObserver(IssuesObserver* observer) { |
| @@ -197,10 +201,10 @@ void MediaRouterAndroid::OnSinksReceived( |
| JNIEnv* env, |
| jobject obj, |
| jstring jsource_urn, |
| - jint count) { |
| + jint jcount) { |
| std::vector<MediaSink> sinks_converted; |
| - sinks_converted.reserve(count); |
| - for (int i = 0; i < count; ++i) { |
| + sinks_converted.reserve(jcount); |
| + for (int i = 0; i < jcount; ++i) { |
| ScopedJavaLocalRef<jstring> jsink_urn = |
| Java_ChromeMediaRouter_getSinkUrn( |
| env, java_media_router_.obj(), jsource_urn, i); |
| @@ -243,6 +247,8 @@ void MediaRouterAndroid::OnRouteCreated( |
| callback.Run(route.get(), request->presentation_id, std::string()); |
| create_route_requests_.Remove(jcreate_route_request_id); |
| + active_routes_.add(route->media_route_id(), route.Pass()); |
| + UpdateRoutesObservers(); |
| } |
| void MediaRouterAndroid::OnRouteCreationError( |
| @@ -263,4 +269,23 @@ void MediaRouterAndroid::OnRouteCreationError( |
| create_route_requests_.Remove(jcreate_route_request_id); |
| } |
| +void MediaRouterAndroid::OnRouteClosed(JNIEnv* env, |
| + jobject obj, |
| + jstring jmedia_route_id) { |
| + MediaRoute::Id route_id = ConvertJavaStringToUTF8(env, jmedia_route_id); |
| + active_routes_.erase(route_id); |
| + |
| + UpdateRoutesObservers(); |
| +} |
| + |
| +void MediaRouterAndroid::UpdateRoutesObservers() { |
| + std::vector<MediaRoute> routes; |
| + routes.reserve(active_routes_.size()); |
| + for (auto it = active_routes_.begin(); it != active_routes_.end(); ++it) |
|
mlamouri (slow - plz ping)
2015/08/18 22:39:37
nit: const auto& it
also, can you do: for (const
whywhat
2015/08/19 00:26:43
A const reference to iterator can't be ++'ed
|
| + routes.push_back(*it->second); |
|
mlamouri (slow - plz ping)
2015/08/18 22:39:37
nit:
routes.push_back(*(it->second));
|
| + |
| + FOR_EACH_OBSERVER(MediaRoutesObserver, routes_observers_, |
| + OnRoutesUpdated(routes)); |
| +} |
| + |
| } // namespace media_router |