Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: extensions/browser/api/display_source/display_source_connection_delegate.h

Issue 1410093008: Introduce chrome.displaySource API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from Antony Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEGATE _H_
6 #define EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEGATE _H_
7
8 #include "base/callback.h"
9 #include "base/observer_list.h"
10 #include "components/keyed_service/core/keyed_service.h"
11 #include "extensions/common/api/display_source.h"
12
13 namespace extensions {
14
15 using DisplaySourceSinkInfoPtr = linked_ptr<api::display_source::SinkInfo>;
16 using DisplaySourceSinkInfoList = std::vector<DisplaySourceSinkInfoPtr>;
17 using DisplaySourceAuthInfo = api::display_source::AuthenticationInfo;
18
19 // The DisplaySourceConnectionDelegate interface should be implemented
20 // to provide sinks search and connection functionality for
21 // 'chrome.displaySource'
22 // API.
23 class DisplaySourceConnectionDelegate : public KeyedService {
24 public:
25 using AuthInfoCallback = base::Callback<void(const DisplaySourceAuthInfo&)>;
26 using FailureCallback = base::Callback<void(const std::string&)>;
27 using SinkInfoListCallback =
28 base::Callback<void(const DisplaySourceSinkInfoList&)>;
29
30 struct Connection {
31 Connection();
32 ~Connection();
33 DisplaySourceSinkInfoPtr connected_sink;
34 std::string local_ip;
35 std::string sink_ip;
36 };
37
38 class Observer {
39 public:
40 // This method is called each tiome the list of available
41 // sinks is updated whether after 'GetAvailableSinks' call
42 // or while the implementation is constantly watching the sinks
43 // (after 'StartWatchingSinks' was called).
44 virtual void OnSinksUpdated(const DisplaySourceSinkInfoList& sinks) = 0;
45
46 protected:
47 virtual ~Observer() {}
48 };
49
50 DisplaySourceConnectionDelegate();
51 ~DisplaySourceConnectionDelegate() override;
52
53 virtual void AddObserver(Observer* observer);
54 virtual void RemoveObserver(Observer* observer);
55
56 // Returns the list of last found available sinks
57 // this list may contain outdated data if the delegate
58 // is not watching the sinks (via 'StartWatchingSinks'
59 // method). The list is refreshed after 'GetAvailableSinks'
60 // call.
61 virtual DisplaySourceSinkInfoList last_found_sinks() const = 0;
62
63 // Returns the Connection object representing the current
64 // connection to the sink or NULL if there is no curent connection.
65 virtual const Connection* connection() const = 0;
66
67 // Queries the list of currently available sinks.
68 virtual void GetAvailableSinks(const SinkInfoListCallback& sinks_callback,
69 const FailureCallback& failure_callback) = 0;
70
71 // Queries the authentication method required by the sink for connection.
72 // If the used authentication method requires authentication data to be
73 // visible on the sink's display (e.g. PIN) the implementation should
74 // request the sink to show it.
75 virtual void RequestAuthentication(
76 int sink_id,
77 const AuthInfoCallback& auth_info_callback,
78 const FailureCallback& failure_callback) = 0;
79
80 // Connects to a sink by given id and auth info.
81 virtual void Connect(int sink_id,
82 const DisplaySourceAuthInfo& auth_info,
83 const base::Closure& connected_callback,
84 const FailureCallback& failure_callback) = 0;
85
86 // Disconnects the current connection to sink, the 'failure_callback'
87 // is called if there is no current connection.
88 virtual void Disconnect(const base::Closure& disconnected_callback,
89 const FailureCallback& failure_callback) = 0;
90
91 // Implementation should start watching the sinks updates.
92 virtual void StartWatchingSinks() = 0;
93
94 // Implementation should stop watching the sinks updates.
95 virtual void StopWatchingSinks() = 0;
96
97 protected:
98 base::ObserverList<Observer> observers_;
99 };
100
101 } // namespace extensions
102
103 #endif // EXTENSIONS_BROWSER_API_DISPLAY_SOURCE_DISPLAY_SOURCE_CONNECTION_DELEG ATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698