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

Side by Side Diff: chrome/common/media_router/discovery/media_sink_service.h

Issue 2965843002: [Media Router] Support dual discovery (Closed)
Patch Set: clean up and fix unit tests Created 3 years, 5 months 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 CHROME_COMMON_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_H_ 5 #ifndef CHROME_COMMON_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_H_
6 #define CHROME_COMMON_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_H_ 6 #define CHROME_COMMON_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "chrome/common/media_router/discovery/media_sink_internal.h" 12 #include "chrome/common/media_router/discovery/media_sink_internal.h"
13 #include "chrome/common/media_router/media_sink.h" 13 #include "chrome/common/media_router/media_sink.h"
14 14
15 namespace media_router { 15 namespace media_router {
16 16
17 // A service which can be used to start background discovery and resolution of 17 // A service which can be used to start background discovery and resolution of
18 // MediaSinks. Often these are remote devices, like Chromecast. In addition, the 18 // MediaSinks. Often these are remote devices, like Chromecast. In addition, the
19 // service is capable of answering MediaSink queries using the sinks that it 19 // service is capable of answering MediaSink queries using the sinks that it
20 // generated. 20 // generated.
21 // This class is not thread safe. All methods must be called from the UI thread. 21 // This class is not thread safe. All methods must be called from the UI thread.
22 class MediaSinkService { 22 class MediaSinkService {
23 public: 23 public:
24 class Observer {
25 public:
26 // Invoked when |sink| is added to current service.
27 virtual void OnMediaSinkAdded(const MediaSinkInternal& sink) = 0;
28
29 // Invoked when media sinks are removed from current service.
30 virtual void OnMediaSinksRemoved() = 0;
31 };
32
24 // Callback to be invoked when this class finishes sink discovering. 33 // Callback to be invoked when this class finishes sink discovering.
25 // Arg 0: Sinks discovered and resolved by the service. 34 // Arg 0: Sinks discovered and resolved by the service.
26 using OnSinksDiscoveredCallback = 35 using OnSinksDiscoveredCallback =
27 base::Callback<void(std::vector<MediaSinkInternal>)>; 36 base::Callback<void(std::vector<MediaSinkInternal>)>;
28 37
29 explicit MediaSinkService( 38 explicit MediaSinkService(
30 const OnSinksDiscoveredCallback& sink_discovery_callback); 39 const OnSinksDiscoveredCallback& sink_discovery_callback);
31 40
32 virtual ~MediaSinkService(); 41 virtual ~MediaSinkService();
33 42
34 // Starts sink discovery. No-ops if already started. 43 // Starts sink discovery. No-ops if already started.
35 // Sinks discovered and resolved are continuously passed to 44 // Sinks discovered and resolved are continuously passed to
36 // |callback|. 45 // |callback|.
37 virtual void Start() = 0; 46 virtual void Start() = 0;
38 47
39 // Stops sink discovery. No-ops if already stopped. 48 // Stops sink discovery. No-ops if already stopped.
40 virtual void Stop() = 0; 49 virtual void Stop() = 0;
41 50
51 // Adds |observer| to current service. Does not take ownership of |observer|.
52 // Caller should make sure that |observer| outlives current service.
53 virtual void AddObserver(Observer* observer) = 0;
54
55 // Removes |observer| from current service. Does not take ownership of
56 // |observer|.
57 virtual void RemoveObserver(Observer* observer) = 0;
58
42 protected: 59 protected:
43 OnSinksDiscoveredCallback sink_discovery_callback_; 60 OnSinksDiscoveredCallback sink_discovery_callback_;
44 61
45 DISALLOW_COPY_AND_ASSIGN(MediaSinkService); 62 DISALLOW_COPY_AND_ASSIGN(MediaSinkService);
46 }; 63 };
47 64
48 } // namespace media_router 65 } // namespace media_router
49 66
50 #endif // CHROME_COMMON_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_H_ 67 #endif // CHROME_COMMON_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698