| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/i18n/string_compare.h" | |
| 6 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "chrome/browser/media/router/media_sink.h" | |
| 8 #include "third_party/icu/source/i18n/unicode/coll.h" | |
| 9 | |
| 10 namespace media_router { | |
| 11 | |
| 12 MediaSink::MediaSink(const MediaSink::Id& sink_id, | |
| 13 const std::string& name, | |
| 14 const MediaSink::IconType icon_type) | |
| 15 : sink_id_(sink_id), name_(name), icon_type_(icon_type) {} | |
| 16 | |
| 17 MediaSink::MediaSink(const MediaSink& other) = default; | |
| 18 | |
| 19 MediaSink::MediaSink() {} | |
| 20 | |
| 21 MediaSink::~MediaSink() { | |
| 22 } | |
| 23 | |
| 24 bool MediaSink::Equals(const MediaSink& other) const { | |
| 25 return sink_id_ == other.sink_id_; | |
| 26 } | |
| 27 | |
| 28 bool MediaSink::operator==(const MediaSink& other) const { | |
| 29 return sink_id_ == other.sink_id_ && name_ == other.name_ && | |
| 30 description_ == other.description_ && domain_ == other.domain_ && | |
| 31 icon_type_ == other.icon_type_; | |
| 32 } | |
| 33 | |
| 34 bool MediaSink::operator!=(const MediaSink& other) const { | |
| 35 return !operator==(other); | |
| 36 } | |
| 37 | |
| 38 bool MediaSink::CompareUsingCollator(const MediaSink& other, | |
| 39 const icu::Collator* collator) const { | |
| 40 if (icon_type_ != other.icon_type_) | |
| 41 return icon_type_ < other.icon_type_; | |
| 42 | |
| 43 if (collator) { | |
| 44 base::string16 this_name = base::UTF8ToUTF16(name_); | |
| 45 base::string16 other_name = base::UTF8ToUTF16(other.name_); | |
| 46 UCollationResult result = base::i18n::CompareString16WithCollator( | |
| 47 *collator, this_name, other_name); | |
| 48 if (result != UCOL_EQUAL) | |
| 49 return result == UCOL_LESS; | |
| 50 } else { | |
| 51 // Fall back to simple string comparison if collator is not | |
| 52 // available. | |
| 53 int val = name_.compare(other.name_); | |
| 54 if (val) | |
| 55 return val < 0; | |
| 56 } | |
| 57 | |
| 58 return sink_id_ < other.sink_id_; | |
| 59 } | |
| 60 | |
| 61 } // namespace media_router | |
| OLD | NEW |