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

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

Issue 2425713002: [ios] Adds configuration helper files for voice search. (Closed)
Patch Set: Separate targets. 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_UI_VOICE_SPEECH_INPUT_LOCALE_CONFIG_IMPL_H_
6 #define IOS_CHROME_BROWSER_UI_VOICE_SPEECH_INPUT_LOCALE_CONFIG_IMPL_H_
7
8 #include <map>
9
10 #include "base/memory/singleton.h"
11 #include "ios/chrome/browser/ui/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);
31
32 // SpeechInputLocaleConfig:
33 SpeechInputLocale GetDefaultLocale() override;
34 const std::vector<SpeechInputLocale>& GetAvailableLocales() override;
35 SpeechInputLocale GetLocaleForCode(const std::string& locale_code) override;
36 const std::vector<std::string>& GetTextToSpeechLanguages() override;
37 bool IsTextToSpeechEnabledForCode(const std::string& locale_code) override;
38
39 protected:
40 // The constructor is protected, as the object must be referenced via
41 // SpeechInputLocaleConfig's singleton getter.
42 SpeechInputLocaleConfigImpl();
43 ~SpeechInputLocaleConfigImpl() override;
44
45 private:
46 // Returns a canonical locale code created from combining the UI language
47 // preference from NSLocale's |+preferredLanguages| and the country code from
48 // the device's locale.
49 std::string GetDefaultLocaleCode();
50
51 // Populates |available_locales_| using S3Kit's language manager.
52 void InitializeAvailableLocales();
53
54 // Adds local matching data from speech_input_matches.plist into
55 // |locale_indices_for_codes_|.
56 void InitializeLocaleMatches();
57
58 // Populates |text_to_speech_languages_| with the available locales.
59 void InitializeTextToSpeechLangauges();
60
61 friend struct base::DefaultSingletonTraits<SpeechInputLocaleConfigImpl>;
62
63 // The list of available speech input locales.
64 std::vector<SpeechInputLocale> available_locales_;
65 // A map storing canonical locale codes with the index of their associated
66 // InputLocale within |available_locales_|.
67 std::map<std::string, size_t> locale_indices_for_codes_;
68 // A map storing the language portions of locale codes with the index of their
69 // associated InputLocale within |available_locales_|.
70 std::map<std::string, size_t> default_locale_indices_for_languages_;
71 // The languages available for Text To Speech search results.
72 std::vector<std::string> text_to_speech_languages_;
73
74 DISALLOW_COPY_AND_ASSIGN(SpeechInputLocaleConfigImpl);
75 };
76
77 } // namespace voice
78
79 #endif // IOS_CHROME_BROWSER_UI_VOICE_SPEECH_INPUT_LOCALE_CONFIG_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698