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

Side by Side Diff: components/sync/base/get_session_name_mac.mm

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sync/util/get_session_name_mac.h" 5 #include "components/sync/base/get_session_name_mac.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <sys/sysctl.h> 8 #include <sys/sysctl.h>
9 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h> 9 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
10 10
11 #include "base/mac/scoped_cftyperef.h" 11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 14
15 namespace syncer { 15 namespace syncer {
16 namespace internal { 16 namespace internal {
17 17
18 std::string GetHardwareModelName() { 18 std::string GetHardwareModelName() {
19 // Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570 19 // Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570
20 SCDynamicStoreContext context = { 0, NULL, NULL, NULL }; 20 SCDynamicStoreContext context = {0, NULL, NULL, NULL};
21 base::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate( 21 base::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate(
22 kCFAllocatorDefault, CFSTR("chrome_sync"), NULL, &context)); 22 kCFAllocatorDefault, CFSTR("chrome_sync"), NULL, &context));
23 base::ScopedCFTypeRef<CFStringRef> machine_name( 23 base::ScopedCFTypeRef<CFStringRef> machine_name(
24 SCDynamicStoreCopyLocalHostName(store.get())); 24 SCDynamicStoreCopyLocalHostName(store.get()));
25 if (machine_name.get()) 25 if (machine_name.get())
26 return base::SysCFStringRefToUTF8(machine_name.get()); 26 return base::SysCFStringRefToUTF8(machine_name.get());
27 27
28 // Fall back to get computer name. 28 // Fall back to get computer name.
29 base::ScopedCFTypeRef<CFStringRef> computer_name( 29 base::ScopedCFTypeRef<CFStringRef> computer_name(
30 SCDynamicStoreCopyComputerName(store.get(), NULL)); 30 SCDynamicStoreCopyComputerName(store.get(), NULL));
31 if (computer_name.get()) 31 if (computer_name.get())
32 return base::SysCFStringRefToUTF8(computer_name.get()); 32 return base::SysCFStringRefToUTF8(computer_name.get());
33 33
34 // If all else fails, return to using a slightly nicer version of the 34 // If all else fails, return to using a slightly nicer version of the
35 // hardware model. 35 // hardware model.
36 char modelBuffer[256]; 36 char modelBuffer[256];
37 size_t length = sizeof(modelBuffer); 37 size_t length = sizeof(modelBuffer);
38 if (!sysctlbyname("hw.model", modelBuffer, &length, NULL, 0)) { 38 if (!sysctlbyname("hw.model", modelBuffer, &length, NULL, 0)) {
39 for (size_t i = 0; i < length; i++) { 39 for (size_t i = 0; i < length; i++) {
40 if (base::IsAsciiDigit(modelBuffer[i])) 40 if (base::IsAsciiDigit(modelBuffer[i]))
41 return std::string(modelBuffer, 0, i); 41 return std::string(modelBuffer, 0, i);
42 } 42 }
43 return std::string(modelBuffer, 0, length); 43 return std::string(modelBuffer, 0, length);
44 } 44 }
45 return "Unknown"; 45 return "Unknown";
46 } 46 }
47 47
48 } // namespace internal 48 } // namespace internal
49 } // namespace syncer 49 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/base/get_session_name_mac.h ('k') | components/sync/base/get_session_name_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698