Chromium Code Reviews| 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 "chrome/browser/media/router/media_sink.h" | |
| 9 #include "net/base/ip_address.h" | |
| 10 #include "url/gurl.h" | |
| 11 | |
| 12 namespace media_router { | |
| 13 | |
| 14 // Extra data for DIAL media sink. | |
| 15 struct DialSinkExtraData { | |
| 16 net::IPAddress ip_address; | |
| 17 | |
| 18 // Model name of the sink. | |
| 19 std::string model_name; | |
| 20 | |
| 21 // The base URL used for DIAL operations. | |
| 22 GURL app_url; | |
| 23 | |
| 24 DialSinkExtraData(); | |
| 25 DialSinkExtraData(const DialSinkExtraData& other); | |
| 26 ~DialSinkExtraData(); | |
| 27 }; | |
| 28 | |
| 29 // Extra data for cast media sink. | |
| 30 struct CastSinkExtraData { | |
| 31 net::IPAddress ip_address; | |
| 32 | |
| 33 // Model name of the sink. | |
| 34 std::string model_name; | |
| 35 | |
| 36 // A bit vector representing the capabilities of the sink. The values are | |
| 37 // defined in media_router.mojom. | |
| 38 int capabilities = 0; | |
| 39 | |
| 40 // ID of Cast channel opened for the sink. The caller must set this value to a | |
| 41 // valid cast_channel_id. The cast_channel_id may change over time as the | |
| 42 // browser reconnects to a device. | |
| 43 int cast_channel_id = 0; | |
| 44 | |
| 45 CastSinkExtraData(); | |
| 46 CastSinkExtraData(const CastSinkExtraData& other); | |
| 47 ~CastSinkExtraData(); | |
| 48 }; | |
| 49 | |
| 50 // Represents a media sink discovered by MediaSinkService. It is used by | |
| 51 // MediaSinkService to push MediaSinks with extra data to the | |
| 52 // MediaRouteProvider, and it is not exposed to users of MediaRouter. | |
| 53 class MediaSinkInternal { | |
| 54 public: | |
| 55 // Used by mojo. | |
| 56 MediaSinkInternal(); | |
| 57 | |
| 58 // Used by unit test. | |
| 59 explicit MediaSinkInternal(const MediaSink& sink); | |
| 60 | |
| 61 // Used by MediaSinkService to create media sinks. | |
| 62 MediaSinkInternal(const MediaSink& sink, const DialSinkExtraData& dial_data); | |
| 63 MediaSinkInternal(const MediaSink& sink, const CastSinkExtraData& cast_data); | |
| 64 | |
| 65 // Used to push instance of this class into vector. | |
| 66 MediaSinkInternal(const MediaSinkInternal& other); | |
| 67 | |
| 68 ~MediaSinkInternal(); | |
| 69 | |
| 70 MediaSinkInternal& operator=(const MediaSinkInternal& other); | |
| 71 | |
| 72 void set_sink(const MediaSink& sink); | |
| 73 const MediaSink& sink() const { return sink_; } | |
| 74 | |
| 75 void set_dial_data(const DialSinkExtraData& dial_data); | |
| 76 | |
| 77 // Must only be called if the sink is a DIAL sink. | |
| 78 const DialSinkExtraData& dial_data() const; | |
| 79 | |
| 80 void set_cast_data(const CastSinkExtraData& cast_data); | |
| 81 | |
| 82 // Must only be called if the sink is a Cast sink. | |
| 83 const CastSinkExtraData& cast_data() const; | |
| 84 | |
| 85 bool is_dial_sink() const { return dial_data_ && !cast_data_; } | |
| 86 bool is_cast_sink() const { return cast_data_ && !dial_data_; } | |
| 87 | |
| 88 static bool IsValidSinkId(const std::string& sink_id); | |
| 89 | |
| 90 private: | |
| 91 MediaSink sink_; | |
| 92 | |
| 93 // Set if sink is DIAL sink. | |
|
dcheng
2017/03/03 10:37:10
One option (that results in a smaller object) is t
zhaobin
2017/03/03 23:56:42
We tried union. It is a little complicated to cons
dcheng
2017/03/04 01:49:15
Hmm... it's still preferable here though: with thi
zhaobin
2017/03/06 18:31:26
Done.
| |
| 94 base::Optional<DialSinkExtraData> dial_data_; | |
| 95 | |
| 96 // Set if sink is Cast sink. | |
| 97 base::Optional<CastSinkExtraData> cast_data_; | |
| 98 }; | |
| 99 | |
| 100 } // namespace media_router | |
| 101 | |
| 102 #endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_INTERNAL_H_ | |
| OLD | NEW |