OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_INTERNAL_H_ | |
6 #define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_INTERNAL_H_ | |
7 | |
8 #include <utility> | |
9 | |
10 #include "base/memory/manual_constructor.h" | |
11 #include "chrome/browser/media/router/media_sink.h" | |
12 #include "net/base/ip_address.h" | |
13 #include "url/gurl.h" | |
14 | |
15 namespace media_router { | |
16 | |
17 // Extra data for DIAL media sink. | |
18 struct DialSinkExtraData { | |
19 net::IPAddress ip_address; | |
20 | |
21 // Model name of the sink. | |
22 std::string model_name; | |
23 | |
24 // The base URL used for DIAL operations. | |
25 GURL app_url; | |
26 | |
27 DialSinkExtraData(); | |
28 DialSinkExtraData(const DialSinkExtraData& other); | |
29 ~DialSinkExtraData(); | |
30 | |
31 bool operator==(const DialSinkExtraData& other) const; | |
32 }; | |
33 | |
34 // Extra data for cast media sink. | |
mark a. foltz
2017/03/13 17:47:24
nit: Cast
zhaobin
2017/03/14 01:23:23
Done.
| |
35 struct CastSinkExtraData { | |
36 net::IPAddress ip_address; | |
37 | |
38 // Model name of the sink. | |
39 std::string model_name; | |
40 | |
41 // A bit vector representing the capabilities of the sink. The values are | |
42 // defined in media_router.mojom. | |
43 uint8_t capabilities = 0; | |
44 | |
45 // ID of Cast channel opened for the sink. The caller must set this value to a | |
46 // valid cast_channel_id. The cast_channel_id may change over time as the | |
47 // browser reconnects to a device. | |
48 int cast_channel_id = 0; | |
49 | |
50 CastSinkExtraData(); | |
51 CastSinkExtraData(const CastSinkExtraData& other); | |
52 ~CastSinkExtraData(); | |
53 | |
54 bool operator==(const CastSinkExtraData& other) const; | |
55 }; | |
56 | |
57 // Represents a media sink discovered by MediaSinkService. It is used by | |
58 // MediaSinkService to push MediaSinks with extra data to the | |
59 // MediaRouteProvider, and it is not exposed to users of MediaRouter. | |
60 class MediaSinkInternal { | |
61 public: | |
62 // Used by mojo. | |
63 MediaSinkInternal(); | |
64 | |
65 // Used by unit test. | |
66 explicit MediaSinkInternal(const MediaSink& sink); | |
mark a. foltz
2017/03/13 17:47:24
If this is just for tests, it seems like this can
zhaobin
2017/03/14 01:23:23
Done.
| |
67 | |
68 // Used by MediaSinkService to create media sinks. | |
69 MediaSinkInternal(const MediaSink& sink, const DialSinkExtraData& dial_data); | |
70 MediaSinkInternal(const MediaSink& sink, const CastSinkExtraData& cast_data); | |
71 | |
72 // Used to push instance of this class into vector. | |
73 MediaSinkInternal(const MediaSinkInternal& other); | |
74 | |
75 ~MediaSinkInternal(); | |
76 | |
77 // Used by unit test. | |
mark a. foltz
2017/03/13 17:47:24
Not sure this comment is needed; also, these will
zhaobin
2017/03/14 01:23:23
Done.
| |
78 MediaSinkInternal& operator=(const MediaSinkInternal& other); | |
79 bool operator==(const MediaSinkInternal& other) const; | |
80 | |
81 // Used by mojo. | |
82 void set_sink_id(const MediaSink::Id& sink_id) { sink_.set_sink_id(sink_id); } | |
83 void set_name(const std::string& name) { sink_.set_name(name); } | |
84 void set_description(const std::string& description) { | |
85 sink_.set_description(description); | |
86 } | |
87 void set_domain(const std::string& domain) { sink_.set_domain(domain); } | |
88 void set_icon_type(MediaSink::IconType icon_type) { | |
89 sink_.set_icon_type(icon_type); | |
90 } | |
91 | |
92 void set_sink(const MediaSink& sink); | |
93 const MediaSink& sink() const { return sink_; } | |
94 | |
95 void set_dial_data(const DialSinkExtraData& dial_data); | |
96 | |
97 // Must only be called if the sink is a DIAL sink. | |
98 const DialSinkExtraData& dial_data() const; | |
99 | |
100 void set_cast_data(const CastSinkExtraData& cast_data); | |
101 | |
102 // Must only be called if the sink is a Cast sink. | |
103 const CastSinkExtraData& cast_data() const; | |
104 | |
105 bool is_dial_sink() const { return sink_type_ == SinkType::DIAL; } | |
106 bool is_cast_sink() const { return sink_type_ == SinkType::CAST; } | |
107 | |
108 static bool IsValidSinkId(const std::string& sink_id); | |
109 | |
110 private: | |
111 void InternalCopyAssignFrom(const MediaSinkInternal& other); | |
112 void InternalCopyConstructFrom(const MediaSinkInternal& other); | |
113 void InternalCleanup(); | |
114 | |
115 enum class SinkType { GENERIC = 0, DIAL, CAST }; | |
imcheng
2017/03/11 00:33:08
The = 0 is not necessary?
zhaobin
2017/03/14 01:23:23
Done.
| |
116 | |
117 MediaSink sink_; | |
118 | |
119 SinkType sink_type_; | |
120 | |
121 union { | |
122 // Set if sink is DIAL sink. | |
123 base::ManualConstructor<DialSinkExtraData> dial_data_; | |
124 | |
125 // Set if sink is Cast sink. | |
126 base::ManualConstructor<CastSinkExtraData> cast_data_; | |
127 }; | |
128 }; | |
129 | |
130 } // namespace media_router | |
131 | |
132 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_INTERNAL_H_ | |
OLD | NEW |