| OLD | NEW |
| (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/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 |
| 19 } // namespace |
| 20 |
| 21 #pragma mark - SpeechInputLocaleMatchConfig |
| 22 |
| 23 @interface SpeechInputLocaleMatchConfig () { |
| 24 // Backing object for the property of the same name. |
| 25 base::scoped_nsobject<NSArray> _matches; |
| 26 } |
| 27 |
| 28 @end |
| 29 |
| 30 @implementation SpeechInputLocaleMatchConfig |
| 31 |
| 32 + (instancetype)sharedInstance { |
| 33 static SpeechInputLocaleMatchConfig* matchConfig; |
| 34 static dispatch_once_t onceToken; |
| 35 dispatch_once(&onceToken, ^{ |
| 36 matchConfig = [[SpeechInputLocaleMatchConfig alloc] init]; |
| 37 }); |
| 38 return matchConfig; |
| 39 } |
| 40 |
| 41 - (instancetype)init { |
| 42 self = [super initWithAppId:nil version:nil plist:kLocaleMatchesFilename]; |
| 43 if (self) |
| 44 self.stopsUpdateChecksOnAppTermination = YES; |
| 45 return self; |
| 46 } |
| 47 |
| 48 #pragma mark Accessors |
| 49 |
| 50 - (NSArray*)matches { |
| 51 if (!_matches) { |
| 52 NSMutableArray* matches = [NSMutableArray array]; |
| 53 for (NSDictionary* matchDict in [self arrayFromConfig]) { |
| 54 SpeechInputLocaleMatch* match = [[[SpeechInputLocaleMatch alloc] |
| 55 initWithDictionary:matchDict] autorelease]; |
| 56 [matches addObject:match]; |
| 57 } |
| 58 _matches.reset([matches copy]); |
| 59 } |
| 60 return _matches; |
| 61 } |
| 62 |
| 63 #pragma mark UpdatableConfigBase |
| 64 |
| 65 - (void)resourceDidUpdate:(NSNotification*)notification { |
| 66 [super resourceDidUpdate:notification]; |
| 67 _matches.reset(); |
| 68 } |
| 69 |
| 70 @end |
| 71 |
| 72 #pragma mark - SpeechInputLocaleMatch |
| 73 |
| 74 @interface SpeechInputLocaleMatch () { |
| 75 // Backing objects for properties of the same name. |
| 76 base::scoped_nsobject<NSString> _matchedLocaleCode; |
| 77 base::scoped_nsobject<NSArray> _matchingLocaleCodes; |
| 78 base::scoped_nsobject<NSArray> _matchingLanguages; |
| 79 } |
| 80 |
| 81 @end |
| 82 |
| 83 @implementation SpeechInputLocaleMatch |
| 84 |
| 85 - (instancetype)initWithDictionary:(NSDictionary*)matchDict { |
| 86 if ((self = [super init])) { |
| 87 _matchedLocaleCode.reset([matchDict[kMatchedLocaleKey] copy]); |
| 88 _matchingLocaleCodes.reset([matchDict[kMatchingLocalesKey] copy]); |
| 89 _matchingLanguages.reset([matchDict[kMatchingLanguagesKey] copy]); |
| 90 } |
| 91 return self; |
| 92 } |
| 93 |
| 94 #pragma mark Accessors |
| 95 |
| 96 - (NSString*)matchedLocaleCode { |
| 97 return _matchedLocaleCode; |
| 98 } |
| 99 |
| 100 - (NSArray*)matchingLocaleCodes { |
| 101 return _matchingLocaleCodes; |
| 102 } |
| 103 |
| 104 - (NSArray*)matchingLanguages { |
| 105 return _matchingLanguages; |
| 106 } |
| 107 |
| 108 @end |
| OLD | NEW |