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

Unified Diff: base/mac/mac_util.mm

Issue 7740055: Set user-visible machine names and devices types for synced sessions. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Split off platform-specific code to various util files, addressed comments Created 9 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 side-by-side diff with in-line comments
Download patch
Index: base/mac/mac_util.mm
diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm
index 60f544fd1ebecec96cd54382a8e5611b19654824..d60342e746664ca6343ba3e7e8440b5159fe80be 100644
--- a/base/mac/mac_util.mm
+++ b/base/mac/mac_util.mm
@@ -6,6 +6,7 @@
#import <Cocoa/Cocoa.h>
#include <string.h>
+#include <sys/sysctl.h> // sysctlbyname()
#include <sys/utsname.h>
#include "base/file_path.h"
@@ -14,6 +15,8 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_nsobject.h"
#include "base/string_number_conversions.h"
+#include "base/string_util.h"
+#include "base/sys_info.h"
#include "base/sys_string_conversions.h"
namespace base {
@@ -352,6 +355,21 @@ void SetProcessName(CFStringRef process_name) {
LOG_IF(ERROR, err) << "Call to set process name failed, err " << err;
}
+std::string GetHardwareModelName() {
+ 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);
+ } else {
+ return "Unknown";
+ }
Nico 2011/08/31 03:55:50 Don't you want [[NSHost currentHost] localizedName
Nico 2011/08/31 03:58:22 (If so, you'll probably need some kind of fallback
Yaron 2011/08/31 23:23:22 No the thinking was that people identify their com
Nico 2011/08/31 23:27:13 That string usually looks like "Nico Weber's MacBo
Yaron 2011/09/01 20:16:17 Ah, ok, fair enough. Added that for 10.6 and left
+}
+
// Converts a NSImage to a CGImageRef. Normally, the system frameworks can do
// this fine, especially on 10.6. On 10.5, however, CGImage cannot handle
// converting a PDF-backed NSImage into a CGImageRef. This function will
« no previous file with comments | « base/mac/mac_util.h ('k') | base/mac/mac_util_unittest.mm » ('j') | base/win/win_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698