Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Side by Side Diff: ios/chrome/browser/voice/speech_input_locale_config_impl.h

Issue 2425713002: [ios] Adds configuration helper files for voice search. (Closed)
Patch Set: Review and file moves. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef IOS_CHROME_BROWSER_VOICE_SPEECH_INPUT_LOCALE_CONFIG_IMPL_H_
6 #define IOS_CHROME_BROWSER_VOICE_SPEECH_INPUT_LOCALE_CONFIG_IMPL_H_
7
8 #include <map>
9
10 #include "base/memory/singleton.h"
11 #include "ios/chrome/browser/voice/speech_input_locale_config.h"
12
13 namespace base {
14 template <typename T>
15 struct DefaultSingletonTraits;
16 } // namespace base
17
18 namespace voice {
19
20 // A concrete implementation of SpeechInputLocaleConfig that uses the available
21 // language list from S3Kit and the speech input locale matching from
22 // SpeechInputLocaleMatches.plist.
23 class SpeechInputLocaleConfigImpl : public SpeechInputLocaleConfig {
24 public:
25 // Singleton getter for subclass.
26 static SpeechInputLocaleConfigImpl* GetInstance();
27
28 // Returns the available locale that matches |locale_code|. Defaults to en-US
29 // if a matching locale is not found.
30 SpeechInputLocale GetMatchingLocale(const std::string& locale_code) const;
31
32 // SpeechInputLocaleConfig:
33 SpeechInputLocale GetDefaultLocale() const override;
34 const std::vector<SpeechInputLocale>& GetAvailableLocales() const override;
35 SpeechInputLocale GetLocaleForCode(
36 const std::string& locale_code) const override;
37 const std::vector<std::string>& GetTextToSpeechLanguages() const override;
38 bool IsTextToSpeechEnabledForCode(
39 const std::string& locale_code) const override;
40
41 protected:
42 // The constructor is protected, as the object must be referenced via
43 // SpeechInputLocaleConfig's singleton getter.
44 SpeechInputLocaleConfigImpl();
45 ~SpeechInputLocaleConfigImpl() override;
46
47 private:
48 // Returns a canonical locale code created from combining the UI language
49 // preference from NSLocale's |+preferredLanguages| and the country code from
50 // the device's locale.
51 std::string GetDefaultLocaleCode() const;
52
53 // Populates |available_locales_| using S3Kit's language manager.
54 void InitializeAvailableLocales();
55
56 // Adds local matching data from speech_input_matches.plist into
57 // |locale_indices_for_codes_|.
58 void InitializeLocaleMatches();
59
60 // Populates |text_to_speech_languages_| with the available locales.
61 void InitializeTextToSpeechLangauges();
62
63 friend struct base::DefaultSingletonTraits<SpeechInputLocaleConfigImpl>;
64
65 // The list of available speech input locales.
66 std::vector<SpeechInputLocale> available_locales_;
67 // A map storing canonical locale codes with the index of their associated
68 // InputLocale within |available_locales_|.
69 std::map<std::string, size_t> locale_indices_for_codes_;
70 // A map storing the language portions of locale codes with the index of their
71 // associated InputLocale within |available_locales_|.
72 std::map<std::string, size_t> default_locale_indices_for_languages_;
73 // The languages available for Text To Speech search results.
74 std::vector<std::string> text_to_speech_languages_;
75
76 DISALLOW_COPY_AND_ASSIGN(SpeechInputLocaleConfigImpl);
77 };
78
79 } // namespace voice
80
81 #endif // IOS_CHROME_BROWSER_VOICE_SPEECH_INPUT_LOCALE_CONFIG_IMPL_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/voice/speech_input_locale_config.mm ('k') | ios/chrome/browser/voice/speech_input_locale_config_impl.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698