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
3 // found in the LICENSE file.
5 #include "chrome/browser/media/router/create_presentation_session_request.h"
7 #include "chrome/browser/media/router/media_source_helper.h"
9 using content::PresentationSessionInfo
;
10 using content::PresentationError
;
12 namespace media_router
{
14 CreatePresentationSessionRequest::CreatePresentationSessionRequest(
15 const std::string
& presentation_url
,
16 const GURL
& frame_url
,
17 const PresentationSessionSuccessCallback
& success_cb
,
18 const PresentationSessionErrorCallback
& error_cb
)
19 : media_source_(MediaSourceForPresentationUrl(presentation_url
)),
20 frame_url_(frame_url
),
21 success_cb_(success_cb
),
24 DCHECK(!success_cb
.is_null());
25 DCHECK(!error_cb
.is_null());
28 CreatePresentationSessionRequest::~CreatePresentationSessionRequest() {
30 error_cb_
.Run(content::PresentationError(
31 content::PRESENTATION_ERROR_UNKNOWN
, "Unknown error."));
35 void CreatePresentationSessionRequest::InvokeSuccessCallback(
36 const std::string
& presentation_id
,
37 const MediaRoute::Id
& route_id
) {
40 // Overwrite presentation ID.
42 content::PresentationSessionInfo(
43 PresentationUrlFromMediaSource(media_source_
), presentation_id
),
49 void CreatePresentationSessionRequest::InvokeErrorCallback(
50 const content::PresentationError
& error
) {
59 void CreatePresentationSessionRequest::HandleRouteResponse(
60 scoped_ptr
<CreatePresentationSessionRequest
> presentation_request
,
61 const MediaRoute
* route
,
62 const std::string
& presentation_id
,
63 const std::string
& error
) {
65 presentation_request
->InvokeErrorCallback(
66 content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN
, error
));
68 presentation_request
->InvokeSuccessCallback(presentation_id
,
69 route
->media_route_id());
73 } // namespace media_router