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

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: Remove DCHECK since tests are hitting the code path 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<url::Origin>& origins) { 178 const std::vector<url::Origin>& 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<MediaSink> sink_list;
189 sink_list.reserve(sinks.size());
190 for (size_t i = 0; i < sinks.size(); ++i)
191 sink_list.push_back(sinks[i].To<MediaSink>());
192
193 auto* sinks_query = it->second.get(); 187 auto* sinks_query = it->second.get();
194 sinks_query->has_cached_result = true; 188 sinks_query->has_cached_result = true;
195 sinks_query->origins = origins; 189 sinks_query->origins = origins;
196 sinks_query->cached_sink_list.swap(sink_list); 190 sinks_query->cached_sink_list = sinks;
197 191
198 if (!sinks_query->observers.might_have_observers()) { 192 if (!sinks_query->observers.might_have_observers()) {
199 DVLOG_WITH_INSTANCE(1) 193 DVLOG_WITH_INSTANCE(1)
200 << "Received sink list without any active observers: " << media_source; 194 << "Received sink list without any active observers: " << media_source;
201 } else { 195 } else {
202 for (auto& observer : sinks_query->observers) { 196 for (auto& observer : sinks_query->observers) {
203 observer.OnSinksUpdated(sinks_query->cached_sink_list, 197 observer.OnSinksUpdated(sinks_query->cached_sink_list,
204 sinks_query->origins); 198 sinks_query->origins);
205 } 199 }
206 } 200 }
207 } 201 }
208 202
209 void MediaRouterMojoImpl::OnRoutesUpdated( 203 void MediaRouterMojoImpl::OnRoutesUpdated(
210 std::vector<mojom::MediaRoutePtr> routes, 204 const std::vector<MediaRoute>& routes,
211 const std::string& media_source, 205 const std::string& media_source,
212 const std::vector<std::string>& joinable_route_ids) { 206 const std::vector<std::string>& joinable_route_ids) {
213 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 207 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
214 208
215 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated"; 209 DVLOG_WITH_INSTANCE(1) << "OnRoutesUpdated";
216 auto it = routes_queries_.find(media_source); 210 auto it = routes_queries_.find(media_source);
217 if (it == routes_queries_.end() || 211 if (it == routes_queries_.end() ||
218 !(it->second->observers.might_have_observers())) { 212 !(it->second->observers.might_have_observers())) {
219 DVLOG_WITH_INSTANCE(1) 213 DVLOG_WITH_INSTANCE(1)
220 << "Received route list without any active observers: " << media_source; 214 << "Received route list without any active observers: " << media_source;
221 return; 215 return;
222 } 216 }
223 217
224 std::vector<MediaRoute> routes_converted;
225 routes_converted.reserve(routes.size());
226 for (size_t i = 0; i < routes.size(); ++i)
227 routes_converted.push_back(routes[i].To<MediaRoute>());
228
229 for (auto& observer : it->second->observers) 218 for (auto& observer : it->second->observers)
230 observer.OnRoutesUpdated(routes_converted, joinable_route_ids); 219 observer.OnRoutesUpdated(routes, joinable_route_ids);
231 } 220 }
232 221
233 void MediaRouterMojoImpl::RouteResponseReceived( 222 void MediaRouterMojoImpl::RouteResponseReceived(
234 const std::string& presentation_id, 223 const std::string& presentation_id,
235 bool is_incognito, 224 bool is_incognito,
236 const std::vector<MediaRouteResponseCallback>& callbacks, 225 const std::vector<MediaRouteResponseCallback>& callbacks,
237 bool is_join, 226 bool is_join,
238 mojom::MediaRoutePtr media_route, 227 const base::Optional<MediaRoute>& media_route,
239 const base::Optional<std::string>& error_text, 228 const base::Optional<std::string>& error_text,
240 mojom::RouteRequestResultCode result_code) { 229 RouteRequestResult::ResultCode result_code) {
241 std::unique_ptr<RouteRequestResult> result; 230 std::unique_ptr<RouteRequestResult> result;
242 if (media_route.is_null()) { 231 if (!media_route) {
243 // An error occurred. 232 // An error occurred.
244 const std::string& error = (error_text && !error_text->empty()) 233 const std::string& error = (error_text && !error_text->empty())
245 ? *error_text : std::string("Unknown error."); 234 ? *error_text : std::string("Unknown error.");
246 result = RouteRequestResult::FromError( 235 result = RouteRequestResult::FromError(error, result_code);
247 error, mojo::RouteRequestResultCodeFromMojo(result_code)); 236 } else if (media_route->is_incognito() != is_incognito) {
248 } else if (media_route->is_incognito != is_incognito) {
249 std::string error = base::StringPrintf( 237 std::string error = base::StringPrintf(
250 "Mismatch in incognito status: request = %d, response = %d", 238 "Mismatch in incognito status: request = %d, response = %d",
251 is_incognito, media_route->is_incognito); 239 is_incognito, media_route->is_incognito());
252 result = RouteRequestResult::FromError( 240 result = RouteRequestResult::FromError(
253 error, RouteRequestResult::INCOGNITO_MISMATCH); 241 error, RouteRequestResult::INCOGNITO_MISMATCH);
254 } else { 242 } else {
255 result = RouteRequestResult::FromSuccess( 243 result =
256 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id); 244 RouteRequestResult::FromSuccess(media_route.value(), presentation_id);
257 } 245 }
258 246
259 if (is_join) 247 if (is_join)
260 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); 248 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code());
261 else 249 else
262 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code()); 250 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code());
263 251
264 RunRouteRequestCallbacks(std::move(result), callbacks); 252 RunRouteRequestCallbacks(std::move(result), callbacks);
265 } 253 }
266 254
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 // Sinks are now available. Tell MRPM to start all sink queries again. 693 // Sinks are now available. Tell MRPM to start all sink queries again.
706 for (const auto& source_and_query : sinks_queries_) { 694 for (const auto& source_and_query : sinks_queries_) {
707 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, 695 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks,
708 base::Unretained(this), source_and_query.first)); 696 base::Unretained(this), source_and_query.first));
709 } 697 }
710 } 698 }
711 } 699 }
712 700
713 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged( 701 void MediaRouterMojoImpl::OnPresentationConnectionStateChanged(
714 const std::string& route_id, 702 const std::string& route_id,
715 mojom::MediaRouter::PresentationConnectionState state) { 703 content::PresentationConnectionState state) {
716 NotifyPresentationConnectionStateChange( 704 NotifyPresentationConnectionStateChange(route_id, state);
717 route_id, mojo::PresentationConnectionStateFromMojo(state));
718 } 705 }
719 706
720 void MediaRouterMojoImpl::OnPresentationConnectionClosed( 707 void MediaRouterMojoImpl::OnPresentationConnectionClosed(
721 const std::string& route_id, 708 const std::string& route_id,
722 mojom::MediaRouter::PresentationConnectionCloseReason reason, 709 content::PresentationConnectionCloseReason reason,
723 const std::string& message) { 710 const std::string& message) {
724 NotifyPresentationConnectionClose( 711 NotifyPresentationConnectionClose(route_id, reason, message);
725 route_id, mojo::PresentationConnectionCloseReasonFromMojo(reason),
726 message);
727 } 712 }
728 713
729 void MediaRouterMojoImpl::OnTerminateRouteResult( 714 void MediaRouterMojoImpl::OnTerminateRouteResult(
730 const MediaRoute::Id& route_id, 715 const MediaRoute::Id& route_id,
731 const base::Optional<std::string>& error_text, 716 const base::Optional<std::string>& error_text,
732 mojom::RouteRequestResultCode result_code) { 717 RouteRequestResult::ResultCode result_code) {
733 if (result_code != mojom::RouteRequestResultCode::OK) { 718 if (result_code != RouteRequestResult::OK) {
734 LOG(WARNING) << "Failed to terminate route " << route_id 719 LOG(WARNING) << "Failed to terminate route " << route_id
735 << ": result_code = " << result_code << ", " 720 << ": result_code = " << result_code << ", "
736 << error_text.value_or(std::string()); 721 << error_text.value_or(std::string());
737 } 722 }
738 MediaRouterMojoMetrics::RecordMediaRouteProviderTerminateRoute( 723 MediaRouterMojoMetrics::RecordMediaRouteProviderTerminateRoute(result_code);
739 mojo::RouteRequestResultCodeFromMojo(result_code));
740 } 724 }
741 725
742 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 726 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
743 const MediaSource::Id& source_id) { 727 const MediaSource::Id& source_id) {
744 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id; 728 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
745 // No need to call MRPM if there are no sinks available. 729 // No need to call MRPM if there are no sinks available.
746 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) 730 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE)
747 return; 731 return;
748 732
749 // No need to call MRPM if all observers have been removed in the meantime. 733 // 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
945 base::Unretained(this), source_id)); 929 base::Unretained(this), source_id));
946 } 930 }
947 931
948 void MediaRouterMojoImpl::DoUpdateMediaSinks( 932 void MediaRouterMojoImpl::DoUpdateMediaSinks(
949 const MediaSource::Id& source_id) { 933 const MediaSource::Id& source_id) {
950 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; 934 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id;
951 media_route_provider_->UpdateMediaSinks(source_id); 935 media_route_provider_->UpdateMediaSinks(source_id);
952 } 936 }
953 937
954 } // namespace media_router 938 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698