summaryrefslogtreecommitdiffstats
path: root/sync/util
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-02 21:55:31 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-02 21:55:31 +0000
commit6d7e29f5a72e200473b4750e4f87d70f51e20b36 (patch)
tree7287f55f0b723d631c8aad80a0e90f22f2252a46 /sync/util
parent335d4ea5307bba3ed09e6df486cf55379b15c28c (diff)
downloadchromium_src-6d7e29f5a72e200473b4750e4f87d70f51e20b36.zip
chromium_src-6d7e29f5a72e200473b4750e4f87d70f51e20b36.tar.gz
chromium_src-6d7e29f5a72e200473b4750e4f87d70f51e20b36.tar.bz2
Try to fix a crash in the new sync machine code
This adds back the fallback code that was deleted after the 10.6 migration in https://chromiumcodereview.appspot.com/10807052, it's necessary again. BUG=140256,138570 Review URL: https://chromiumcodereview.appspot.com/10824151 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/util')
-rw-r--r--sync/util/get_session_name_mac.mm29
1 files changed, 26 insertions, 3 deletions
diff --git a/sync/util/get_session_name_mac.mm b/sync/util/get_session_name_mac.mm
index b8eb25e..7f5940b 100644
--- a/sync/util/get_session_name_mac.mm
+++ b/sync/util/get_session_name_mac.mm
@@ -5,8 +5,10 @@
#include "sync/util/get_session_name_mac.h"
#import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
+#include <sys/sysctl.h>
#include "base/mac/scoped_cftyperef.h"
+#include "base/string_util.h"
#include "base/sys_string_conversions.h"
namespace syncer {
@@ -16,10 +18,31 @@ std::string GetHardwareModelName() {
// Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570
SCDynamicStoreContext context = { 0, NULL, NULL, NULL };
base::mac::ScopedCFTypeRef<SCDynamicStoreRef> store(
- SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("policy_subsystem"),
+ SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("chrome_sync"),
NULL, &context));
- CFStringRef machine_name = SCDynamicStoreCopyLocalHostName(store.get());
- return base::SysCFStringRefToUTF8(machine_name);
+ base::mac::ScopedCFTypeRef<CFStringRef> machine_name(
+ SCDynamicStoreCopyLocalHostName(store.get()));
+ if (machine_name.get())
+ return base::SysCFStringRefToUTF8(machine_name.get());
+
+ // Fall back to get computer name.
+ base::mac::ScopedCFTypeRef<CFStringRef> computer_name(
+ SCDynamicStoreCopyComputerName(store.get(), NULL));
+ if (computer_name.get())
+ return base::SysCFStringRefToUTF8(computer_name.get());
+
+ // If all else fails, return to using a slightly nicer version of the
+ // hardware model.
+ char modelBuffer[256];
+ size_t length = sizeof(modelBuffer);
+ if (!sysctlbyname("hw.model", modelBuffer, &length, NULL, 0)) {
+ for (size_t i = 0; i < length; i++) {
+ if (IsAsciiDigit(modelBuffer[i]))
+ return std::string(modelBuffer, 0, i);
+ }
+ return std::string(modelBuffer, 0, length);
+ }
+ return "Unknown";
}
} // namespace internal