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

Side by Side Diff: chrome/browser/sync/glue/session_model_associator_mac.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: Changed mac name retrieval, other fixes Created 9 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/glue/session_model_associator.h"
6
7 #import <Foundation/Foundation.h>
8 #import <SystemConfiguration/SCDynamicStoreCopySpecific.h>
9 #include <sys/sysctl.h> // sysctlbyname()
10
11 #include "base/mac/mac_util.h"
12 #include "base/string_util.h"
13 #include "base/sys_info.h"
14 #include "base/sys_string_conversions.h"
15
16 @interface NSHost(SnowLeopardAPI)
17 - (NSString *)localizedName;
Nico 2011/09/01 20:20:41 No space after *
Yaron 2011/09/01 22:19:46 Done. Or did you mean to add a space after the ")"
18 @end
19
20 namespace browser_sync {
21
22 // Static
23 std::string SessionModelAssociator::GetHardwareModelName() {
24 NSHost* myHost = [NSHost currentHost];
25 if ([myHost respondsToSelector:@selector(localizedName)]) {
26 return base::SysNSStringToUTF8([myHost localizedName]);
27 } else {
Nico 2011/09/01 20:20:41 No else after return, that makes the function less
Yaron 2011/09/01 22:19:46 Done.
28 // Fallback for 10.5
29 NSString* computerName = (NSString *)SCDynamicStoreCopyComputerName(
Nico 2011/09/01 20:20:41 No space in front of *. Also, we don't like C-styl
Yaron 2011/09/01 22:19:46 Done.
30 NULL, NULL);
31 if (computerName != NULL) {
32 return base::SysNSStringToUTF8([myHost localizedName]);
Nico 2011/09/01 20:20:41 s/\[myHost localizedName\]/computerName/ :-)
Yaron 2011/09/01 22:19:46 Done. Ugh.
33 }
34
35 // If all else fails, return to using a slightly nicer version of the
36 // hardware model.
37 char modelBuffer[256];
38 size_t length = sizeof(modelBuffer);
39 if (!sysctlbyname("hw.model", modelBuffer, &length, NULL, 0)) {
40 for (size_t i = 0; i < length; i++) {
41 if (IsAsciiDigit(modelBuffer[i])) {
42 return std::string(modelBuffer, 0, i);
43 }
44 }
45 return std::string(modelBuffer, 0, length);
46 } else {
Nico 2011/09/01 20:20:41 No else after return
Yaron 2011/09/01 22:19:46 Done.
47 return "Unknown";
48 }
49 }
50 }
51
52 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/session_model_associator.cc ('k') | chrome/browser/sync/glue/session_model_associator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698