| 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 occurs 'Observer::OnConnectionError' is invoked. |
| 45 virtual void SendMessage(const std::string& message) const = 0; |
| 46 |
| 47 // Sets a callback to receive control messages from the connected sink. |
| 48 // This method should only be called once in the lifetime of each |
| 49 // Connection object. |
| 50 // If an error occurs 'Observer::OnConnectionError' is invoked. |
| 51 virtual void SetMessageReceivedCallback( |
| 52 const StringCallback& callback) const = 0; |
| 53 |
| 54 protected: |
| 32 Connection(); | 55 Connection(); |
| 33 ~Connection(); | 56 virtual ~Connection(); |
| 34 DisplaySourceSinkInfoPtr connected_sink; | |
| 35 std::string local_ip; | |
| 36 std::string sink_ip; | |
| 37 }; | 57 }; |
| 38 | 58 |
| 39 class Observer { | 59 class Observer { |
| 40 public: | 60 public: |
| 41 // This method is called each time the list of available | 61 // This method is called each time the list of available |
| 42 // sinks is updated whether after 'GetAvailableSinks' call | 62 // sinks is updated whether after 'GetAvailableSinks' call |
| 43 // or while the implementation is constantly watching the | 63 // or while the implementation is constantly watching the |
| 44 // available sinks (after 'StartWatchingAvailableSinks' was called). | 64 // available sinks (after 'StartWatchingAvailableSinks' was called). |
| 45 // Also this method is called to reflect current connection updates. | 65 // Also this method is called to reflect current connection updates. |
| 46 virtual void OnSinksUpdated(const DisplaySourceSinkInfoList& sinks) = 0; | 66 virtual void OnSinksUpdated(const DisplaySourceSinkInfoList& sinks) = 0; |
| 47 | 67 |
| 68 // This method is called during the established connection to report |
| 69 // a transport layer fatal error (which implies that the connection |
| 70 // becomes broken/disconnected). |
| 71 virtual void OnConnectionError(int sink_id, |
| 72 DisplaySourceErrorType type, |
| 73 const std::string& description) = 0; |
| 74 |
| 48 protected: | 75 protected: |
| 49 virtual ~Observer() {} | 76 virtual ~Observer() {} |
| 50 }; | 77 }; |
| 51 | 78 |
| 52 DisplaySourceConnectionDelegate(); | 79 DisplaySourceConnectionDelegate(); |
| 53 ~DisplaySourceConnectionDelegate() override; | 80 ~DisplaySourceConnectionDelegate() override; |
| 54 | 81 |
| 55 virtual void AddObserver(Observer* observer); | 82 virtual void AddObserver(Observer* observer); |
| 56 virtual void RemoveObserver(Observer* observer); | 83 virtual void RemoveObserver(Observer* observer); |
| 57 | 84 |
| 58 // Returns the list of last found available sinks | 85 // Returns the list of last found available sinks |
| 59 // this list may contain outdated data if the delegate | 86 // this list may contain outdated data if the delegate |
| 60 // is not watching the sinks (via 'StartWatchingSinks' | 87 // is not watching the sinks (via 'StartWatchingSinks' |
| 61 // method). The list is refreshed after 'GetAvailableSinks' | 88 // method). The list is refreshed after 'GetAvailableSinks' |
| 62 // call. | 89 // call. |
| 63 virtual DisplaySourceSinkInfoList last_found_sinks() const = 0; | 90 virtual DisplaySourceSinkInfoList last_found_sinks() const = 0; |
| 64 | 91 |
| 65 // Returns the Connection object representing the current | 92 // Returns the Connection object representing the current |
| 66 // connection to the sink or NULL if there is no current connection. | 93 // connection to the sink or NULL if there is no current connection. |
| 67 virtual const Connection* connection() const = 0; | 94 virtual const Connection* connection() const = 0; |
| 68 | 95 |
| 69 // Queries the list of currently available sinks. | 96 // Queries the list of currently available sinks. |
| 70 virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback, | 97 virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback, |
| 71 const FailureCallback& failure_callback) = 0; | 98 const StringCallback& failure_callback) = 0; |
| 72 | 99 |
| 73 // Queries the authentication method required by the sink for connection. | 100 // Queries the authentication method required by the sink for connection. |
| 74 // If the used authentication method requires authentication data to be | 101 // If the used authentication method requires authentication data to be |
| 75 // visible on the sink's display (e.g. PIN) the implementation should | 102 // visible on the sink's display (e.g. PIN) the implementation should |
| 76 // request the sink to show it. | 103 // request the sink to show it. |
| 77 virtual void RequestAuthentication( | 104 virtual void RequestAuthentication( |
| 78 int sink_id, | 105 int sink_id, |
| 79 const AuthInfoCallback& auth_info_callback, | 106 const AuthInfoCallback& auth_info_callback, |
| 80 const FailureCallback& failure_callback) = 0; | 107 const StringCallback& failure_callback) = 0; |
| 81 | 108 |
| 82 // Connects to a sink by given id and auth info. | 109 // Connects to a sink by given id and auth info. |
| 83 virtual void Connect(int sink_id, | 110 virtual void Connect(int sink_id, |
| 84 const DisplaySourceAuthInfo& auth_info, | 111 const DisplaySourceAuthInfo& auth_info, |
| 85 const FailureCallback& failure_callback) = 0; | 112 const StringCallback& failure_callback) = 0; |
| 86 | 113 |
| 87 // Disconnects the current connection to sink, the 'failure_callback' | 114 // Disconnects the current connection to sink, the 'failure_callback' |
| 88 // is called if an error has occurred or if there is no established | 115 // is called if an error has occurred or if there is no established |
| 89 // connection. | 116 // connection. |
| 90 virtual void Disconnect(const FailureCallback& failure_callback) = 0; | 117 virtual void Disconnect(const StringCallback& failure_callback) = 0; |
| 91 | 118 |
| 92 // Implementation should start watching the available sinks updates. | 119 // Implementation should start watching the available sinks updates. |
| 93 virtual void StartWatchingAvailableSinks() = 0; | 120 virtual void StartWatchingAvailableSinks() = 0; |
| 94 | 121 |
| 95 // Implementation should stop watching the available sinks updates. | 122 // Implementation should stop watching the available sinks updates. |
| 96 virtual void StopWatchingAvailableSinks() = 0; | 123 virtual void StopWatchingAvailableSinks() = 0; |
| 97 | 124 |
| 98 protected: | 125 protected: |
| 99 base::ObserverList<Observer> observers_; | 126 base::ObserverList<Observer> observers_; |
| 100 }; | 127 }; |
| 101 | 128 |
| 102 } // namespace extensions | 129 } // namespace extensions |
| 103 | 130 |
| 104 #endif // EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEG
ATE_H_ | 131 #endif // EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEG
ATE_H_ |
| OLD | NEW |