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 EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ | |
6 #define EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/macros.h" | |
10 #include "extensions/common/api/display_source.h" | |
11 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" | |
12 | |
13 namespace extensions { | |
14 | |
15 using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo; | |
16 using DisplaySourceErrorType = api::display_source::ErrorType; | |
17 | |
18 // This class represents a generic display source session interface. | |
19 class DisplaySourceSession { | |
20 public: | |
21 using SinkIdCallback = base::Callback<void(int)>; | |
22 using ErrorCallback = | |
23 base::Callback<void(int, DisplaySourceErrorType, const std::string&)>; | |
24 // State flow is ether: | |
25 // 'Idle' -> 'Establishing' -> 'Established' -> 'Terminating' -> 'Idle' | |
26 // (terminated by Terminate() call) | |
27 // or | |
28 // 'Idle' -> 'Establishing' -> 'Established' -> 'Idle' | |
29 // (terminated from sink device or due to an error) | |
30 enum State { | |
31 Idle, | |
32 Establishing, | |
33 Established, | |
34 Terminating | |
35 }; | |
36 | |
37 virtual ~DisplaySourceSession(); | |
38 // Starts the session. | |
asargent_no_longer_on_chrome
2015/11/26 00:50:07
optional nit: consider adding an additional whites
Mikhail
2015/11/26 13:00:46
Done.
| |
39 // The session state should be set to 'Establishing' immediately after this | |
40 // method is called. | |
41 virtual void Start() = 0; | |
42 // Terminates the session. | |
43 // The session state should be set to 'Terminating' immediately after this | |
44 // method is called. | |
45 virtual void Terminate() = 0; | |
46 | |
47 State state() const { return state_; } | |
48 | |
49 // Sets the callbacks invoked to inform about the session's state changes | |
50 // |started_callback| : Called when the session was actually started (state | |
51 // should be set to 'Established') | |
52 // |terminated_callback| : Called when the session was actually started (state | |
53 // should be set to 'Idle') | |
54 // |error_callback| : Called if a fatal error has occured and the session | |
55 // either cannot be started (if was invoked in | |
56 // 'Establishing' state) or will be terminated soon for | |
57 // emergency reasons (if was invoked in 'Established' | |
58 // state). | |
59 void SetCallbacks(const SinkIdCallback& started_callback, | |
60 const SinkIdCallback& terminated_callback, | |
61 const ErrorCallback& error_callback); | |
62 | |
63 protected: | |
64 DisplaySourceSession(); | |
65 | |
66 State state_; | |
67 SinkIdCallback started_callback_; | |
68 SinkIdCallback terminated_callback_; | |
69 ErrorCallback error_callback_; | |
70 | |
71 private: | |
72 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSession); | |
73 }; | |
74 | |
75 class DisplaySourceSessionFactory { | |
76 public: | |
77 static scoped_ptr<DisplaySourceSession> CreateSession( | |
78 int sink_id, | |
79 const blink::WebMediaStreamTrack& video_track, | |
80 const blink::WebMediaStreamTrack& audio_track, | |
81 scoped_ptr<DisplaySourceAuthInfo> auth_info); | |
82 private: | |
83 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSessionFactory); | |
84 }; | |
85 | |
86 } // namespace extensions | |
87 | |
88 #endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ | |
OLD | NEW |