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. | |
23 base::scoped_nsobject<NSArray> _matches; | |
24 } | 25 } |
kkhorimoto
2017/06/01 19:25:27
Can you also remove the curly braces themselves?
lindsayw
2017/06/02 13:31:51
Done.
| |
25 | 26 |
26 // Loads |_matches| from config file |plistFileName|. | 27 // Loads |_matches| from config file |plistFileName|. |
27 - (void)loadConfigFile:(NSString*)plistFileName; | 28 - (void)loadConfigFile:(NSString*)plistFileName; |
28 | 29 |
29 @end | 30 @end |
30 | 31 |
31 @implementation SpeechInputLocaleMatchConfig | 32 @implementation SpeechInputLocaleMatchConfig |
33 @synthesize matches = _matches; | |
32 | 34 |
33 + (instancetype)sharedInstance { | 35 + (instancetype)sharedInstance { |
34 static SpeechInputLocaleMatchConfig* matchConfig; | 36 static SpeechInputLocaleMatchConfig* matchConfig; |
35 static dispatch_once_t onceToken; | 37 static dispatch_once_t onceToken; |
36 dispatch_once(&onceToken, ^{ | 38 dispatch_once(&onceToken, ^{ |
37 matchConfig = [[SpeechInputLocaleMatchConfig alloc] init]; | 39 matchConfig = [[SpeechInputLocaleMatchConfig alloc] init]; |
38 }); | 40 }); |
39 return matchConfig; | 41 return matchConfig; |
40 } | 42 } |
41 | 43 |
42 - (instancetype)init { | 44 - (instancetype)init { |
43 self = [super init]; | 45 self = [super init]; |
44 if (self) { | 46 if (self) { |
45 [self loadConfigFile:@"SpeechInputLocaleMatches"]; | 47 [self loadConfigFile:@"SpeechInputLocaleMatches"]; |
46 } | 48 } |
47 return self; | 49 return self; |
48 } | 50 } |
49 | 51 |
50 #pragma mark Accessors | |
51 | |
52 - (NSArray*)matches { | |
53 return _matches.get(); | |
54 } | |
55 | 52 |
56 #pragma mark - Private | 53 #pragma mark - Private |
57 | 54 |
58 - (void)loadConfigFile:(NSString*)plistFileName { | 55 - (void)loadConfigFile:(NSString*)plistFileName { |
59 NSString* path = [[NSBundle mainBundle] pathForResource:plistFileName | 56 NSString* path = [[NSBundle mainBundle] pathForResource:plistFileName |
60 ofType:@"plist" | 57 ofType:@"plist" |
61 inDirectory:@"gm-config/ANY"]; | 58 inDirectory:@"gm-config/ANY"]; |
62 NSArray* configData = [NSArray arrayWithContentsOfFile:path]; | 59 NSArray* configData = [NSArray arrayWithContentsOfFile:path]; |
63 NSMutableArray* matches = [NSMutableArray array]; | 60 NSMutableArray* matches = [NSMutableArray array]; |
64 for (id item in configData) { | 61 for (id item in configData) { |
65 NSDictionary* matchDict = base::mac::ObjCCastStrict<NSDictionary>(item); | 62 NSDictionary* matchDict = base::mac::ObjCCastStrict<NSDictionary>(item); |
66 base::scoped_nsobject<SpeechInputLocaleMatch> match( | 63 SpeechInputLocaleMatch* match = |
67 [[SpeechInputLocaleMatch alloc] initWithDictionary:matchDict]); | 64 [[SpeechInputLocaleMatch alloc] initWithDictionary:matchDict]; |
68 [matches addObject:match]; | 65 [matches addObject:match]; |
69 } | 66 } |
70 _matches.reset([matches copy]); | 67 _matches = [matches copy]; |
71 } | 68 } |
72 | 69 |
73 @end | 70 @end |
74 | 71 |
75 #pragma mark - SpeechInputLocaleMatch | 72 #pragma mark - SpeechInputLocaleMatch |
76 | 73 |
77 @interface SpeechInputLocaleMatch () { | |
78 // Backing objects for properties of the same name. | |
79 base::scoped_nsobject<NSString> _matchedLocaleCode; | |
80 base::scoped_nsobject<NSArray> _matchingLocaleCodes; | |
81 base::scoped_nsobject<NSArray> _matchingLanguages; | |
82 } | |
83 | |
84 @end | |
85 | |
86 @implementation SpeechInputLocaleMatch | 74 @implementation SpeechInputLocaleMatch |
75 @synthesize matchedLocaleCode = _matchedLocaleCode; | |
76 @synthesize matchingLocaleCodes = _matchingLocaleCodes; | |
77 @synthesize matchingLanguages = _matchingLanguages; | |
87 | 78 |
88 - (instancetype)initWithDictionary:(NSDictionary*)matchDict { | 79 - (instancetype)initWithDictionary:(NSDictionary*)matchDict { |
89 if ((self = [super init])) { | 80 if ((self = [super init])) { |
90 _matchedLocaleCode.reset([matchDict[kMatchedLocaleKey] copy]); | 81 _matchedLocaleCode = [matchDict[kMatchedLocaleKey] copy]; |
91 _matchingLocaleCodes.reset([matchDict[kMatchingLocalesKey] copy]); | 82 _matchingLocaleCodes = [matchDict[kMatchingLocalesKey] copy]; |
92 _matchingLanguages.reset([matchDict[kMatchingLanguagesKey] copy]); | 83 _matchingLanguages = [matchDict[kMatchingLanguagesKey] copy]; |
93 } | 84 } |
94 return self; | 85 return self; |
95 } | 86 } |
96 | 87 |
97 #pragma mark Accessors | |
98 | |
99 - (NSString*)matchedLocaleCode { | |
100 return _matchedLocaleCode; | |
101 } | |
102 | |
103 - (NSArray*)matchingLocaleCodes { | |
104 return _matchingLocaleCodes; | |
105 } | |
106 | |
107 - (NSArray*)matchingLanguages { | |
108 return _matchingLanguages; | |
109 } | |
110 | |
111 @end | 88 @end |
OLD | NEW |