| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_MEDIA_ANDROID_ROUTER_MEDIA_ROUTER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ANDROID_ROUTER_MEDIA_ROUTER_ANDROID_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ANDROID_ROUTER_MEDIA_ROUTER_ANDROID_H_ | 6 #define CHROME_BROWSER_MEDIA_ANDROID_ROUTER_MEDIA_ROUTER_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | |
| 9 #include <stdint.h> | 8 #include <stdint.h> |
| 10 | 9 |
| 11 #include <memory> | 10 #include <memory> |
| 12 #include <unordered_map> | 11 #include <unordered_map> |
| 13 | 12 |
| 14 #include "base/android/scoped_java_ref.h" | |
| 15 #include "base/id_map.h" | 13 #include "base/id_map.h" |
| 16 #include "base/macros.h" | 14 #include "base/macros.h" |
| 17 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "chrome/browser/media/android/router/media_router_android_bridge.h" |
| 18 #include "chrome/browser/media/router/media_router_base.h" | 17 #include "chrome/browser/media/router/media_router_base.h" |
| 19 | 18 |
| 20 namespace content { | 19 namespace content { |
| 21 class BrowserContext; | 20 class BrowserContext; |
| 22 } | 21 } |
| 23 | 22 |
| 24 namespace media_router { | 23 namespace media_router { |
| 25 | 24 |
| 26 // A stub implementation of MediaRouter interface on Android. | 25 // An implementation of MediaRouter interface on Android. |
| 27 class MediaRouterAndroid : public MediaRouterBase { | 26 class MediaRouterAndroid : public MediaRouterBase { |
| 28 public: | 27 public: |
| 29 ~MediaRouterAndroid() override; | 28 ~MediaRouterAndroid() override; |
| 30 | 29 |
| 31 static bool Register(JNIEnv* env); | |
| 32 | |
| 33 const MediaRoute* FindRouteBySource(const MediaSource::Id& source_id) const; | 30 const MediaRoute* FindRouteBySource(const MediaSource::Id& source_id) const; |
| 34 | 31 |
| 35 // MediaRouter implementation. | 32 // MediaRouter implementation. |
| 36 void CreateRoute(const MediaSource::Id& source_id, | 33 void CreateRoute(const MediaSource::Id& source_id, |
| 37 const MediaSink::Id& sink_id, | 34 const MediaSink::Id& sink_id, |
| 38 const url::Origin& origin, | 35 const url::Origin& origin, |
| 39 content::WebContents* web_contents, | 36 content::WebContents* web_contents, |
| 40 const std::vector<MediaRouteResponseCallback>& callbacks, | 37 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 41 base::TimeDelta timeout, | 38 base::TimeDelta timeout, |
| 42 bool incognito) override; | 39 bool incognito) override; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 69 void OnUserGesture() override; | 66 void OnUserGesture() override; |
| 70 void SearchSinks( | 67 void SearchSinks( |
| 71 const MediaSink::Id& sink_id, | 68 const MediaSink::Id& sink_id, |
| 72 const MediaSource::Id& source_id, | 69 const MediaSource::Id& source_id, |
| 73 const std::string& search_input, | 70 const std::string& search_input, |
| 74 const std::string& domain, | 71 const std::string& domain, |
| 75 const MediaSinkSearchResponseCallback& sink_callback) override; | 72 const MediaSinkSearchResponseCallback& sink_callback) override; |
| 76 void ProvideSinks(const std::string& provider_name, | 73 void ProvideSinks(const std::string& provider_name, |
| 77 const std::vector<MediaSinkInternal>& sinks) override; | 74 const std::vector<MediaSinkInternal>& sinks) override; |
| 78 | 75 |
| 79 // The methods called by the Java counterpart. | 76 // The methods called by the Java bridge. |
| 80 | |
| 81 // Notifies the media router that information about sinks is received for | 77 // Notifies the media router that information about sinks is received for |
| 82 // a specific source URN. | 78 // a specific source id. |
| 83 void OnSinksReceived(JNIEnv* env, | 79 void OnSinksReceived(const MediaSource::Id& source_id, |
| 84 const base::android::JavaParamRef<jobject>& obj, | 80 const std::vector<MediaSink>& sinks); |
| 85 const base::android::JavaParamRef<jstring>& jsource_urn, | |
| 86 jint jcount); | |
| 87 | 81 |
| 88 // Notifies the media router about a successful route creation. | 82 // Notifies the media router about a successful route creation. |
| 89 void OnRouteCreated( | 83 void OnRouteCreated(const MediaRoute::Id& route_id, |
| 90 JNIEnv* env, | 84 const MediaSink::Id& sink_id, |
| 91 const base::android::JavaParamRef<jobject>& obj, | 85 int request_id, |
| 92 const base::android::JavaParamRef<jstring>& jmedia_route_id, | 86 bool is_local); |
| 93 const base::android::JavaParamRef<jstring>& jmedia_sink_id, | |
| 94 jint jroute_request_id, | |
| 95 jboolean jis_local); | |
| 96 | 87 |
| 97 // Notifies the media router that route creation or joining failed. | 88 // Notifies the media router that route creation or joining failed. |
| 98 void OnRouteRequestError( | 89 void OnRouteRequestError(const std::string& error_text, int request_id); |
| 99 JNIEnv* env, | |
| 100 const base::android::JavaParamRef<jobject>& obj, | |
| 101 const base::android::JavaParamRef<jstring>& jerror_text, | |
| 102 jint jroute_request_id); | |
| 103 | 90 |
| 104 // Notifies the media router when the route was closed. | 91 // Notifies the media router when the route was closed. |
| 105 void OnRouteClosed( | 92 void OnRouteClosed(const MediaRoute::Id& route_id); |
| 106 JNIEnv* env, | |
| 107 const base::android::JavaParamRef<jobject>& obj, | |
| 108 const base::android::JavaParamRef<jstring>& jmedia_route_id); | |
| 109 | 93 |
| 110 // Notifies the media router when the route was closed with an error. | 94 // Notifies the media router when the route was closed with an error. |
| 111 void OnRouteClosedWithError( | 95 void OnRouteClosedWithError(const MediaRoute::Id& route_id, |
| 112 JNIEnv* env, | 96 const std::string& message); |
| 113 const base::android::JavaParamRef<jobject>& obj, | |
| 114 const base::android::JavaParamRef<jstring>& jmedia_route_id, | |
| 115 const base::android::JavaParamRef<jstring>& jmessage); | |
| 116 | 97 |
| 117 // Notifies the media router about the result of sending a message. | 98 // Notifies the media router about the result of sending a message. |
| 118 void OnMessageSentResult(JNIEnv* env, | 99 void OnMessageSentResult(bool success, int callback_id); |
| 119 const base::android::JavaParamRef<jobject>& obj, | |
| 120 jboolean jsuccess, | |
| 121 jint jcallback_id); | |
| 122 | 100 |
| 123 // Notifies the media router about a message received from the media route. | 101 // Notifies the media router about a message received from the media route. |
| 124 void OnMessage(JNIEnv* env, | 102 void OnMessage(const MediaRoute::Id& route_id, const std::string& message); |
| 125 const base::android::JavaParamRef<jobject>& obj, | |
| 126 const base::android::JavaParamRef<jstring>& jmedia_route_id, | |
| 127 const base::android::JavaParamRef<jstring>& jmessage); | |
| 128 | 103 |
| 129 private: | 104 private: |
| 130 friend class MediaRouterFactory; | 105 friend class MediaRouterFactory; |
| 106 friend class MediaRouterAndroidTest; |
| 131 | 107 |
| 132 explicit MediaRouterAndroid(content::BrowserContext*); | 108 explicit MediaRouterAndroid(content::BrowserContext*); |
| 133 | 109 |
| 110 // Removes the route with the given id from |active_routes_| and updates the |
| 111 // registered route observers. |
| 112 void RemoveRoute(const MediaRoute::Id& route_id); |
| 113 |
| 134 // MediaRouter implementation. | 114 // MediaRouter implementation. |
| 135 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override; | 115 bool RegisterMediaSinksObserver(MediaSinksObserver* observer) override; |
| 136 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; | 116 void UnregisterMediaSinksObserver(MediaSinksObserver* observer) override; |
| 137 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; | 117 void RegisterMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| 138 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; | 118 void UnregisterMediaRoutesObserver(MediaRoutesObserver* observer) override; |
| 139 void RegisterIssuesObserver(IssuesObserver* observer) override; | 119 void RegisterIssuesObserver(IssuesObserver* observer) override; |
| 140 void UnregisterIssuesObserver(IssuesObserver* observer) override; | 120 void UnregisterIssuesObserver(IssuesObserver* observer) override; |
| 141 void RegisterRouteMessageObserver(RouteMessageObserver* observer) override; | 121 void RegisterRouteMessageObserver(RouteMessageObserver* observer) override; |
| 142 void UnregisterRouteMessageObserver(RouteMessageObserver* observer) override; | 122 void UnregisterRouteMessageObserver(RouteMessageObserver* observer) override; |
| 143 | 123 |
| 144 base::android::ScopedJavaGlobalRef<jobject> java_media_router_; | 124 void SetMediaRouterBridgeForTest(MediaRouterAndroidBridge* bridge) { |
| 125 bridge_.reset(bridge); |
| 126 } |
| 127 |
| 128 std::unique_ptr<MediaRouterAndroidBridge> bridge_; |
| 145 | 129 |
| 146 using MediaSinkObservers = std::unordered_map< | 130 using MediaSinkObservers = std::unordered_map< |
| 147 MediaSource::Id, | 131 MediaSource::Id, |
| 148 std::unique_ptr<base::ObserverList<MediaSinksObserver>>>; | 132 std::unique_ptr<base::ObserverList<MediaSinksObserver>>>; |
| 149 MediaSinkObservers sinks_observers_; | 133 MediaSinkObservers sinks_observers_; |
| 150 | 134 |
| 151 base::ObserverList<MediaRoutesObserver> routes_observers_; | 135 base::ObserverList<MediaRoutesObserver> routes_observers_; |
| 152 | 136 |
| 153 struct MediaRouteRequest { | 137 struct MediaRouteRequest { |
| 154 MediaRouteRequest( | 138 MediaRouteRequest( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 172 SendMessageCallbacks message_callbacks_; | 156 SendMessageCallbacks message_callbacks_; |
| 173 | 157 |
| 174 using MessageObservers = std::unordered_map< | 158 using MessageObservers = std::unordered_map< |
| 175 MediaRoute::Id, | 159 MediaRoute::Id, |
| 176 std::unique_ptr<base::ObserverList<RouteMessageObserver>>>; | 160 std::unique_ptr<base::ObserverList<RouteMessageObserver>>>; |
| 177 MessageObservers message_observers_; | 161 MessageObservers message_observers_; |
| 178 | 162 |
| 179 DISALLOW_COPY_AND_ASSIGN(MediaRouterAndroid); | 163 DISALLOW_COPY_AND_ASSIGN(MediaRouterAndroid); |
| 180 }; | 164 }; |
| 181 | 165 |
| 182 } // namespace media_router | 166 } // namespace media_router |
| 183 | 167 |
| 184 #endif // CHROME_BROWSER_MEDIA_ANDROID_ROUTER_MEDIA_ROUTER_ANDROID_H_ | 168 #endif // CHROME_BROWSER_MEDIA_ANDROID_ROUTER_MEDIA_ROUTER_ANDROID_H_ |
| OLD | NEW |