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

Side by Side Diff: ios/chrome/browser/ui/voice/speech_input_locale_match_config.mm

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 #import "ios/chrome/browser/ui/voice/speech_input_locale_match_config.h"
6
7 #import "base/mac/scoped_nsobject.h"
8
9 namespace {
10
11 // Name of plist file containing locale matches.
12 NSString* const kLocaleMatchesFilename = @"SpeechInputLocaleMatches.plist";
13
14 // Keys used in SpeechInputLocaleMatches.plist:
15 NSString* const kMatchedLocaleKey = @"Locale";
16 NSString* const kMatchingLocalesKey = @"MatchingLocales";
17 NSString* const kMatchingLanguagesKey = @"MatchingLanguages";
18 }
sdefresne 2016/10/17 16:12:40 nit: blank line before closing the namespace and t
rohitrao (ping after 24h) 2016/10/17 17:42:27 Done.
19
20 #pragma mark - SpeechInputLocaleMatchConfig
21
22 @interface SpeechInputLocaleMatchConfig () {
23 // Backing object for the property of the same name.
24 base::scoped_nsobject<NSArray> _matches;
25 }
26
27 @end
28
29 @implementation SpeechInputLocaleMatchConfig
30
31 + (instancetype)sharedInstance {
32 static SpeechInputLocaleMatchConfig* matchConfig;
33 static dispatch_once_t onceToken;
34 dispatch_once(&onceToken, ^{
35 matchConfig = [[SpeechInputLocaleMatchConfig alloc] init];
36 });
37 return matchConfig;
38 }
39
40 - (instancetype)init {
41 self = [super initWithAppId:nil version:nil plist:kLocaleMatchesFilename];
42 if (self)
43 self.stopsUpdateChecksOnAppTermination = YES;
44 return self;
45 }
46
47 #pragma mark Accessors
48
49 - (NSArray*)matches {
50 if (!_matches) {
51 NSMutableArray* matches = [NSMutableArray array];
52 for (NSDictionary* matchDict in [self arrayFromConfig]) {
53 SpeechInputLocaleMatch* match = [[[SpeechInputLocaleMatch alloc]
54 initWithDictionary:matchDict] autorelease];
55 [matches addObject:match];
56 }
57 _matches.reset([[NSArray alloc] initWithArray:matches]);
sdefresne 2016/10/17 16:12:40 nit: would be better to use -copy here _matches
rohitrao (ping after 24h) 2016/10/17 17:42:27 Done.
58 }
59 return _matches;
60 }
61
62 #pragma mark UpdatableConfigBase
63
64 - (void)resourceDidUpdate:(NSNotification*)notification {
65 [super resourceDidUpdate:notification];
66 _matches.reset();
67 }
68
69 @end
70
71 #pragma mark - SpeechInputLocaleMatch
72
73 @interface SpeechInputLocaleMatch () {
74 // Backing objects for properties of the same name.
75 base::scoped_nsobject<NSString> _matchedLocaleCode;
76 base::scoped_nsobject<NSArray> _matchingLocaleCodes;
77 base::scoped_nsobject<NSArray> _matchingLanguages;
78 }
79
80 @end
81
82 @implementation SpeechInputLocaleMatch
83
84 - (instancetype)initWithDictionary:(NSDictionary*)matchDict {
85 if ((self = [super init])) {
86 _matchedLocaleCode.reset([matchDict[kMatchedLocaleKey] copy]);
87 _matchingLocaleCodes.reset([matchDict[kMatchingLocalesKey] copy]);
88 _matchingLanguages.reset([matchDict[kMatchingLanguagesKey] copy]);
89 }
90 return self;
91 }
92
93 #pragma mark Accessors
94
95 - (NSString*)matchedLocaleCode {
96 return _matchedLocaleCode;
97 }
98
99 - (NSArray*)matchingLocaleCodes {
100 return _matchingLocaleCodes;
101 }
102
103 - (NSArray*)matchingLanguages {
104 return _matchingLanguages;
105 }
106
107 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698