Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_BROWSER_MEDIA_ROUTER_MEDIA_SINK_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_SINK_H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_SINK_H_ | 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_SINK_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/optional.h" | |
| 10 #include "third_party/icu/source/common/unicode/uversion.h" | 11 #include "third_party/icu/source/common/unicode/uversion.h" |
| 11 | 12 |
| 12 namespace U_ICU_NAMESPACE { | 13 namespace U_ICU_NAMESPACE { |
| 13 class Collator; | 14 class Collator; |
| 14 } // namespace U_ICU_NAMESPACE | 15 } // namespace U_ICU_NAMESPACE |
| 15 | 16 |
| 16 namespace media_router { | 17 namespace media_router { |
| 17 | 18 |
| 18 // Represents a sink to which media can be routed. | 19 // Represents a sink to which media can be routed. |
| 20 // TODO(zhaobin): convert MediaSink into a struct. | |
| 19 class MediaSink { | 21 class MediaSink { |
| 20 public: | 22 public: |
| 21 using Id = std::string; | 23 using Id = std::string; |
| 22 | 24 |
| 23 // IconTypes are listed in the order in which sinks should be sorted. | 25 // IconTypes are listed in the order in which sinks should be sorted. |
| 24 // The order must stay in sync with | 26 // The order must stay in sync with |
| 25 // chrome/browser/resources/media_router/media_router_data.js. | 27 // chrome/browser/resources/media_router/media_router_data.js. |
| 26 enum IconType { | 28 enum IconType { |
| 27 CAST, | 29 CAST, |
| 28 CAST_AUDIO_GROUP, | 30 CAST_AUDIO_GROUP, |
| 29 CAST_AUDIO, | 31 CAST_AUDIO, |
| 30 HANGOUT, | 32 HANGOUT, |
| 31 GENERIC | 33 GENERIC |
| 32 }; | 34 }; |
| 33 | 35 |
| 36 // SinkType indicates if sink is discovered by DIAL / CAST / other (e.g. | |
| 37 // cloud) media sink services. Each SinkType value, with the exception of | |
| 38 // GENERIC, corresponds to a subtype of MediaSink. | |
| 39 enum class SinkType { | |
| 40 DIAL, // DialMediaSink | |
| 41 CAST, // CastMediaSink | |
| 42 GENERIC | |
| 43 }; | |
| 44 | |
| 34 MediaSink(const MediaSink::Id& sink_id, | 45 MediaSink(const MediaSink::Id& sink_id, |
| 35 const std::string& name, | 46 const std::string& name, |
| 36 const IconType icon_type); | 47 const IconType icon_type); |
| 37 | 48 |
| 38 MediaSink(const MediaSink& other); | 49 MediaSink(const MediaSink& other); |
| 39 | 50 |
| 40 ~MediaSink(); | 51 virtual ~MediaSink(); |
| 41 | 52 |
| 53 SinkType type() const { return type_; } | |
|
imcheng
2017/02/09 02:19:57
We should make this method virtual, and return GEN
| |
| 42 const MediaSink::Id& id() const { return sink_id_; } | 54 const MediaSink::Id& id() const { return sink_id_; } |
| 43 const std::string& name() const { return name_; } | 55 const std::string& name() const { return name_; } |
| 44 void set_description(const std::string& description) { | 56 void set_description(const std::string& description) { |
| 45 description_ = description; | 57 description_ = description; |
| 46 } | 58 } |
| 47 const std::string& description() const { return description_; } | 59 const base::Optional<std::string>& description() const { |
| 60 return description_; | |
| 61 } | |
| 48 void set_domain(const std::string& domain) { domain_ = domain; } | 62 void set_domain(const std::string& domain) { domain_ = domain; } |
| 49 const std::string& domain() const { return domain_; } | 63 const base::Optional<std::string>& domain() const { return domain_; } |
| 50 IconType icon_type() const { return icon_type_; } | 64 IconType icon_type() const { return icon_type_; } |
| 65 void set_model_name(const std::string& model_name) { | |
| 66 model_name_ = model_name; | |
| 67 } | |
| 68 const base::Optional<std::string>& model_name() const { return model_name_; } | |
| 51 | 69 |
| 70 // This method only compares IDs. | |
| 52 bool Equals(const MediaSink& other) const; | 71 bool Equals(const MediaSink& other) const; |
| 53 | 72 |
| 54 // Compares |this| to |other| first by their icon types, then their names | 73 // Compares |this| to |other| first by their icon types, then their names |
| 55 // using |collator|, and finally their IDs. | 74 // using |collator|, and finally their IDs. |
| 56 bool CompareUsingCollator(const MediaSink& other, | 75 bool CompareUsingCollator(const MediaSink& other, |
| 57 const icu::Collator* collator) const; | 76 const icu::Collator* collator) const; |
| 58 | 77 |
| 59 // For storing in sets and in maps as keys. | 78 // For storing in sets and in maps as keys. |
| 60 struct Compare { | 79 struct Compare { |
| 61 bool operator()(const MediaSink& sink1, const MediaSink& sink2) const { | 80 bool operator()(const MediaSink& sink1, const MediaSink& sink2) const { |
| 62 return sink1.id() < sink2.id(); | 81 return sink1.id() < sink2.id(); |
| 63 } | 82 } |
| 64 }; | 83 }; |
| 65 | 84 |
| 85 protected: | |
| 86 MediaSink(const MediaSink::Id& sink_id, | |
| 87 const std::string& name, | |
| 88 const IconType icon_type, | |
| 89 const SinkType sink_type); | |
| 90 | |
| 91 // Type of the MediaSink. | |
| 92 SinkType type_; | |
| 93 | |
| 66 private: | 94 private: |
| 67 // Unique identifier for the MediaSink. | 95 // Unique identifier for the MediaSink. |
| 68 MediaSink::Id sink_id_; | 96 MediaSink::Id sink_id_; |
| 69 | 97 |
| 70 // Descriptive name of the MediaSink. | 98 // Descriptive name of the MediaSink. |
| 71 std::string name_; | 99 std::string name_; |
| 72 | 100 |
| 73 // Optional description of the MediaSink. | 101 base::Optional<std::string> description_; |
| 74 std::string description_; | |
| 75 | 102 |
| 76 // Optional domain of the MediaSink. | 103 base::Optional<std::string> domain_; |
| 77 std::string domain_; | |
| 78 | 104 |
| 79 // The type of icon that corresponds with the MediaSink. | 105 // The type of icon that corresponds with the MediaSink. |
| 80 IconType icon_type_; | 106 IconType icon_type_; |
| 107 | |
| 108 // Model name of the sink, if it represents a physical device. | |
| 109 base::Optional<std::string> model_name_; | |
| 81 }; | 110 }; |
| 82 | 111 |
| 83 } // namespace media_router | 112 } // namespace media_router |
| 84 | 113 |
| 85 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_SINK_H_ | 114 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_SINK_H_ |
| OLD | NEW |