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 EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ |
6 #define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ | 6 #define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "extensions/common/api/display_source.h" | 10 #include "extensions/common/api/display_source.h" |
11 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" | 11 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 class RenderFrame; | 14 class RenderFrame; |
15 } | 15 } |
16 | 16 |
17 namespace extensions { | 17 namespace extensions { |
18 | 18 |
19 using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo; | 19 using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo; |
20 using DisplaySourceAuthMethod = api::display_source::AuthenticationMethod; | 20 using DisplaySourceAuthMethod = api::display_source::AuthenticationMethod; |
21 using DisplaySourceErrorType = api::display_source::ErrorType; | 21 using DisplaySourceErrorType = api::display_source::ErrorType; |
22 | 22 |
23 // This class represents a generic display source session interface. | 23 // This class represents a generic display source session interface. |
24 class DisplaySourceSession { | 24 class DisplaySourceSession { |
25 public: | 25 public: |
26 using SinkIdCallback = base::Callback<void(int sink_id)>; | 26 using CompletionCallback = |
| 27 base::Callback<void(bool success, const std::string& error_description)>; |
27 using ErrorCallback = | 28 using ErrorCallback = |
28 base::Callback<void(int sink_id, | 29 base::Callback<void(DisplaySourceErrorType error_type, |
29 DisplaySourceErrorType error_type, | |
30 const std::string& error_description)>; | 30 const std::string& error_description)>; |
31 | 31 |
32 // State flow is ether: | 32 // State flow is ether: |
33 // 'Idle' -> 'Establishing' -> 'Established' -> 'Terminating' -> 'Idle' | 33 // 'Idle' -> 'Establishing' -> 'Established' -> 'Terminating' -> 'Idle' |
34 // (terminated by Terminate() call) | 34 // (terminated by Terminate() call) |
35 // or | 35 // or |
36 // 'Idle' -> 'Establishing' -> 'Established' -> 'Idle' | 36 // 'Idle' -> 'Establishing' -> 'Established' -> 'Idle' |
37 // (terminated from sink device or due to an error) | 37 // (terminated from sink device or due to an error) |
38 enum State { | 38 enum State { |
39 Idle, | 39 Idle, |
40 Establishing, | 40 Establishing, |
41 Established, | 41 Established, |
42 Terminating | 42 Terminating |
43 }; | 43 }; |
44 | 44 |
45 virtual ~DisplaySourceSession(); | 45 virtual ~DisplaySourceSession(); |
46 | 46 |
47 // Starts the session. | 47 // Starts the session. |
48 // The session state should be set to 'Establishing' immediately after this | 48 // The session state should be set to 'Establishing' immediately after this |
49 // method is called. | 49 // method is called. |
50 virtual void Start() = 0; | 50 // |callback| : Called with 'success' flag set to 'true' if the session is |
| 51 // successfully started (state should be set to 'Established') |
| 52 // |
| 53 // Called with 'success' flag set to 'false' if the session |
| 54 // has failed to start (state should be set back to 'Idle'). |
| 55 // The 'error_description' argument contains description of |
| 56 // an error that had caused the call falure. |
| 57 virtual void Start(const CompletionCallback& callback) = 0; |
51 | 58 |
52 // Terminates the session. | 59 // Terminates the session. |
53 // The session state should be set to 'Terminating' immediately after this | 60 // The session state should be set to 'Terminating' immediately after this |
54 // method is called. | 61 // method is called. |
55 virtual void Terminate() = 0; | 62 // |callback| : Called with 'success' flag set to 'true' if the session is |
| 63 // successfully terminated (state should be set to 'Idle') |
| 64 // |
| 65 // Called with 'success' flag set to 'false' if the session |
| 66 // could not terminate (state should not be modified). |
| 67 // The 'error_description' argument contains description of |
| 68 // an error that had caused the call falure. |
| 69 virtual void Terminate(const CompletionCallback& callback) = 0; |
56 | 70 |
57 State state() const { return state_; } | 71 State state() const { return state_; } |
58 | 72 |
59 // Sets the callbacks invoked to inform about the session's state changes. | 73 // Sets the callbacks invoked to inform about the session's state changes. |
60 // It is required to set the callbacks before the session is started. | 74 // It is required to set the callbacks before the session is started. |
61 // |started_callback| : Called when the session was actually started (state | 75 // |terminated_callback| : Called when session was terminated (state |
62 // should be set to 'Established') | |
63 // |terminated_callback| : Called when the session was actually started (state | |
64 // should be set to 'Idle') | 76 // should be set to 'Idle') |
65 // |error_callback| : Called if a fatal error has occured and the session | 77 // |error_callback| : Called if a fatal error has occured and the session |
66 // either cannot be started (if was invoked in | 78 // will be terminated soon for emergency reasons. |
67 // 'Establishing' state) or will be terminated soon for | 79 void SetNotificationCallbacks(const base::Closure& terminated_callback, |
68 // emergency reasons (if was invoked in 'Established' | 80 const ErrorCallback& error_callback); |
69 // state). | |
70 void SetCallbacks(const SinkIdCallback& started_callback, | |
71 const SinkIdCallback& terminated_callback, | |
72 const ErrorCallback& error_callback); | |
73 | 81 |
74 protected: | 82 protected: |
75 DisplaySourceSession(); | 83 DisplaySourceSession(); |
76 | 84 |
77 State state_; | 85 State state_; |
78 SinkIdCallback started_callback_; | 86 base::Closure terminated_callback_; |
79 SinkIdCallback terminated_callback_; | |
80 ErrorCallback error_callback_; | 87 ErrorCallback error_callback_; |
81 | 88 |
82 private: | 89 private: |
83 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSession); | 90 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSession); |
84 }; | 91 }; |
85 | 92 |
86 struct DisplaySourceSessionParams { | 93 struct DisplaySourceSessionParams { |
87 DisplaySourceSessionParams(); | 94 DisplaySourceSessionParams(); |
88 ~DisplaySourceSessionParams(); | 95 ~DisplaySourceSessionParams(); |
89 | 96 |
90 int sink_id; | 97 int sink_id; |
91 blink::WebMediaStreamTrack video_track; | 98 blink::WebMediaStreamTrack video_track; |
92 blink::WebMediaStreamTrack audio_track; | 99 blink::WebMediaStreamTrack audio_track; |
93 DisplaySourceAuthMethod auth_method; | 100 DisplaySourceAuthMethod auth_method; |
94 std::string auth_data; | 101 std::string auth_data; |
95 content::RenderFrame* render_frame; | 102 content::RenderFrame* render_frame; |
96 }; | 103 }; |
97 | 104 |
98 class DisplaySourceSessionFactory { | 105 class DisplaySourceSessionFactory { |
99 public: | 106 public: |
100 static scoped_ptr<DisplaySourceSession> CreateSession( | 107 static scoped_ptr<DisplaySourceSession> CreateSession( |
101 const DisplaySourceSessionParams& params); | 108 const DisplaySourceSessionParams& params); |
102 private: | 109 private: |
103 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSessionFactory); | 110 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSessionFactory); |
104 }; | 111 }; |
105 | 112 |
106 } // namespace extensions | 113 } // namespace extensions |
107 | 114 |
108 #endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ | 115 #endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ |
OLD | NEW |