| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "ios/chrome/browser/voice/speech_input_locale_config_impl.h" | 5 #include "ios/chrome/browser/voice/speech_input_locale_config_impl.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
| 12 #include "base/stl_util.h" |
| 12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 14 #import "ios/chrome/browser/voice/speech_input_locale_match_config.h" | 15 #import "ios/chrome/browser/voice/speech_input_locale_match_config.h" |
| 15 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 16 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 16 #include "ios/public/provider/chrome/browser/voice/voice_search_language.h" | 17 #include "ios/public/provider/chrome/browser/voice/voice_search_language.h" |
| 17 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" | 18 #include "ios/public/provider/chrome/browser/voice/voice_search_provider.h" |
| 18 | 19 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 20 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." | 21 #error "This file requires ARC support." |
| 21 #endif | 22 #endif |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 77 } |
| 77 | 78 |
| 78 const std::vector<std::string>& | 79 const std::vector<std::string>& |
| 79 SpeechInputLocaleConfigImpl::GetTextToSpeechLanguages() const { | 80 SpeechInputLocaleConfigImpl::GetTextToSpeechLanguages() const { |
| 80 return text_to_speech_languages_; | 81 return text_to_speech_languages_; |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool SpeechInputLocaleConfigImpl::IsTextToSpeechEnabledForCode( | 84 bool SpeechInputLocaleConfigImpl::IsTextToSpeechEnabledForCode( |
| 84 const std::string& locale_code) const { | 85 const std::string& locale_code) const { |
| 85 std::string language = GetLanguageComponentForLocaleCode(locale_code); | 86 std::string language = GetLanguageComponentForLocaleCode(locale_code); |
| 86 auto found_language = std::find(text_to_speech_languages_.begin(), | 87 return base::ContainsValue(text_to_speech_languages_, language); |
| 87 text_to_speech_languages_.end(), language); | |
| 88 return found_language != text_to_speech_languages_.end(); | |
| 89 } | 88 } |
| 90 | 89 |
| 91 SpeechInputLocale SpeechInputLocaleConfigImpl::GetMatchingLocale( | 90 SpeechInputLocale SpeechInputLocaleConfigImpl::GetMatchingLocale( |
| 92 const std::string& locale_code) const { | 91 const std::string& locale_code) const { |
| 93 // Return exact match if one is found. | 92 // Return exact match if one is found. |
| 94 auto index_iterator = locale_indices_for_codes_.find(locale_code); | 93 auto index_iterator = locale_indices_for_codes_.find(locale_code); |
| 95 if (index_iterator != locale_indices_for_codes_.end()) | 94 if (index_iterator != locale_indices_for_codes_.end()) |
| 96 return available_locales_[index_iterator->second]; | 95 return available_locales_[index_iterator->second]; |
| 97 // If there is no exact match, search for another locale with the same | 96 // If there is no exact match, search for another locale with the same |
| 98 // language component. | 97 // language component. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 189 } |
| 191 } | 190 } |
| 192 } | 191 } |
| 193 } | 192 } |
| 194 | 193 |
| 195 void SpeechInputLocaleConfigImpl::InitializeTextToSpeechLangauges() { | 194 void SpeechInputLocaleConfigImpl::InitializeTextToSpeechLangauges() { |
| 196 text_to_speech_languages_ = {"de", "en", "es", "fr", "it", "ja", "ko"}; | 195 text_to_speech_languages_ = {"de", "en", "es", "fr", "it", "ja", "ko"}; |
| 197 } | 196 } |
| 198 | 197 |
| 199 } // namespace voice | 198 } // namespace voice |
| OLD | NEW |