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

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: Created 7 years, 7 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 {
651
652 // ScopedGenericObj functor for IOObjectRelease().
653 class ScopedReleaseIOObject {
654 public:
655 void operator()(io_object_t x) const {
656 IOObjectRelease(x);
657 }
658 };
659
660 } // namespace
661
662 std::string GetModelIdentifier() { 650 std::string GetModelIdentifier() {
663 ScopedGenericObj<io_service_t, ScopedReleaseIOObject> 651 std::string return_string;
664 platform_expert(IOServiceGetMatchingService( 652 ScopedIOObject<io_service_t> platform_expert(
665 kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))); 653 IOServiceGetMatchingService(kIOMasterPortDefault,
654 IOServiceMatching("IOPlatformExpertDevice")));
666 if (!platform_expert) 655 if (!platform_expert)
667 return ""; 656 return return_string;
Mark Mentovai 2013/05/28 20:52:18 Since you’ve rewritten this function to always ret
Lei Zhang 2013/05/28 21:01:18 Done.
668 ScopedCFTypeRef<CFDataRef> model_data( 657 ScopedCFTypeRef<CFDataRef> model_data(
669 static_cast<CFDataRef>(IORegistryEntryCreateCFProperty( 658 static_cast<CFDataRef>(IORegistryEntryCreateCFProperty(
670 platform_expert, 659 platform_expert,
671 CFSTR("model"), 660 CFSTR("model"),
672 kCFAllocatorDefault, 661 kCFAllocatorDefault,
673 0))); 662 0)));
674 if (!model_data) 663 if (model_data)
675 return ""; 664 return_string = reinterpret_cast<const char*>(CFDataGetBytePtr(model_data));
676 return reinterpret_cast<const char*>( 665 return return_string;
677 CFDataGetBytePtr(model_data));
678 } 666 }
679 667
680 bool ParseModelIdentifier(const std::string& ident, 668 bool ParseModelIdentifier(const std::string& ident,
681 std::string* type, 669 std::string* type,
682 int32* major, 670 int32* major,
683 int32* minor) { 671 int32* minor) {
684 size_t number_loc = ident.find_first_of("0123456789"); 672 size_t number_loc = ident.find_first_of("0123456789");
685 if (number_loc == std::string::npos) 673 if (number_loc == std::string::npos)
686 return false; 674 return false;
687 size_t comma_loc = ident.find(',', number_loc); 675 size_t comma_loc = ident.find(',', number_loc);
688 if (comma_loc == std::string::npos) 676 if (comma_loc == std::string::npos)
689 return false; 677 return false;
690 int32 major_tmp, minor_tmp; 678 int32 major_tmp, minor_tmp;
691 std::string::const_iterator begin = ident.begin(); 679 std::string::const_iterator begin = ident.begin();
692 if (!StringToInt( 680 if (!StringToInt(
693 StringPiece(begin + number_loc, begin + comma_loc), &major_tmp) || 681 StringPiece(begin + number_loc, begin + comma_loc), &major_tmp) ||
694 !StringToInt( 682 !StringToInt(
695 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp)) 683 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp))
696 return false; 684 return false;
697 *type = ident.substr(0, number_loc); 685 *type = ident.substr(0, number_loc);
698 *major = major_tmp; 686 *major = major_tmp;
699 *minor = minor_tmp; 687 *minor = minor_tmp;
700 return true; 688 return true;
701 } 689 }
702 690
703 } // namespace mac 691 } // namespace mac
704 } // namespace base 692 } // 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