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_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEGATE _H_ | 5 #ifndef EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEGATE _H_ |
6 #define EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEGATE _H_ | 6 #define EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEGATE _H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
10 #include "components/keyed_service/core/keyed_service.h" | 10 #include "components/keyed_service/core/keyed_service.h" |
11 #include "extensions/common/api/display_source.h" | 11 #include "extensions/common/api/display_source.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 using DisplaySourceSinkInfoPtr = linked_ptr<api::display_source::SinkInfo>; | 15 using DisplaySourceSinkInfoPtr = linked_ptr<api::display_source::SinkInfo>; |
16 using DisplaySourceSinkInfoList = std::vector<DisplaySourceSinkInfoPtr>; | 16 using DisplaySourceSinkInfoList = std::vector<DisplaySourceSinkInfoPtr>; |
17 using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo; | 17 using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo; |
18 | 18 using DisplaySourceErrorType = api::display_source::ErrorType; |
19 // The DisplaySourceConnectionDelegate interface should be implemented | 19 // The DisplaySourceConnectionDelegate interface should be implemented |
20 // to provide sinks search and connection functionality for | 20 // to provide sinks search and connection functionality for |
21 // 'chrome.displaySource' API. | 21 // 'chrome.displaySource' API. |
22 class DisplaySourceConnectionDelegate : public KeyedService { | 22 class DisplaySourceConnectionDelegate : public KeyedService { |
23 public: | 23 public: |
24 using AuthInfoCallback = base::Callback<void(const DisplaySourceAuthInfo&)>; | 24 using AuthInfoCallback = base::Callback<void(const DisplaySourceAuthInfo&)>; |
25 using FailureCallback = base::Callback<void(const std::string&)>; | 25 using StringCallback = base::Callback<void(const std::string&)>; |
26 using SinkInfoListCallback = | 26 using SinkInfoListCallback = |
27 base::Callback<void(const DisplaySourceSinkInfoList&)>; | 27 base::Callback<void(const DisplaySourceSinkInfoList&)>; |
28 | 28 |
29 const static int kInvalidSinkId = -1; | 29 const static int kInvalidSinkId = -1; |
30 | 30 |
31 struct Connection { | 31 class Connection { |
32 public: | |
33 // Returns a pointer to the connected sink object. The result is | |
34 // guaranteed not to be NULL. | |
35 virtual DisplaySourceSinkInfoPtr GetConnectedSink() const = 0; | |
36 | |
37 // Returns the local address of the source. | |
38 virtual std::string GetLocalAddress() const = 0; | |
39 | |
40 // Returns the address of the connected sink. | |
41 virtual std::string GetSinkAddress() const = 0; | |
42 | |
43 // Sends a control message to the connected sink. | |
44 // If an error occurres 'Observer::OnConnectionError' is invoked. | |
asargent_no_longer_on_chrome
2016/01/20 19:26:17
typo: "occurres" should be "occurs"
Mikhail
2016/01/21 09:38:02
Done.
| |
45 virtual void SendMessage(const std::string& message) const = 0; | |
46 | |
47 // Sets a callback to receive control messages from the connected sink. | |
48 // If an error occurres 'Observer::OnConnectionError' is invoked. | |
asargent_no_longer_on_chrome
2016/01/20 19:26:17
same typo: "occurres" should be "occurs"
Also, it
Mikhail
2016/01/21 09:38:02
indeed, thanks for the proposal
| |
49 virtual void SetMessageReceivedCallback( | |
50 const StringCallback& callback) const = 0; | |
51 | |
52 protected: | |
32 Connection(); | 53 Connection(); |
33 ~Connection(); | 54 virtual ~Connection(); |
34 DisplaySourceSinkInfoPtr connected_sink; | |
35 std::string local_ip; | |
36 std::string sink_ip; | |
37 }; | 55 }; |
38 | 56 |
39 class Observer { | 57 class Observer { |
40 public: | 58 public: |
41 // This method is called each time the list of available | 59 // This method is called each time the list of available |
42 // sinks is updated whether after 'GetAvailableSinks' call | 60 // sinks is updated whether after 'GetAvailableSinks' call |
43 // or while the implementation is constantly watching the | 61 // or while the implementation is constantly watching the |
44 // available sinks (after 'StartWatchingAvailableSinks' was called). | 62 // available sinks (after 'StartWatchingAvailableSinks' was called). |
45 // Also this method is called to reflect current connection updates. | 63 // Also this method is called to reflect current connection updates. |
46 virtual void OnSinksUpdated(const DisplaySourceSinkInfoList& sinks) = 0; | 64 virtual void OnSinksUpdated(const DisplaySourceSinkInfoList& sinks) = 0; |
47 | 65 |
66 // This method is called during the established connection to report | |
67 // a transport layer error. | |
asargent_no_longer_on_chrome
2016/01/20 19:26:17
It might be worth mentioning if this event firing
Mikhail
2016/01/21 09:38:02
Done.
| |
68 virtual void OnConnectionError(int sink_id, | |
69 DisplaySourceErrorType type, | |
70 const std::string& description) = 0; | |
71 | |
48 protected: | 72 protected: |
49 virtual ~Observer() {} | 73 virtual ~Observer() {} |
50 }; | 74 }; |
51 | 75 |
52 DisplaySourceConnectionDelegate(); | 76 DisplaySourceConnectionDelegate(); |
53 ~DisplaySourceConnectionDelegate() override; | 77 ~DisplaySourceConnectionDelegate() override; |
54 | 78 |
55 virtual void AddObserver(Observer* observer); | 79 virtual void AddObserver(Observer* observer); |
56 virtual void RemoveObserver(Observer* observer); | 80 virtual void RemoveObserver(Observer* observer); |
57 | 81 |
58 // Returns the list of last found available sinks | 82 // Returns the list of last found available sinks |
59 // this list may contain outdated data if the delegate | 83 // this list may contain outdated data if the delegate |
60 // is not watching the sinks (via 'StartWatchingSinks' | 84 // is not watching the sinks (via 'StartWatchingSinks' |
61 // method). The list is refreshed after 'GetAvailableSinks' | 85 // method). The list is refreshed after 'GetAvailableSinks' |
62 // call. | 86 // call. |
63 virtual DisplaySourceSinkInfoList last_found_sinks() const = 0; | 87 virtual DisplaySourceSinkInfoList last_found_sinks() const = 0; |
64 | 88 |
65 // Returns the Connection object representing the current | 89 // Returns the Connection object representing the current |
66 // connection to the sink or NULL if there is no current connection. | 90 // connection to the sink or NULL if there is no current connection. |
67 virtual const Connection* connection() const = 0; | 91 virtual const Connection* connection() const = 0; |
68 | 92 |
69 // Queries the list of currently available sinks. | 93 // Queries the list of currently available sinks. |
70 virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback, | 94 virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback, |
71 const FailureCallback& failure_callback) = 0; | 95 const StringCallback& failure_callback) = 0; |
72 | 96 |
73 // Queries the authentication method required by the sink for connection. | 97 // Queries the authentication method required by the sink for connection. |
74 // If the used authentication method requires authentication data to be | 98 // If the used authentication method requires authentication data to be |
75 // visible on the sink's display (e.g. PIN) the implementation should | 99 // visible on the sink's display (e.g. PIN) the implementation should |
76 // request the sink to show it. | 100 // request the sink to show it. |
77 virtual void RequestAuthentication( | 101 virtual void RequestAuthentication( |
78 int sink_id, | 102 int sink_id, |
79 const AuthInfoCallback& auth_info_callback, | 103 const AuthInfoCallback& auth_info_callback, |
80 const FailureCallback& failure_callback) = 0; | 104 const StringCallback& failure_callback) = 0; |
81 | 105 |
82 // Connects to a sink by given id and auth info. | 106 // Connects to a sink by given id and auth info. |
83 virtual void Connect(int sink_id, | 107 virtual void Connect(int sink_id, |
84 const DisplaySourceAuthInfo& auth_info, | 108 const DisplaySourceAuthInfo& auth_info, |
85 const FailureCallback& failure_callback) = 0; | 109 const StringCallback& failure_callback) = 0; |
86 | 110 |
87 // Disconnects the current connection to sink, the 'failure_callback' | 111 // Disconnects the current connection to sink, the 'failure_callback' |
88 // is called if an error has occurred or if there is no established | 112 // is called if an error has occurred or if there is no established |
89 // connection. | 113 // connection. |
90 virtual void Disconnect(const FailureCallback& failure_callback) = 0; | 114 virtual void Disconnect(const StringCallback& failure_callback) = 0; |
91 | 115 |
92 // Implementation should start watching the available sinks updates. | 116 // Implementation should start watching the available sinks updates. |
93 virtual void StartWatchingAvailableSinks() = 0; | 117 virtual void StartWatchingAvailableSinks() = 0; |
94 | 118 |
95 // Implementation should stop watching the available sinks updates. | 119 // Implementation should stop watching the available sinks updates. |
96 virtual void StopWatchingAvailableSinks() = 0; | 120 virtual void StopWatchingAvailableSinks() = 0; |
97 | 121 |
98 protected: | 122 protected: |
99 base::ObserverList<Observer> observers_; | 123 base::ObserverList<Observer> observers_; |
100 }; | 124 }; |
101 | 125 |
102 } // namespace extensions | 126 } // namespace extensions |
103 | 127 |
104 #endif // EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEG ATE_H_ | 128 #endif // EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEG ATE_H_ |
OLD | NEW |