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

Side by Side Diff: base/mac/mac_util.mm

Issue 15848005: Cleanup: Remove ScopedGenericObj. Use scoped_ptr<type, CustomDeleter> instead. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: address mark comments, rebase Created 7 years, 6 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 | base/memory/scoped_generic_obj.h » ('j') | 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 "base/mac/mac_util.h" 5 #include "base/mac/mac_util.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #import <IOKit/IOKitLib.h> 8 #import <IOKit/IOKitLib.h>
9 9
10 #include <errno.h> 10 #include <errno.h>
11 #include <string.h> 11 #include <string.h>
12 #include <sys/utsname.h> 12 #include <sys/utsname.h>
13 #include <sys/xattr.h> 13 #include <sys/xattr.h>
14 14
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/mac/bundle_locations.h" 17 #include "base/mac/bundle_locations.h"
18 #include "base/mac/foundation_util.h" 18 #include "base/mac/foundation_util.h"
19 #include "base/mac/mac_logging.h" 19 #include "base/mac/mac_logging.h"
20 #include "base/mac/scoped_cftyperef.h" 20 #include "base/mac/scoped_cftyperef.h"
21 #include "base/memory/scoped_generic_obj.h" 21 #include "base/mac/scoped_ioobject.h"
22 #include "base/memory/scoped_nsobject.h" 22 #include "base/memory/scoped_nsobject.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
25 #include "base/strings/sys_string_conversions.h" 25 #include "base/strings/sys_string_conversions.h"
26 26
27 namespace base { 27 namespace base {
28 namespace mac { 28 namespace mac {
29 29
30 // Replicate specific 10.7 SDK declarations for building with prior SDKs. 30 // Replicate specific 10.7 SDK declarations for building with prior SDKs.
31 #if !defined(MAC_OS_X_VERSION_10_7) || \ 31 #if !defined(MAC_OS_X_VERSION_10_7) || \
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 return MacOSXMinorVersion() >= MOUNTAIN_LION_MINOR_VERSION; 640 return MacOSXMinorVersion() >= MOUNTAIN_LION_MINOR_VERSION;
641 } 641 }
642 #endif 642 #endif
643 643
644 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_8) 644 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_8)
645 bool IsOSLaterThanMountainLion_DontCallThis() { 645 bool IsOSLaterThanMountainLion_DontCallThis() {
646 return MacOSXMinorVersion() > MOUNTAIN_LION_MINOR_VERSION; 646 return MacOSXMinorVersion() > MOUNTAIN_LION_MINOR_VERSION;
647 } 647 }
648 #endif 648 #endif
649 649
650 namespace { 650 std::string GetModelIdentifier() {
651 651 std::string return_string;
652 // ScopedGenericObj functor for IOObjectRelease(). 652 ScopedIOObject<io_service_t> platform_expert(
653 class ScopedReleaseIOObject { 653 IOServiceGetMatchingService(kIOMasterPortDefault,
654 public: 654 IOServiceMatching("IOPlatformExpertDevice")));
655 void operator()(io_object_t x) const { 655 if (platform_expert) {
656 IOObjectRelease(x); 656 ScopedCFTypeRef<CFDataRef> model_data(
657 static_cast<CFDataRef>(IORegistryEntryCreateCFProperty(
658 platform_expert,
659 CFSTR("model"),
660 kCFAllocatorDefault,
661 0)));
662 if (model_data) {
663 return_string =
664 reinterpret_cast<const char*>(CFDataGetBytePtr(model_data));
665 }
657 } 666 }
658 }; 667 return return_string;
659
660 } // namespace
661
662 std::string GetModelIdentifier() {
663 ScopedGenericObj<io_service_t, ScopedReleaseIOObject>
664 platform_expert(IOServiceGetMatchingService(
665 kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")));
666 if (!platform_expert)
667 return "";
668 ScopedCFTypeRef<CFDataRef> model_data(
669 static_cast<CFDataRef>(IORegistryEntryCreateCFProperty(
670 platform_expert,
671 CFSTR("model"),
672 kCFAllocatorDefault,
673 0)));
674 if (!model_data)
675 return "";
676 return reinterpret_cast<const char*>(
677 CFDataGetBytePtr(model_data));
678 } 668 }
679 669
680 bool ParseModelIdentifier(const std::string& ident, 670 bool ParseModelIdentifier(const std::string& ident,
681 std::string* type, 671 std::string* type,
682 int32* major, 672 int32* major,
683 int32* minor) { 673 int32* minor) {
684 size_t number_loc = ident.find_first_of("0123456789"); 674 size_t number_loc = ident.find_first_of("0123456789");
685 if (number_loc == std::string::npos) 675 if (number_loc == std::string::npos)
686 return false; 676 return false;
687 size_t comma_loc = ident.find(',', number_loc); 677 size_t comma_loc = ident.find(',', number_loc);
688 if (comma_loc == std::string::npos) 678 if (comma_loc == std::string::npos)
689 return false; 679 return false;
690 int32 major_tmp, minor_tmp; 680 int32 major_tmp, minor_tmp;
691 std::string::const_iterator begin = ident.begin(); 681 std::string::const_iterator begin = ident.begin();
692 if (!StringToInt( 682 if (!StringToInt(
693 StringPiece(begin + number_loc, begin + comma_loc), &major_tmp) || 683 StringPiece(begin + number_loc, begin + comma_loc), &major_tmp) ||
694 !StringToInt( 684 !StringToInt(
695 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp)) 685 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp))
696 return false; 686 return false;
697 *type = ident.substr(0, number_loc); 687 *type = ident.substr(0, number_loc);
698 *major = major_tmp; 688 *major = major_tmp;
699 *minor = minor_tmp; 689 *minor = minor_tmp;
700 return true; 690 return true;
701 } 691 }
702 692
703 } // namespace mac 693 } // namespace mac
704 } // namespace base 694 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/memory/scoped_generic_obj.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698