| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/media/router/create_presentation_connection_request.h" | |
| 6 | |
| 7 #include "chrome/browser/media/router/media_source_helper.h" | |
| 8 | |
| 9 using content::PresentationSessionInfo; | |
| 10 using content::PresentationError; | |
| 11 | |
| 12 namespace media_router { | |
| 13 | |
| 14 CreatePresentationConnectionRequest::CreatePresentationConnectionRequest( | |
| 15 const RenderFrameHostId& render_frame_host_id, | |
| 16 const std::string& presentation_url, | |
| 17 const GURL& frame_url, | |
| 18 const PresentationSessionSuccessCallback& success_cb, | |
| 19 const PresentationSessionErrorCallback& error_cb) | |
| 20 : presentation_request_(render_frame_host_id, presentation_url, frame_url), | |
| 21 success_cb_(success_cb), | |
| 22 error_cb_(error_cb), | |
| 23 cb_invoked_(false) { | |
| 24 DCHECK(!success_cb.is_null()); | |
| 25 DCHECK(!error_cb.is_null()); | |
| 26 } | |
| 27 | |
| 28 CreatePresentationConnectionRequest::~CreatePresentationConnectionRequest() { | |
| 29 if (!cb_invoked_) { | |
| 30 error_cb_.Run(content::PresentationError( | |
| 31 content::PRESENTATION_ERROR_UNKNOWN, "Unknown error.")); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 void CreatePresentationConnectionRequest::InvokeSuccessCallback( | |
| 36 const std::string& presentation_id, | |
| 37 const MediaRoute::Id& route_id) { | |
| 38 DCHECK(!cb_invoked_); | |
| 39 if (!cb_invoked_) { | |
| 40 success_cb_.Run( | |
| 41 content::PresentationSessionInfo( | |
| 42 presentation_request_.presentation_url(), presentation_id), | |
| 43 route_id); | |
| 44 cb_invoked_ = true; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 void CreatePresentationConnectionRequest::InvokeErrorCallback( | |
| 49 const content::PresentationError& error) { | |
| 50 DCHECK(!cb_invoked_); | |
| 51 if (!cb_invoked_) { | |
| 52 error_cb_.Run(error); | |
| 53 cb_invoked_ = true; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 void CreatePresentationConnectionRequest::HandleRouteResponse( | |
| 59 scoped_ptr<CreatePresentationConnectionRequest> presentation_request, | |
| 60 const MediaRoute* route, | |
| 61 const std::string& presentation_id, | |
| 62 const std::string& error) { | |
| 63 if (!route) { | |
| 64 presentation_request->InvokeErrorCallback( | |
| 65 content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, error)); | |
| 66 } else { | |
| 67 presentation_request->InvokeSuccessCallback(presentation_id, | |
| 68 route->media_route_id()); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 } // namespace media_router | |
| OLD | NEW |