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

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

Issue 1173753003: [Media Router] Implement JoinRoute + update CreateRoute API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/media_router_mojo_impl.h" 5 #include "chrome/browser/media/router/media_router_mojo_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "chrome/browser/media/router/media_router_mojo_impl_factory.h" 11 #include "chrome/browser/media/router/media_router_mojo_impl_factory.h"
12 #include "chrome/browser/media/router/media_router_type_converters.h" 12 #include "chrome/browser/media/router/media_router_type_converters.h"
13 #include "chrome/browser/media/router/media_routes_observer.h" 13 #include "chrome/browser/media/router/media_routes_observer.h"
14 #include "chrome/browser/media/router/media_sinks_observer.h" 14 #include "chrome/browser/media/router/media_sinks_observer.h"
15 #include "extensions/browser/process_manager.h" 15 #include "extensions/browser/process_manager.h"
16 16
17 #define DVLOG_WITH_INSTANCE(level) \ 17 #define DVLOG_WITH_INSTANCE(level) \
18 DVLOG(level) << "MR #" << instance_id_ << ": " 18 DVLOG(level) << "MR #" << instance_id_ << ": "
19 19
20 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": " 20 #define DLOG_WITH_INSTANCE(level) DLOG(level) << "MR #" << instance_id_ << ": "
21 21
22 namespace media_router { 22 namespace media_router {
23 namespace { 23 namespace {
24 24
25 // Converts the callback result of calling Mojo CreateRoute() into a local 25 // Converts the callback result of calling Mojo CreateRoute()/JoinRoute()
26 // callback. 26 // into a local callback.
27 void CreateRouteFinished(const MediaSink::Id& sink_id, 27 void RouteResponseReceived(const MediaRouteResponseCallback& callback,
28 const MediaRouteResponseCallback& callback, 28 interfaces::MediaRoutePtr media_route,
29 interfaces::MediaRoutePtr media_route, 29 const mojo::String& error_text) {
30 const mojo::String& error_text) {
31 if (media_route.is_null()) { 30 if (media_route.is_null()) {
32 // An error occurred. 31 // An error occurred.
33 DCHECK(!error_text.is_null()); 32 DCHECK(!error_text.is_null());
34 callback.Run(nullptr, !error_text.get().empty() ? error_text.get() 33 callback.Run(nullptr, !error_text.get().empty() ? error_text.get()
35 : "Unknown error."); 34 : "Unknown error.");
36 return; 35 return;
37 } 36 }
38 callback.Run(media_route.To<scoped_ptr<MediaRoute>>(), ""); 37 callback.Run(media_route.To<scoped_ptr<MediaRoute>>(), "");
39 } 38 }
40 39
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 routes_converted.push_back(routes[i].To<MediaRoute>()); 152 routes_converted.push_back(routes[i].To<MediaRoute>());
154 } 153 }
155 154
156 FOR_EACH_OBSERVER(MediaRoutesObserver, routes_observers_, 155 FOR_EACH_OBSERVER(MediaRoutesObserver, routes_observers_,
157 OnRoutesUpdated(routes_converted)); 156 OnRoutesUpdated(routes_converted));
158 } 157 }
159 158
160 void MediaRouterMojoImpl::CreateRoute( 159 void MediaRouterMojoImpl::CreateRoute(
161 const MediaSource::Id& source_id, 160 const MediaSource::Id& source_id,
162 const MediaSink::Id& sink_id, 161 const MediaSink::Id& sink_id,
162 const GURL& origin,
163 int tab_id,
163 const MediaRouteResponseCallback& callback) { 164 const MediaRouteResponseCallback& callback) {
164 DCHECK(thread_checker_.CalledOnValidThread()); 165 DCHECK(thread_checker_.CalledOnValidThread());
165 166
166 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, 167 if (!origin.is_empty() && !origin.is_valid()) {
167 base::Unretained(this), source_id, sink_id, callback)); 168 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin;
169 callback.Run(nullptr, "Invalid origin");
170 return;
171 }
172 RunOrDefer(base::Bind(
173 &MediaRouterMojoImpl::DoCreateRoute, base::Unretained(this), source_id,
174 sink_id, origin.is_empty() ? "" : origin.spec(), tab_id, callback));
175 }
176
177 void MediaRouterMojoImpl::JoinRoute(
178 const MediaSource::Id& source_id,
179 const std::string& presentation_id,
180 const GURL& origin,
181 int tab_id,
182 const MediaRouteResponseCallback& callback) {
183 DCHECK(thread_checker_.CalledOnValidThread());
184
185 if (!origin.is_empty() && !origin.is_valid()) {
186 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin;
187 callback.Run(nullptr, "Invalid origin");
188 return;
189 }
190 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute,
191 base::Unretained(this), source_id, presentation_id,
192 origin.is_empty() ? "" : origin.spec(), tab_id,
193 callback));
168 } 194 }
169 195
170 void MediaRouterMojoImpl::CloseRoute(const MediaRoute::Id& route_id) { 196 void MediaRouterMojoImpl::CloseRoute(const MediaRoute::Id& route_id) {
171 DCHECK(thread_checker_.CalledOnValidThread()); 197 DCHECK(thread_checker_.CalledOnValidThread());
172 198
173 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCloseRoute, 199 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCloseRoute,
174 base::Unretained(this), route_id)); 200 base::Unretained(this), route_id));
175 } 201 }
176 202
177 void MediaRouterMojoImpl::PostMessage(const MediaRoute::Id& route_id, 203 void MediaRouterMojoImpl::PostMessage(const MediaRoute::Id& route_id,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 289 }
264 290
265 void MediaRouterMojoImpl::RemoveIssuesObserver(IssuesObserver* observer) { 291 void MediaRouterMojoImpl::RemoveIssuesObserver(IssuesObserver* observer) {
266 // TODO(imcheng): Implement. (crbug.com/461815) 292 // TODO(imcheng): Implement. (crbug.com/461815)
267 NOTIMPLEMENTED(); 293 NOTIMPLEMENTED();
268 } 294 }
269 295
270 void MediaRouterMojoImpl::DoCreateRoute( 296 void MediaRouterMojoImpl::DoCreateRoute(
271 const MediaSource::Id& source_id, 297 const MediaSource::Id& source_id,
272 const MediaSink::Id& sink_id, 298 const MediaSink::Id& sink_id,
299 const std::string& origin,
300 int tab_id,
273 const MediaRouteResponseCallback& callback) { 301 const MediaRouteResponseCallback& callback) {
274 DVLOG_WITH_INSTANCE(1) << "CreateRoute " << source_id << "=>" << sink_id; 302 std::string presentation_id(base::GenerateGUID());
mark a. foltz 2015/06/10 23:18:51 I feel like this should have a prefix like "mr-" t
imcheng (use chromium acct) 2015/06/11 22:49:12 Yes we should have mr_ per the Start + Join doc.
275 mojo_media_router_->CreateRoute( 303 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id
276 source_id, sink_id, base::Bind(&CreateRouteFinished, sink_id, callback)); 304 << ", presentation ID: " << presentation_id;
305 mojo_media_router_->CreateRoute(source_id, sink_id, presentation_id, origin,
306 tab_id,
307 base::Bind(&RouteResponseReceived, callback));
308 }
309
310 void MediaRouterMojoImpl::DoJoinRoute(
311 const MediaSource::Id& source_id,
312 const std::string& presentation_id,
313 const std::string& origin,
314 int tab_id,
315 const MediaRouteResponseCallback& callback) {
316 DVLOG_WITH_INSTANCE(1) << "DoJoinRoute " << source_id
317 << ", presentation ID: " << presentation_id;
318 mojo_media_router_->JoinRoute(source_id, presentation_id, origin, tab_id,
319 base::Bind(&RouteResponseReceived, callback));
277 } 320 }
278 321
279 void MediaRouterMojoImpl::DoCloseRoute(const MediaRoute::Id& route_id) { 322 void MediaRouterMojoImpl::DoCloseRoute(const MediaRoute::Id& route_id) {
280 DVLOG_WITH_INSTANCE(1) << "CloseRoute " << route_id; 323 DVLOG_WITH_INSTANCE(1) << "DoCloseRoute " << route_id;
281 mojo_media_router_->CloseRoute(route_id); 324 mojo_media_router_->CloseRoute(route_id);
282 } 325 }
283 326
284 void MediaRouterMojoImpl::DoPostMessage(const MediaRoute::Id& route_id, 327 void MediaRouterMojoImpl::DoPostMessage(const MediaRoute::Id& route_id,
285 const std::string& message) { 328 const std::string& message) {
286 DVLOG_WITH_INSTANCE(1) << "PostMessage " << route_id; 329 DVLOG_WITH_INSTANCE(1) << "DoPostMessage " << route_id;
287 mojo_media_router_->PostMessage(route_id, message); 330 mojo_media_router_->PostMessage(route_id, message);
288 } 331 }
289 332
290 void MediaRouterMojoImpl::DoClearIssue(const Issue::Id& issue_id) { 333 void MediaRouterMojoImpl::DoClearIssue(const Issue::Id& issue_id) {
291 DVLOG_WITH_INSTANCE(1) << "ClearIssue " << issue_id; 334 DVLOG_WITH_INSTANCE(1) << "DoClearIssue " << issue_id;
292 mojo_media_router_->ClearIssue(issue_id); 335 mojo_media_router_->ClearIssue(issue_id);
293 } 336 }
294 337
295 void MediaRouterMojoImpl::DoStartObservingMediaSinks( 338 void MediaRouterMojoImpl::DoStartObservingMediaSinks(
296 const std::string& source_id) { 339 const MediaSource::Id& source_id) {
297 DVLOG_WITH_INSTANCE(1) << "StartObservingMediaSinks: " << source_id; 340 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaSinks: " << source_id;
298 mojo_media_router_->StartObservingMediaSinks(source_id); 341 mojo_media_router_->StartObservingMediaSinks(source_id);
299 } 342 }
300 343
301 void MediaRouterMojoImpl::DoStopObservingMediaSinks( 344 void MediaRouterMojoImpl::DoStopObservingMediaSinks(
302 const std::string& source_id) { 345 const MediaSource::Id& source_id) {
303 DVLOG_WITH_INSTANCE(1) << "StopObservingMediaSinks: " << source_id; 346 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaSinks: " << source_id;
304 mojo_media_router_->StopObservingMediaSinks(source_id); 347 mojo_media_router_->StopObservingMediaSinks(source_id);
305 } 348 }
306 349
307 void MediaRouterMojoImpl::DoStartObservingMediaRoutes() { 350 void MediaRouterMojoImpl::DoStartObservingMediaRoutes() {
308 DVLOG_WITH_INSTANCE(1) << "StartObservingMediaRoutes"; 351 DVLOG_WITH_INSTANCE(1) << "DoStartObservingMediaRoutes";
309 mojo_media_router_->StartObservingMediaRoutes(); 352 mojo_media_router_->StartObservingMediaRoutes();
310 } 353 }
311 354
312 void MediaRouterMojoImpl::DoStopObservingMediaRoutes() { 355 void MediaRouterMojoImpl::DoStopObservingMediaRoutes() {
313 DVLOG_WITH_INSTANCE(1) << "StopObservingMediaRoutes"; 356 DVLOG_WITH_INSTANCE(1) << "DoStopObservingMediaRoutes";
314 mojo_media_router_->StopObservingMediaRoutes(); 357 mojo_media_router_->StopObservingMediaRoutes();
315 } 358 }
316 359
317 void MediaRouterMojoImpl::EnqueueTask(const base::Closure& closure) { 360 void MediaRouterMojoImpl::EnqueueTask(const base::Closure& closure) {
318 pending_requests_.push_back(closure); 361 pending_requests_.push_back(closure);
319 DVLOG_WITH_INSTANCE(2) << "EnqueueTask (queue-length=" 362 DVLOG_WITH_INSTANCE(2) << "EnqueueTask (queue-length="
320 << pending_requests_.size() << ")"; 363 << pending_requests_.size() << ")";
321 } 364 }
322 365
323 void MediaRouterMojoImpl::RunOrDefer(const base::Closure& request) { 366 void MediaRouterMojoImpl::RunOrDefer(const base::Closure& request) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return; 401 return;
359 } 402 }
360 403
361 for (const auto& next_request : pending_requests_) 404 for (const auto& next_request : pending_requests_)
362 next_request.Run(); 405 next_request.Run();
363 406
364 pending_requests_.clear(); 407 pending_requests_.clear();
365 } 408 }
366 409
367 } // namespace media_router 410 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698