| 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 |
| 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' | 21 // 'chrome.displaySource' API. |
| 22 // API. | |
| 23 class DisplaySourceConnectionDelegate : public KeyedService { | 22 class DisplaySourceConnectionDelegate : public KeyedService { |
| 24 public: | 23 public: |
| 25 using AuthInfoCallback = base::Callback<void(const DisplaySourceAuthInfo&)>; | 24 using AuthInfoCallback = base::Callback<void(const DisplaySourceAuthInfo&)>; |
| 26 using FailureCallback = base::Callback<void(const std::string&)>; | 25 using FailureCallback = base::Callback<void(const std::string&)>; |
| 27 using SinkInfoListCallback = | 26 using SinkInfoListCallback = |
| 28 base::Callback<void(const DisplaySourceSinkInfoList&)>; | 27 base::Callback<void(const DisplaySourceSinkInfoList&)>; |
| 29 | 28 |
| 29 const static int kInvalidSinkId = -1; |
| 30 |
| 30 struct Connection { | 31 struct Connection { |
| 31 Connection(); | 32 Connection(); |
| 32 ~Connection(); | 33 ~Connection(); |
| 33 DisplaySourceSinkInfoPtr connected_sink; | 34 DisplaySourceSinkInfoPtr connected_sink; |
| 34 std::string local_ip; | 35 std::string local_ip; |
| 35 std::string sink_ip; | 36 std::string sink_ip; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 class Observer { | 39 class Observer { |
| 39 public: | 40 public: |
| 40 // This method is called each tiome the list of available | 41 // This method is called each time the list of available |
| 41 // sinks is updated whether after 'GetAvailableSinks' call | 42 // sinks is updated whether after 'GetAvailableSinks' call |
| 42 // or while the implementation is constantly watching the sinks | 43 // or while the implementation is constantly watching the |
| 43 // (after 'StartWatchingSinks' was called). | 44 // available sinks (after 'StartWatchingAvailableSinks' was called). |
| 45 // Also this method is called to reflect current connection updates. |
| 44 virtual void OnSinksUpdated(const DisplaySourceSinkInfoList& sinks) = 0; | 46 virtual void OnSinksUpdated(const DisplaySourceSinkInfoList& sinks) = 0; |
| 45 | 47 |
| 46 protected: | 48 protected: |
| 47 virtual ~Observer() {} | 49 virtual ~Observer() {} |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 DisplaySourceConnectionDelegate(); | 52 DisplaySourceConnectionDelegate(); |
| 51 ~DisplaySourceConnectionDelegate() override; | 53 ~DisplaySourceConnectionDelegate() override; |
| 52 | 54 |
| 53 virtual void AddObserver(Observer* observer); | 55 virtual void AddObserver(Observer* observer); |
| 54 virtual void RemoveObserver(Observer* observer); | 56 virtual void RemoveObserver(Observer* observer); |
| 55 | 57 |
| 56 // Returns the list of last found available sinks | 58 // Returns the list of last found available sinks |
| 57 // this list may contain outdated data if the delegate | 59 // this list may contain outdated data if the delegate |
| 58 // is not watching the sinks (via 'StartWatchingSinks' | 60 // is not watching the sinks (via 'StartWatchingSinks' |
| 59 // method). The list is refreshed after 'GetAvailableSinks' | 61 // method). The list is refreshed after 'GetAvailableSinks' |
| 60 // call. | 62 // call. |
| 61 virtual DisplaySourceSinkInfoList last_found_sinks() const = 0; | 63 virtual DisplaySourceSinkInfoList last_found_sinks() const = 0; |
| 62 | 64 |
| 63 // Returns the Connection object representing the current | 65 // Returns the Connection object representing the current |
| 64 // connection to the sink or NULL if there is no curent connection. | 66 // connection to the sink or NULL if there is no current connection. |
| 65 virtual const Connection* connection() const = 0; | 67 virtual const Connection* connection() const = 0; |
| 66 | 68 |
| 67 // Queries the list of currently available sinks. | 69 // Queries the list of currently available sinks. |
| 68 virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback, | 70 virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback, |
| 69 const FailureCallback& failure_callback) = 0; | 71 const FailureCallback& failure_callback) = 0; |
| 70 | 72 |
| 71 // Queries the authentication method required by the sink for connection. | 73 // Queries the authentication method required by the sink for connection. |
| 72 // If the used authentication method requires authentication data to be | 74 // If the used authentication method requires authentication data to be |
| 73 // visible on the sink's display (e.g. PIN) the implementation should | 75 // visible on the sink's display (e.g. PIN) the implementation should |
| 74 // request the sink to show it. | 76 // request the sink to show it. |
| 75 virtual void RequestAuthentication( | 77 virtual void RequestAuthentication( |
| 76 int sink_id, | 78 int sink_id, |
| 77 const AuthInfoCallback& auth_info_callback, | 79 const AuthInfoCallback& auth_info_callback, |
| 78 const FailureCallback& failure_callback) = 0; | 80 const FailureCallback& failure_callback) = 0; |
| 79 | 81 |
| 80 // Connects to a sink by given id and auth info. | 82 // Connects to a sink by given id and auth info. |
| 81 virtual void Connect(int sink_id, | 83 virtual void Connect(int sink_id, |
| 82 const DisplaySourceAuthInfo& auth_info, | 84 const DisplaySourceAuthInfo& auth_info, |
| 83 const base::Closure& connected_callback, | |
| 84 const FailureCallback& failure_callback) = 0; | 85 const FailureCallback& failure_callback) = 0; |
| 85 | 86 |
| 86 // Disconnects the current connection to sink, the 'failure_callback' | 87 // Disconnects the current connection to sink, the 'failure_callback' |
| 87 // is called if there is no current connection. | 88 // is called if an error has occurred or if there is no established |
| 88 virtual void Disconnect(const base::Closure& disconnected_callback, | 89 // connection. |
| 89 const FailureCallback& failure_callback) = 0; | 90 virtual void Disconnect(const FailureCallback& failure_callback) = 0; |
| 90 | 91 |
| 91 // Implementation should start watching the sinks updates. | 92 // Implementation should start watching the available sinks updates. |
| 92 virtual void StartWatchingSinks() = 0; | 93 virtual void StartWatchingAvailableSinks() = 0; |
| 93 | 94 |
| 94 // Implementation should stop watching the sinks updates. | 95 // Implementation should stop watching the available sinks updates. |
| 95 virtual void StopWatchingSinks() = 0; | 96 virtual void StopWatchingAvailableSinks() = 0; |
| 96 | 97 |
| 97 protected: | 98 protected: |
| 98 base::ObserverList<Observer> observers_; | 99 base::ObserverList<Observer> observers_; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 } // namespace extensions | 102 } // namespace extensions |
| 102 | 103 |
| 103 #endif // EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEG
ATE_H_ | 104 #endif // EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEG
ATE_H_ |
| OLD | NEW |