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

Side by Side Diff: chrome/browser/media/router/mojo/media_router_mojo_impl.cc

Issue 2666873006: [Media Router] Convert to use typemaps for media_router.mojom. (Closed)
Patch Set: Created 3 years, 10 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/router/mojo/media_router_mojo_impl.h" 5 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "chrome/browser/media/router/issues_observer.h" 19 #include "chrome/browser/media/router/issues_observer.h"
20 #include "chrome/browser/media/router/media_router_factory.h" 20 #include "chrome/browser/media/router/media_router_factory.h"
21 #include "chrome/browser/media/router/media_routes_observer.h" 21 #include "chrome/browser/media/router/media_routes_observer.h"
22 #include "chrome/browser/media/router/media_sinks_observer.h" 22 #include "chrome/browser/media/router/media_sinks_observer.h"
23 #include "chrome/browser/media/router/media_source_helper.h" 23 #include "chrome/browser/media/router/media_source_helper.h"
24 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h" 24 #include "chrome/browser/media/router/mojo/media_route_provider_util_win.h"
25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h" 25 #include "chrome/browser/media/router/mojo/media_router_mojo_metrics.h"
26 #include "chrome/browser/media/router/mojo/media_router_type_converters.h"
27 #include "chrome/browser/media/router/route_message.h" 26 #include "chrome/browser/media/router/route_message.h"
28 #include "chrome/browser/media/router/route_message_observer.h" 27 #include "chrome/browser/media/router/route_message_observer.h"
29 #include "chrome/browser/sessions/session_tab_helper.h" 28 #include "chrome/browser/sessions/session_tab_helper.h"
30 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
31 #include "extensions/browser/process_manager.h" 30 #include "extensions/browser/process_manager.h"
32 31
33 #define DVLOG_WITH_INSTANCE(level) \ 32 #define DVLOG_WITH_INSTANCE(level) \
34 DVLOG(level) << "MR #" << instance_id_ << ": " 33 DVLOG(level) << "MR #" << instance_id_ << ": "
35 34
36 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " 35 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": "
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 } 167 }
169 168
170 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { 169 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) {
171 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
172 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; 171 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title;
173 issue_manager_.AddIssue(issue); 172 issue_manager_.AddIssue(issue);
174 } 173 }
175 174
176 void MediaRouterMojoImpl::OnSinksReceived( 175 void MediaRouterMojoImpl::OnSinksReceived(
177 const std::string& media_source, 176 const std::string& media_source,
178 std::vector<mojom::MediaSinkPtr> sinks, 177 const std::vector<MediaSink>& sinks,
179 const std::vector<std::string>& origins) { 178 const std::vector<std::string>& origins) {
180 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 179 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
181 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived"; 180 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived";
182 auto it = sinks_queries_.find(media_source); 181 auto it = sinks_queries_.find(media_source);
183 if (it == sinks_queries_.end()) { 182 if (it == sinks_queries_.end()) {
184 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery."; 183 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery.";
185 return; 184 return;
186 } 185 }
187 186
188 std::vector<GURL> origin_list; 187 std::vector<GURL> origin_list;
189 origin_list.reserve(origins.size()); 188 origin_list.reserve(origins.size());
190 for (size_t i = 0; i < origins.size(); ++i) { 189 for (size_t i = 0; i < origins.size(); ++i) {
191 GURL origin(origins[i]); 190 GURL origin(origins[i]);
192 if (!origin.is_valid()) { 191 if (!origin.is_valid()) {
193 LOG(WARNING) << "Received invalid origin: " << origin 192 LOG(WARNING) << "Received invalid origin: " << origin
194 << ". Dropping result."; 193 << ". Dropping result.";
195 return; 194 return;
196 } 195 }
197 origin_list.push_back(origin); 196 origin_list.push_back(origin);
198 } 197 }
199 198
200 std::vector<MediaSink> sink_list;
201 sink_list.reserve(sinks.size());
202 for (size_t i = 0; i < sinks.size(); ++i)
203 sink_list.push_back(sinks[i].To<MediaSink>());
204
205 auto* sinks_query = it->second.get(); 199 auto* sinks_query = it->second.get();
206 sinks_query->has_cached_result = true; 200 sinks_query->has_cached_result = true;
207 sinks_query->origins.swap(origin_list); 201 sinks_query->origins.swap(origin_list);
208 sinks_query->cached_sink_list.swap(sink_list); 202 sinks_query->cached_sink_list = sinks;
209 203
210 if (!sinks_query->observers.might_have_observers()) { 204 if (!sinks_query->observers.might_have_observers()) {
211 DVLOG_WITH_INSTANCE(1) 205 DVLOG_WITH_INSTANCE(1)
212 << "Received sink list without any active observers: " << media_source; 206 << "Received sink list without any active observers: " << media_source;
213 } else { 207 } else {
214 for (auto& observer : sinks_query->observers) { 208 for (auto& observer : sinks_query->observers) {
215 observer.OnSinksUpdated(sinks_query->cached_sink_list, 209 observer.OnSinksUpdated(sinks_query->cached_sink_list,
216 sinks_query->origins); 210 sinks_query->origins);
217 } 211 }
218 } 212 }
219 } 213 }
220 214
221 void MediaRouterMojoImpl::OnRoutesUpdated( 215 void MediaRouterMojoImpl::OnRoutesUpdated(
222 std::vector<mojom::MediaRoutePtr> routes, 216 const std::vector<MediaRoute>& routes,
223 const std::string& media_source, 217 const std::string& media_source,
224 const std::vector<std::string>& joinable_route_ids) { 218 const std::vector<std::string>& joinable_route_ids) {
225 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 219 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
226 220
227 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; 221 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated";
228 auto it = routes_queries_.find(media_source); 222 auto it = routes_queries_.find(media_source);
229 if (it == routes_queries_.end() || 223 if (it == routes_queries_.end() ||
230 !(it->second->observers.might_have_observers())) { 224 !(it->second->observers.might_have_observers())) {
231 DVLOG_WITH_INSTANCE(1) 225 DVLOG_WITH_INSTANCE(1)
232 << "Received route list without any active observers: " << media_source; 226 << "Received route list without any active observers: " << media_source;
233 return; 227 return;
234 } 228 }
235 229
236 std::vector<MediaRoute> routes_converted;
237 routes_converted.reserve(routes.size());
238 for (size_t i = 0; i < routes.size(); ++i)
239 routes_converted.push_back(routes[i].To<MediaRoute>());
240
241 for (auto& observer : it->second->observers) 230 for (auto& observer : it->second->observers)
242 observer.OnRoutesUpdated(routes_converted, joinable_route_ids); 231 observer.OnRoutesUpdated(routes, joinable_route_ids);
243 } 232 }
244 233
245 void MediaRouterMojoImpl::RouteResponseReceived( 234 void MediaRouterMojoImpl::RouteResponseReceived(
246 const std::string& presentation_id, 235 const std::string& presentation_id,
247 bool is_incognito, 236 bool is_incognito,
248 const std::vector<MediaRouteResponseCallback>& callbacks, 237 const std::vector<MediaRouteResponseCallback>& callbacks,
249 bool is_join, 238 bool is_join,
250 mojom::MediaRoutePtr media_route, 239 const base::Optional<MediaRoute>& media_route,
251 const base::Optional<std::string>& error_text, 240 const base::Optional<std::string>& error_text,
252 mojom::RouteRequestResultCode result_code) { 241 RouteRequestResult::ResultCode result_code) {
253 std::unique_ptr<RouteRequestResult> result; 242 std::unique_ptr<RouteRequestResult> result;
254 if (media_route.is_null()) { 243 if (!media_route) {
255 // An error occurred. 244 // An error occurred.
256 const std::string& error = (error_text && !error_text->empty()) 245 const std::string& error = (error_text && !error_text->empty())
257 ? *error_text : std::string("Unknown error."); 246 ? *error_text : std::string("Unknown error.");
258 result = RouteRequestResult::FromError( 247 result = RouteRequestResult::FromError(error, result_code);
259 error, mojo::RouteRequestResultCodeFromMojo(result_code)); 248 } else if (media_route->is_incognito() != is_incognito) {
260 } else if (media_route->is_incognito != is_incognito) {
261 std::string error = base::StringPrintf( 249 std::string error = base::StringPrintf(
262 "Mismatch in incognito status: request = %d, response = %d", 250 "Mismatch in incognito status: request = %d, response = %d",
263 is_incognito, media_route->is_incognito); 251 is_incognito, media_route->is_incognito());
264 result = RouteRequestResult::FromError( 252 result = RouteRequestResult::FromError(
265 error, RouteRequestResult::INCOGNITO_MISMATCH); 253 error, RouteRequestResult::INCOGNITO_MISMATCH);
266 } else { 254 } else {
267 result = RouteRequestResult::FromSuccess( 255 result =
268 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id); 256 RouteRequestResult::FromSuccess(media_route.value(), presentation_id);
269 } 257 }
270 258
271 if (is_join) 259 if (is_join)
272 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); 260 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code());
273 else 261 else
274 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code()); 262 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code());
275 263
276 RunRouteRequestCallbacks(std::move(result), callbacks); 264 RunRouteRequestCallbacks(std::move(result), callbacks);
277 } 265 }
278 266
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 // Sinks are now available. Tell MRPM to start all sink queries again. 735 // Sinks are now available. Tell MRPM to start all sink queries again.
748 for (const auto& source_and_query : sinks_queries_) { 736 for (const auto& source_and_query : sinks_queries_) {
749 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 737 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
750 base::Unretained(this), source_and_query.first)); 738 base::Unretained(this), source_and_query.first));
751 } 739 }
752 } 740 }
753 } 741 }
754 742
755 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( 743 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged(
756 const std::string& route_id, 744 const std::string& route_id,
757 mojom::MediaRouter::PresentationConnectionState state) { 745 content::PresentationConnectionState state) {
758 NotifyPresentationConnectionStateChange( 746 NotifyPresentationConnectionStateChange(route_id, state);
759 route_id, mojo::PresentationConnectionStateFromMojo(state));
760 } 747 }
761 748
762 void MediaRouterMojoImpl::OnPresentationConnectionClosed( 749 void MediaRouterMojoImpl::OnPresentationConnectionClosed(
763 const std::string& route_id, 750 const std::string& route_id,
764 mojom::MediaRouter::PresentationConnectionCloseReason reason, 751 content::PresentationConnectionCloseReason reason,
765 const std::string& message) { 752 const std::string& message) {
766 NotifyPresentationConnectionClose( 753 NotifyPresentationConnectionClose(route_id, reason, message);
767 route_id, mojo::PresentationConnectionCloseReasonFromMojo(reason),
768 message);
769 } 754 }
770 755
771 void MediaRouterMojoImpl::OnTerminateRouteResult( 756 void MediaRouterMojoImpl::OnTerminateRouteResult(
772 const MediaRoute::Id& route_id, 757 const MediaRoute::Id& route_id,
773 const base::Optional<std::string>& error_text, 758 const base::Optional<std::string>& error_text,
774 mojom::RouteRequestResultCode result_code) { 759 RouteRequestResult::ResultCode result_code) {
775 if (result_code != mojom::RouteRequestResultCode::OK) { 760 if (result_code != RouteRequestResult::OK) {
776 LOG(WARNING) << "Failed to terminate route " << route_id 761 LOG(WARNING) << "Failed to terminate route " << route_id
777 << ": result_code = " << result_code << ", " 762 << ": result_code = " << result_code << ", "
778 << error_text.value_or(std::string()); 763 << error_text.value_or(std::string());
779 } 764 }
780 MediaRouterMojoMetrics::RecordMediaRouteProviderTerminateRoute( 765 MediaRouterMojoMetrics::RecordMediaRouteProviderTerminateRoute(result_code);
781 mojo::RouteRequestResultCodeFromMojo(result_code));
782 } 766 }
783 767
784 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 768 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
785 const MediaSource::Id& source_id) { 769 const MediaSource::Id& source_id) {
786 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; 770 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
787 // No need to call MRPM if there are no sinks available. 771 // No need to call MRPM if there are no sinks available.
788 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) 772 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE)
789 return; 773 return;
790 774
791 // No need to call MRPM if all observers have been removed in the meantime. 775 // No need to call MRPM if all observers have been removed in the meantime.
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 base::Unretained(this), source_id)); 971 base::Unretained(this), source_id));
988 } 972 }
989 973
990 void MediaRouterMojoImpl::DoUpdateMediaSinks( 974 void MediaRouterMojoImpl::DoUpdateMediaSinks(
991 const MediaSource::Id& source_id) { 975 const MediaSource::Id& source_id) {
992 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; 976 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id;
993 media_route_provider_->UpdateMediaSinks(source_id); 977 media_route_provider_->UpdateMediaSinks(source_id);
994 } 978 }
995 979
996 } // namespace media_router 980 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698