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