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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/util/get_session_name_mac.mm
diff --git a/sync/util/get_session_name_mac.mm b/sync/util/get_session_name_mac.mm
index b8eb25e3e94d12f3842699e11211c793f2d7c22c..7f5940b5a040d9c7cf63cb58df5ff58d377719a4 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
« 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