Chromium Code Reviews| 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 #import "ios/chrome/browser/voice/speech_input_locale_match_config.h" | 5 #import "ios/chrome/browser/voice/speech_input_locale_match_config.h" |
| 6 | 6 |
| 7 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 8 |
| 9 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 10 #error "This file requires ARC support." | |
| 11 #endif | |
| 9 | 12 |
| 10 namespace { | 13 namespace { |
| 11 | 14 |
| 12 // Keys used in SpeechInputLocaleMatches.plist: | 15 // Keys used in SpeechInputLocaleMatches.plist: |
| 13 NSString* const kMatchedLocaleKey = @"Locale"; | 16 NSString* const kMatchedLocaleKey = @"Locale"; |
| 14 NSString* const kMatchingLocalesKey = @"MatchingLocales"; | 17 NSString* const kMatchingLocalesKey = @"MatchingLocales"; |
| 15 NSString* const kMatchingLanguagesKey = @"MatchingLanguages"; | 18 NSString* const kMatchingLanguagesKey = @"MatchingLanguages"; |
| 16 | 19 |
| 17 } // namespace | 20 } // namespace |
| 18 | 21 |
| 19 #pragma mark - SpeechInputLocaleMatchConfig | 22 #pragma mark - SpeechInputLocaleMatchConfig |
| 20 | 23 |
| 21 @interface SpeechInputLocaleMatchConfig () { | 24 @interface SpeechInputLocaleMatchConfig () { |
| 22 // Backing object for the property of the same name. | 25 // Backing object for the property of the same name. |
| 23 base::scoped_nsobject<NSArray> _matches; | 26 NSArray* _matches; |
| 24 } | 27 } |
|
kkhorimoto
2017/05/25 19:07:36
This whole block within the curly braces can be re
lindsayw
2017/06/01 19:22:46
Done.
| |
| 25 | 28 |
| 26 // Loads |_matches| from config file |plistFileName|. | 29 // Loads |_matches| from config file |plistFileName|. |
| 27 - (void)loadConfigFile:(NSString*)plistFileName; | 30 - (void)loadConfigFile:(NSString*)plistFileName; |
| 28 | 31 |
| 29 @end | 32 @end |
| 30 | 33 |
| 31 @implementation SpeechInputLocaleMatchConfig | 34 @implementation SpeechInputLocaleMatchConfig |
| 32 | 35 |
|
kkhorimoto
2017/05/25 19:07:36
Can you synthesize the property here?
@synthesize
lindsayw
2017/06/01 19:22:46
Done.
| |
| 33 + (instancetype)sharedInstance { | 36 + (instancetype)sharedInstance { |
| 34 static SpeechInputLocaleMatchConfig* matchConfig; | 37 static SpeechInputLocaleMatchConfig* matchConfig; |
| 35 static dispatch_once_t onceToken; | 38 static dispatch_once_t onceToken; |
| 36 dispatch_once(&onceToken, ^{ | 39 dispatch_once(&onceToken, ^{ |
| 37 matchConfig = [[SpeechInputLocaleMatchConfig alloc] init]; | 40 matchConfig = [[SpeechInputLocaleMatchConfig alloc] init]; |
| 38 }); | 41 }); |
| 39 return matchConfig; | 42 return matchConfig; |
| 40 } | 43 } |
| 41 | 44 |
| 42 - (instancetype)init { | 45 - (instancetype)init { |
| 43 self = [super init]; | 46 self = [super init]; |
| 44 if (self) { | 47 if (self) { |
| 45 [self loadConfigFile:@"SpeechInputLocaleMatches"]; | 48 [self loadConfigFile:@"SpeechInputLocaleMatches"]; |
| 46 } | 49 } |
| 47 return self; | 50 return self; |
| 48 } | 51 } |
| 49 | 52 |
| 50 #pragma mark Accessors | 53 #pragma mark Accessors |
| 51 | 54 |
| 52 - (NSArray*)matches { | 55 - (NSArray*)matches { |
| 53 return _matches.get(); | 56 return _matches; |
| 54 } | 57 } |
|
kkhorimoto
2017/05/25 19:07:36
This will also be handled by property synthesis
lindsayw
2017/06/01 19:22:46
Ok, so I just deleted the line 56, please let me k
| |
| 55 | 58 |
| 56 #pragma mark - Private | 59 #pragma mark - Private |
| 57 | 60 |
| 58 - (void)loadConfigFile:(NSString*)plistFileName { | 61 - (void)loadConfigFile:(NSString*)plistFileName { |
| 59 NSString* path = [[NSBundle mainBundle] pathForResource:plistFileName | 62 NSString* path = [[NSBundle mainBundle] pathForResource:plistFileName |
| 60 ofType:@"plist" | 63 ofType:@"plist" |
| 61 inDirectory:@"gm-config/ANY"]; | 64 inDirectory:@"gm-config/ANY"]; |
| 62 NSArray* configData = [NSArray arrayWithContentsOfFile:path]; | 65 NSArray* configData = [NSArray arrayWithContentsOfFile:path]; |
| 63 NSMutableArray* matches = [NSMutableArray array]; | 66 NSMutableArray* matches = [NSMutableArray array]; |
| 64 for (id item in configData) { | 67 for (id item in configData) { |
| 65 NSDictionary* matchDict = base::mac::ObjCCastStrict<NSDictionary>(item); | 68 NSDictionary* matchDict = base::mac::ObjCCastStrict<NSDictionary>(item); |
| 66 base::scoped_nsobject<SpeechInputLocaleMatch> match( | 69 SpeechInputLocaleMatch* match = |
| 67 [[SpeechInputLocaleMatch alloc] initWithDictionary:matchDict]); | 70 [[SpeechInputLocaleMatch alloc] initWithDictionary:matchDict]; |
| 68 [matches addObject:match]; | 71 [matches addObject:match]; |
| 69 } | 72 } |
| 70 _matches.reset([matches copy]); | 73 _matches = [matches copy]; |
| 71 } | 74 } |
| 72 | 75 |
| 73 @end | 76 @end |
| 74 | 77 |
| 75 #pragma mark - SpeechInputLocaleMatch | 78 #pragma mark - SpeechInputLocaleMatch |
| 76 | 79 |
| 77 @interface SpeechInputLocaleMatch () { | 80 @interface SpeechInputLocaleMatch () { |
| 78 // Backing objects for properties of the same name. | 81 // Backing objects for properties of the same name. |
| 79 base::scoped_nsobject<NSString> _matchedLocaleCode; | 82 NSString* _matchedLocaleCode; |
| 80 base::scoped_nsobject<NSArray> _matchingLocaleCodes; | 83 NSArray* _matchingLocaleCodes; |
| 81 base::scoped_nsobject<NSArray> _matchingLanguages; | 84 NSArray* _matchingLanguages; |
| 82 } | 85 } |
| 83 | 86 |
| 84 @end | 87 @end |
|
kkhorimoto
2017/05/25 19:07:36
This whole @interface section can be removed if yo
lindsayw
2017/06/01 19:22:46
Done.
| |
| 85 | 88 |
| 86 @implementation SpeechInputLocaleMatch | 89 @implementation SpeechInputLocaleMatch |
| 87 | 90 |
|
kkhorimoto
2017/05/25 19:07:37
@synthesize matchedLocaleCode = _matchedLocaleCode
lindsayw
2017/06/01 19:22:46
Done.
| |
| 88 - (instancetype)initWithDictionary:(NSDictionary*)matchDict { | 91 - (instancetype)initWithDictionary:(NSDictionary*)matchDict { |
| 89 if ((self = [super init])) { | 92 if ((self = [super init])) { |
| 90 _matchedLocaleCode.reset([matchDict[kMatchedLocaleKey] copy]); | 93 _matchedLocaleCode = [matchDict[kMatchedLocaleKey] copy]; |
| 91 _matchingLocaleCodes.reset([matchDict[kMatchingLocalesKey] copy]); | 94 _matchingLocaleCodes = [matchDict[kMatchingLocalesKey] copy]; |
| 92 _matchingLanguages.reset([matchDict[kMatchingLanguagesKey] copy]); | 95 _matchingLanguages = [matchDict[kMatchingLanguagesKey] copy]; |
| 93 } | 96 } |
| 94 return self; | 97 return self; |
| 95 } | 98 } |
| 96 | 99 |
| 97 #pragma mark Accessors | 100 #pragma mark Accessors |
| 98 | 101 |
| 99 - (NSString*)matchedLocaleCode { | 102 - (NSString*)matchedLocaleCode { |
| 100 return _matchedLocaleCode; | 103 return _matchedLocaleCode; |
| 101 } | 104 } |
| 102 | 105 |
| 103 - (NSArray*)matchingLocaleCodes { | 106 - (NSArray*)matchingLocaleCodes { |
| 104 return _matchingLocaleCodes; | 107 return _matchingLocaleCodes; |
| 105 } | 108 } |
| 106 | 109 |
| 107 - (NSArray*)matchingLanguages { | 110 - (NSArray*)matchingLanguages { |
| 108 return _matchingLanguages; | 111 return _matchingLanguages; |
| 109 } | 112 } |
|
kkhorimoto
2017/05/25 19:07:37
All three of these can be removed.
lindsayw
2017/06/01 19:22:46
Done.
| |
| 110 | 113 |
| 111 @end | 114 @end |
| OLD | NEW |