Chromium Code Reviews| Index: chrome/browser/media/router/discovery/media_sink_internal.h |
| diff --git a/chrome/browser/media/router/discovery/media_sink_internal.h b/chrome/browser/media/router/discovery/media_sink_internal.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..331ab4e6893846f25078f2c8bad7ee3f25387960 |
| --- /dev/null |
| +++ b/chrome/browser/media/router/discovery/media_sink_internal.h |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_INTERNAL_H_ |
| +#define CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_INTERNAL_H_ |
| + |
| +#include "chrome/browser/media/router/media_sink.h" |
| +#include "net/base/ip_address.h" |
| +#include "url/gurl.h" |
| + |
| +namespace media_router { |
| + |
| +// Extra data for DIAL media sink. |
| +struct DialSinkExtraData { |
| + net::IPAddress ip_address; |
| + |
| + // Model name of the sink. |
| + std::string model_name; |
| + |
| + // The base URL used for DIAL operations. |
| + GURL app_url; |
| + |
| + DialSinkExtraData(); |
| + DialSinkExtraData(const DialSinkExtraData& other); |
| + ~DialSinkExtraData(); |
| +}; |
| + |
| +// Extra data for cast media sink. |
| +struct CastSinkExtraData { |
| + net::IPAddress ip_address; |
| + |
| + // Model name of the sink. |
| + std::string model_name; |
| + |
| + // A bit vector representing the capabilities of the sink. The values are |
| + // defined in media_router.mojom. |
| + int capabilities = 0; |
| + |
| + // ID of Cast channel opened for the sink. The caller must set this value to a |
| + // valid cast_channel_id. The cast_channel_id may change over time as the |
| + // browser reconnects to a device. |
| + int cast_channel_id = 0; |
| + |
| + CastSinkExtraData(); |
| + CastSinkExtraData(const CastSinkExtraData& other); |
| + ~CastSinkExtraData(); |
| +}; |
| + |
| +// Represents a media sink discovered by MediaSinkService. It is used by |
| +// MediaSinkService to push MediaSinks with extra data to the |
| +// MediaRouteProvider, and it is not exposed to users of MediaRouter. |
| +class MediaSinkInternal { |
| + public: |
| + // Used by mojo. |
| + MediaSinkInternal(); |
| + |
| + // Used by unit test. |
| + explicit MediaSinkInternal(const MediaSink& sink); |
| + |
| + // Used by MediaSinkService to create media sinks. |
| + MediaSinkInternal(const MediaSink& sink, const DialSinkExtraData& dial_data); |
| + MediaSinkInternal(const MediaSink& sink, const CastSinkExtraData& cast_data); |
| + |
| + // Used to push instance of this class into vector. |
| + MediaSinkInternal(const MediaSinkInternal& other); |
| + |
| + ~MediaSinkInternal(); |
| + |
| + MediaSinkInternal& operator=(const MediaSinkInternal& other); |
| + |
| + void set_sink(const MediaSink& sink); |
| + const MediaSink& sink() const { return sink_; } |
| + |
| + void set_dial_data(const DialSinkExtraData& dial_data); |
| + |
| + // Must only be called if the sink is a DIAL sink. |
| + const DialSinkExtraData& dial_data() const; |
| + |
| + void set_cast_data(const CastSinkExtraData& cast_data); |
| + |
| + // Must only be called if the sink is a Cast sink. |
| + const CastSinkExtraData& cast_data() const; |
| + |
| + bool is_dial_sink() const { return dial_data_ && !cast_data_; } |
| + bool is_cast_sink() const { return cast_data_ && !dial_data_; } |
| + |
| + static bool IsValidSinkId(const std::string& sink_id); |
| + |
| + private: |
| + MediaSink sink_; |
| + |
| + // 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.
|
| + base::Optional<DialSinkExtraData> dial_data_; |
| + |
| + // Set if sink is Cast sink. |
| + base::Optional<CastSinkExtraData> cast_data_; |
| +}; |
| + |
| +} // namespace media_router |
| + |
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_DISCOVERY_MEDIA_SINK_INTERNAL_H_ |