Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/browser/policy/policy_path_parser_mac.mm

Issue 7000022: Faster way to read the hostname on mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #import <SystemConfiguration/SCDynamicStore.h>
12 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
11 13
12 #include <string> 14 #include <string>
13 15
14 namespace policy { 16 namespace policy {
15 17
16 namespace path_parser { 18 namespace path_parser {
17 19
18 const char* kUserNamePolicyVarName = "${user_name}"; 20 const char* kUserNamePolicyVarName = "${user_name}";
19 const char* kMachineNamePolicyVarName = "${machine_name}"; 21 const char* kMachineNamePolicyVarName = "${machine_name}";
20 const char* kMacUsersDirectory = "${users}"; 22 const char* kMacUsersDirectory = "${users}";
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 NSString* username = NSUserName(); 57 NSString* username = NSUserName();
56 if (username) { 58 if (username) {
57 result.replace(position, strlen(kUserNamePolicyVarName), 59 result.replace(position, strlen(kUserNamePolicyVarName),
58 base::SysNSStringToUTF8(username)); 60 base::SysNSStringToUTF8(username));
59 } else { 61 } else {
60 LOG(ERROR) << "Username variable can not be resolved."; 62 LOG(ERROR) << "Username variable can not be resolved.";
61 } 63 }
62 } 64 }
63 position = result.find(kMachineNamePolicyVarName); 65 position = result.find(kMachineNamePolicyVarName);
64 if (position != std::string::npos) { 66 if (position != std::string::npos) {
65 NSString* machinename = [[NSHost currentHost] name]; 67 SCDynamicStoreContext context = { 0, NULL, NULL, NULL };
68 SCDynamicStoreRef store = SCDynamicStoreCreate(kCFAllocatorDefault,
69 CFSTR("policy_subsystem"),
70 NULL, &context);
71 CFStringRef machinename = SCDynamicStoreCopyLocalHostName(store);
66 if (machinename) { 72 if (machinename) {
67 result.replace(position, strlen(kMachineNamePolicyVarName), 73 result.replace(position, strlen(kMachineNamePolicyVarName),
68 base::SysNSStringToUTF8(machinename)); 74 base::SysCFStringRefToUTF8(machinename));
75 CFRelease(machinename);
69 } else { 76 } else {
70 LOG(ERROR) << "Machine name variable can not be resolved."; 77 LOG(ERROR) << "Machine name variable can not be resolved.";
71 } 78 }
79 CFRelease(store);
72 } 80 }
73 return result; 81 return result;
74 } 82 }
75 83
76 } // namespace path_parser 84 } // namespace path_parser
77 85
78 } // namespace policy 86 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698