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 |
| 25 // State flow is ether: |
| 26 // 'Idle' -> 'Establishing' -> 'Established' -> 'Terminating' -> 'Idle' |
| 27 // (terminated by Terminate() call) |
| 28 // or |
| 29 // 'Idle' -> 'Establishing' -> 'Established' -> 'Idle' |
| 30 // (terminated from sink device or due to an error) |
| 31 enum State { |
| 32 Idle, |
| 33 Establishing, |
| 34 Established, |
| 35 Terminating |
| 36 }; |
| 37 |
| 38 virtual ~DisplaySourceSession(); |
| 39 |
| 40 // Starts the session. |
| 41 // The session state should be set to 'Establishing' immediately after this |
| 42 // method is called. |
| 43 virtual void Start() = 0; |
| 44 |
| 45 // Terminates the session. |
| 46 // The session state should be set to 'Terminating' immediately after this |
| 47 // method is called. |
| 48 virtual void Terminate() = 0; |
| 49 |
| 50 State state() const { return state_; } |
| 51 |
| 52 // Sets the callbacks invoked to inform about the session's state changes |
| 53 // |started_callback| : Called when the session was actually started (state |
| 54 // should be set to 'Established') |
| 55 // |terminated_callback| : Called when the session was actually started (state |
| 56 // should be set to 'Idle') |
| 57 // |error_callback| : Called if a fatal error has occured and the session |
| 58 // either cannot be started (if was invoked in |
| 59 // 'Establishing' state) or will be terminated soon for |
| 60 // emergency reasons (if was invoked in 'Established' |
| 61 // state). |
| 62 void SetCallbacks(const SinkIdCallback& started_callback, |
| 63 const SinkIdCallback& terminated_callback, |
| 64 const ErrorCallback& error_callback); |
| 65 |
| 66 protected: |
| 67 DisplaySourceSession(); |
| 68 |
| 69 State state_; |
| 70 SinkIdCallback started_callback_; |
| 71 SinkIdCallback terminated_callback_; |
| 72 ErrorCallback error_callback_; |
| 73 |
| 74 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSession); |
| 76 }; |
| 77 |
| 78 class DisplaySourceSessionFactory { |
| 79 public: |
| 80 static scoped_ptr<DisplaySourceSession> CreateSession( |
| 81 int sink_id, |
| 82 const blink::WebMediaStreamTrack& video_track, |
| 83 const blink::WebMediaStreamTrack& audio_track, |
| 84 scoped_ptr<DisplaySourceAuthInfo> auth_info); |
| 85 private: |
| 86 DISALLOW_COPY_AND_ASSIGN(DisplaySourceSessionFactory); |
| 87 }; |
| 88 |
| 89 } // namespace extensions |
| 90 |
| 91 #endif // EXTENSIONS_RENDERER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_SESSION_H_ |
OLD | NEW |