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 #include "ios/chrome/app/startup/register_experimental_settings.h" | 5 #include "ios/chrome/app/startup/register_experimental_settings.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
9 #import "base/mac/scoped_nsobject.h" | |
10 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
11 | 10 |
| 11 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 12 #error "This file requires ARC support." |
| 13 #endif |
| 14 |
12 namespace { | 15 namespace { |
13 // Key in the UserDefaults for the Experimental Keys. | 16 // Key in the UserDefaults for the Experimental Keys. |
14 NSString* kExperimentalKeysKey = @"ExperimentalKeys"; | 17 NSString* kExperimentalKeysKey = @"ExperimentalKeys"; |
15 | 18 |
16 // Returns YES if a setting value is equivalent to not having the setting at | 19 // Returns YES if a setting value is equivalent to not having the setting at |
17 // all. This must always be true for default values, otherwise the experimental | 20 // all. This must always be true for default values, otherwise the experimental |
18 // settings will have different default behaviors in stable channel (where the | 21 // settings will have different default behaviors in stable channel (where the |
19 // bundle isn't present). | 22 // bundle isn't present). |
20 BOOL IsDefaultSettingValueValid(id value) { | 23 BOOL IsDefaultSettingValueValid(id value) { |
21 if (!value) | 24 if (!value) |
(...skipping 25 matching lines...) Expand all Loading... |
47 NSDictionary* infoDictionary = [bundle infoDictionary]; | 50 NSDictionary* infoDictionary = [bundle infoDictionary]; |
48 NSString* version = [infoDictionary objectForKey:@"CFBundleVersion"]; | 51 NSString* version = [infoDictionary objectForKey:@"CFBundleVersion"]; |
49 [userDefaults setObject:version forKey:@"Version"]; | 52 [userDefaults setObject:version forKey:@"Version"]; |
50 | 53 |
51 NSString* bundlePath = [bundle bundlePath]; | 54 NSString* bundlePath = [bundle bundlePath]; |
52 NSString* settingsFilepath = | 55 NSString* settingsFilepath = |
53 [bundlePath stringByAppendingPathComponent:@"Settings.bundle"]; | 56 [bundlePath stringByAppendingPathComponent:@"Settings.bundle"]; |
54 NSArray* settingsContent = | 57 NSArray* settingsContent = |
55 [[NSFileManager defaultManager] contentsOfDirectoryAtPath:settingsFilepath | 58 [[NSFileManager defaultManager] contentsOfDirectoryAtPath:settingsFilepath |
56 error:NULL]; | 59 error:NULL]; |
57 base::scoped_nsobject<NSMutableArray> currentExpKeys( | 60 NSMutableArray* currentExpKeys = [[NSMutableArray alloc] init]; |
58 [[NSMutableArray alloc] init]); | |
59 | 61 |
60 for (NSString* filename in settingsContent) { | 62 for (NSString* filename in settingsContent) { |
61 // Only plist files are preferences definition. | 63 // Only plist files are preferences definition. |
62 if ([[filename pathExtension] isEqualToString:@"plist"]) { | 64 if ([[filename pathExtension] isEqualToString:@"plist"]) { |
63 NSString* filepath = | 65 NSString* filepath = |
64 [settingsFilepath stringByAppendingPathComponent:filename]; | 66 [settingsFilepath stringByAppendingPathComponent:filename]; |
65 NSArray* registeredKeys = | 67 NSArray* registeredKeys = |
66 [self registerExperimentalSettingsForFile:filepath | 68 [self registerExperimentalSettingsForFile:filepath |
67 userDefaults:userDefaults]; | 69 userDefaults:userDefaults]; |
68 [currentExpKeys addObjectsFromArray:registeredKeys]; | 70 [currentExpKeys addObjectsFromArray:registeredKeys]; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 id currentValue = [userDefaults objectForKey:keyValue]; | 121 id currentValue = [userDefaults objectForKey:keyValue]; |
120 if (currentValue && | 122 if (currentValue && |
121 (!defaultValue || [currentValue isEqual:defaultValue])) { | 123 (!defaultValue || [currentValue isEqual:defaultValue])) { |
122 [userDefaults removeObjectForKey:keyValue]; | 124 [userDefaults removeObjectForKey:keyValue]; |
123 } | 125 } |
124 } | 126 } |
125 return registeredKeys; | 127 return registeredKeys; |
126 } | 128 } |
127 | 129 |
128 @end | 130 @end |
OLD | NEW |