1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/media/router/create_presentation_connection_request.h"
#include "chrome/browser/media/router/media_source_helper.h"
using content::PresentationSessionInfo;
using content::PresentationError;
namespace media_router {
CreatePresentationConnectionRequest::CreatePresentationConnectionRequest(
const RenderFrameHostId& render_frame_host_id,
const std::string& presentation_url,
const GURL& frame_url,
const PresentationSessionSuccessCallback& success_cb,
const PresentationSessionErrorCallback& error_cb)
: presentation_request_(render_frame_host_id, presentation_url, frame_url),
success_cb_(success_cb),
error_cb_(error_cb),
cb_invoked_(false) {
DCHECK(!success_cb.is_null());
DCHECK(!error_cb.is_null());
}
CreatePresentationConnectionRequest::~CreatePresentationConnectionRequest() {
if (!cb_invoked_) {
error_cb_.Run(content::PresentationError(
content::PRESENTATION_ERROR_UNKNOWN, "Unknown error."));
}
}
void CreatePresentationConnectionRequest::InvokeSuccessCallback(
const std::string& presentation_id,
const MediaRoute::Id& route_id) {
DCHECK(!cb_invoked_);
if (!cb_invoked_) {
success_cb_.Run(
content::PresentationSessionInfo(
presentation_request_.presentation_url(), presentation_id),
route_id);
cb_invoked_ = true;
}
}
void CreatePresentationConnectionRequest::InvokeErrorCallback(
const content::PresentationError& error) {
DCHECK(!cb_invoked_);
if (!cb_invoked_) {
error_cb_.Run(error);
cb_invoked_ = true;
}
}
// static
void CreatePresentationConnectionRequest::HandleRouteResponse(
scoped_ptr<CreatePresentationConnectionRequest> presentation_request,
const MediaRoute* route,
const std::string& presentation_id,
const std::string& error) {
if (!route) {
presentation_request->InvokeErrorCallback(
content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, error));
} else {
presentation_request->InvokeSuccessCallback(presentation_id,
route->media_route_id());
}
}
} // namespace media_router
|