| 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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_CREATE_PRESENTATION_CONNECTION_REQUEST_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_CREATE_PRESENTATION_CONNECTION_REQUEST_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "chrome/browser/media/router/media_route.h" | |
| 12 #include "chrome/browser/media/router/media_source.h" | |
| 13 #include "chrome/browser/media/router/presentation_request.h" | |
| 14 #include "chrome/browser/media/router/render_frame_host_id.h" | |
| 15 #include "content/public/browser/presentation_service_delegate.h" | |
| 16 #include "url/gurl.h" | |
| 17 | |
| 18 namespace content { | |
| 19 struct PresentationError; | |
| 20 struct PresentationSessionInfo; | |
| 21 } // namespace content | |
| 22 | |
| 23 namespace media_router { | |
| 24 | |
| 25 // Holds parameters for creating a presentation session. | |
| 26 // A request object is created by presentation_service_delegate_impl when it | |
| 27 // gets create-session request. The object is then passed to and owned by the | |
| 28 // MediaRouterUI. |success_cb| will be invoked when create-session | |
| 29 // succeeds, or |error_cb| will be invoked when create-session fails or | |
| 30 // the UI closes. | |
| 31 class CreatePresentationConnectionRequest { | |
| 32 public: | |
| 33 using PresentationSessionSuccessCallback = | |
| 34 base::Callback<void(const content::PresentationSessionInfo&, | |
| 35 const MediaRoute::Id&)>; | |
| 36 using PresentationSessionErrorCallback = | |
| 37 content::PresentationSessionErrorCallback; | |
| 38 // |presentation_url|: The presentation URL of the request. Must be a valid | |
| 39 // URL. | |
| 40 // |frame_url|: The URL of the frame that initiated the presentation request. | |
| 41 // |success_cb|: Callback to invoke when the request succeeds. Must be valid. | |
| 42 // |erorr_cb|: Callback to invoke when the request fails. Must be valid. | |
| 43 CreatePresentationConnectionRequest( | |
| 44 const RenderFrameHostId& render_frame_host_id, | |
| 45 const std::string& presentation_url, | |
| 46 const GURL& frame_url, | |
| 47 const PresentationSessionSuccessCallback& success_cb, | |
| 48 const PresentationSessionErrorCallback& error_cb); | |
| 49 ~CreatePresentationConnectionRequest(); | |
| 50 | |
| 51 const PresentationRequest& presentation_request() const { | |
| 52 return presentation_request_; | |
| 53 } | |
| 54 | |
| 55 // Invokes |success_cb_| or |error_cb_| with the given arguments. | |
| 56 // These functions can only be invoked once per instance. It is an error | |
| 57 // to invoke these functions more than once. | |
| 58 void InvokeSuccessCallback(const std::string& presentation_id, | |
| 59 const MediaRoute::Id& route_id); | |
| 60 void InvokeErrorCallback(const content::PresentationError& error); | |
| 61 | |
| 62 // Handle route creation/joining response by invoking the right callback. | |
| 63 static void HandleRouteResponse( | |
| 64 scoped_ptr<CreatePresentationConnectionRequest> presentation_request, | |
| 65 const MediaRoute* route, | |
| 66 const std::string& presentation_id, | |
| 67 const std::string& error); | |
| 68 | |
| 69 private: | |
| 70 const PresentationRequest presentation_request_; | |
| 71 PresentationSessionSuccessCallback success_cb_; | |
| 72 PresentationSessionErrorCallback error_cb_; | |
| 73 bool cb_invoked_; | |
| 74 | |
| 75 DISALLOW_COPY_AND_ASSIGN(CreatePresentationConnectionRequest); | |
| 76 }; | |
| 77 | |
| 78 } // namespace media_router | |
| 79 | |
| 80 #endif // CHROME_BROWSER_MEDIA_ROUTER_CREATE_PRESENTATION_CONNECTION_REQUEST_H_ | |
| OLD | NEW |