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