OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/policy/policy_path_parser.h" | 5 #include "chrome/browser/policy/policy_path_parser.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
9 | 9 |
10 #import <Cocoa/Cocoa.h> | 10 #import <Cocoa/Cocoa.h> |
(...skipping 20 matching lines...) Expand all Loading... | |
31 const MacFolderNamesToSPDMaping mac_folder_mapping[] = { | 31 const MacFolderNamesToSPDMaping mac_folder_mapping[] = { |
32 { kMacUsersDirectory, NSUserDirectory}, | 32 { kMacUsersDirectory, NSUserDirectory}, |
33 { kMacDocumentsFolderVarName, NSDocumentDirectory} | 33 { kMacDocumentsFolderVarName, NSDocumentDirectory} |
34 }; | 34 }; |
35 | 35 |
36 // Replaces all variable occurrences in the policy string with the respective | 36 // Replaces all variable occurrences in the policy string with the respective |
37 // system settings values. | 37 // system settings values. |
38 FilePath::StringType ExpandPathVariables( | 38 FilePath::StringType ExpandPathVariables( |
39 const FilePath::StringType& untranslated_string) { | 39 const FilePath::StringType& untranslated_string) { |
40 FilePath::StringType result(untranslated_string); | 40 FilePath::StringType result(untranslated_string); |
41 if (!result.length()) | |
markusheintz_
2011/05/26 09:45:23
Nit: I'd prefere (result.length() == 0) here as it
| |
42 return result; | |
43 // Sanitize quotes in case of any around the whole string. | |
44 if (result.length() > 1 && | |
45 ((result[0] == '"' && result[result.length() - 1] == '"') || | |
46 (result[0] == '\'' && result[result.length() - 1] == '\''))) { | |
47 // Strip first and last char which should be matching quotes now. | |
48 result = result.substr(1, result.length() - 2); | |
49 } | |
41 // First translate all path variables we recognize. | 50 // First translate all path variables we recognize. |
42 for (size_t i = 0; i < arraysize(mac_folder_mapping); ++i) { | 51 for (size_t i = 0; i < arraysize(mac_folder_mapping); ++i) { |
43 size_t position = result.find(mac_folder_mapping[i].name); | 52 size_t position = result.find(mac_folder_mapping[i].name); |
44 if (position != std::string::npos) { | 53 if (position != std::string::npos) { |
45 NSArray* searchpaths = NSSearchPathForDirectoriesInDomains( | 54 NSArray* searchpaths = NSSearchPathForDirectoriesInDomains( |
46 mac_folder_mapping[i].id, NSAllDomainsMask, true); | 55 mac_folder_mapping[i].id, NSAllDomainsMask, true); |
47 if ([searchpaths count] > 0) { | 56 if ([searchpaths count] > 0) { |
48 NSString *variable_value = [searchpaths objectAtIndex:0]; | 57 NSString *variable_value = [searchpaths objectAtIndex:0]; |
49 result.replace(position, strlen(mac_folder_mapping[i].name), | 58 result.replace(position, strlen(mac_folder_mapping[i].name), |
50 base::SysNSStringToUTF8(variable_value)); | 59 base::SysNSStringToUTF8(variable_value)); |
(...skipping 26 matching lines...) Expand all Loading... | |
77 LOG(ERROR) << "Machine name variable can not be resolved."; | 86 LOG(ERROR) << "Machine name variable can not be resolved."; |
78 } | 87 } |
79 CFRelease(store); | 88 CFRelease(store); |
80 } | 89 } |
81 return result; | 90 return result; |
82 } | 91 } |
83 | 92 |
84 } // namespace path_parser | 93 } // namespace path_parser |
85 | 94 |
86 } // namespace policy | 95 } // namespace policy |
OLD | NEW |