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

Side by Side Diff: sync/util/get_session_name_mac.mm

Issue 10824151: Try to fix a crash in the new sync machine code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 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 | 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) 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 "sync/util/get_session_name_mac.h"
6 6
7 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h> 7 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
8 #include <sys/sysctl.h>
8 9
9 #include "base/mac/scoped_cftyperef.h" 10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/string_util.h"
10 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
11 13
12 namespace syncer { 14 namespace syncer {
13 namespace internal { 15 namespace internal {
14 16
15 std::string GetHardwareModelName() { 17 std::string GetHardwareModelName() {
16 // Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570 18 // Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570
17 SCDynamicStoreContext context = { 0, NULL, NULL, NULL }; 19 SCDynamicStoreContext context = { 0, NULL, NULL, NULL };
18 base::mac::ScopedCFTypeRef<SCDynamicStoreRef> store( 20 base::mac::ScopedCFTypeRef<SCDynamicStoreRef> store(
19 SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("policy_subsystem"), 21 SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("chrome_sync"),
20 NULL, &context)); 22 NULL, &context));
21 CFStringRef machine_name = SCDynamicStoreCopyLocalHostName(store.get()); 23 base::mac::ScopedCFTypeRef<CFStringRef> machine_name(
22 return base::SysCFStringRefToUTF8(machine_name); 24 SCDynamicStoreCopyLocalHostName(store.get()));
25 if (machine_name.get())
26 return base::SysCFStringRefToUTF8(machine_name.get());
27
28 // Fall back to get computer name.
29 base::mac::ScopedCFTypeRef<CFStringRef> computer_name(
30 SCDynamicStoreCopyComputerName(store.get(), NULL));
31 if (computer_name.get())
32 return base::SysCFStringRefToUTF8(computer_name.get());
33
34 // If all else fails, return to using a slightly nicer version of the
35 // hardware model.
36 char modelBuffer[256];
37 size_t length = sizeof(modelBuffer);
38 if (!sysctlbyname("hw.model", modelBuffer, &length, NULL, 0)) {
39 for (size_t i = 0; i < length; i++) {
40 if (IsAsciiDigit(modelBuffer[i]))
41 return std::string(modelBuffer, 0, i);
42 }
43 return std::string(modelBuffer, 0, length);
44 }
45 return "Unknown";
23 } 46 }
24 47
25 } // namespace internal 48 } // namespace internal
26 } // namespace syncer 49 } // namespace syncer
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