Changeset 259827 in webkit
- Timestamp:
- Apr 9, 2020, 2:04:46 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
platform/cocoa/SystemBattery.mm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r259826 r259827 1 2020-04-09 Per Arne Vollan <pvollan@apple.com> 2 3 [Cocoa] The function WebCore::systemHasBattery() should cache the result. 4 https://bugs.webkit.org/show_bug.cgi?id=210296 5 <rdar://problem/61331536> 6 7 Reviewed by Darin Adler. 8 9 The function WebCore::systemHasBattery() should cache the result, since the return value of this function 10 will be the same on a specific device. 11 12 No new tests, since there is no change in behavior. 13 14 * platform/cocoa/SystemBattery.mm: 15 (WebCore::systemHasBattery): 16 1 17 2020-04-09 Keith Rollin <krollin@apple.com> 2 18 -
trunk/Source/WebCore/platform/cocoa/SystemBattery.mm
r254995 r259827 40 40 bool systemHasBattery() 41 41 { 42 if (hasBattery.hasValue()) 43 return *hasBattery; 42 if (!hasBattery.hasValue()) { 43 hasBattery = [] { 44 RetainPtr<CFTypeRef> powerSourcesInfo = adoptCF(IOPSCopyPowerSourcesInfo()); 45 if (!powerSourcesInfo) 46 return false; 47 RetainPtr<CFArrayRef> powerSourcesList = adoptCF(IOPSCopyPowerSourcesList(powerSourcesInfo.get())); 48 if (!powerSourcesList) 49 return false; 50 for (CFIndex i = 0, count = CFArrayGetCount(powerSourcesList.get()); i < count; ++i) { 51 CFDictionaryRef description = IOPSGetPowerSourceDescription(powerSourcesInfo.get(), CFArrayGetValueAtIndex(powerSourcesList.get(), i)); 52 CFTypeRef value = CFDictionaryGetValue(description, CFSTR(kIOPSTypeKey)); 53 if (!value || CFEqual(value, CFSTR(kIOPSInternalBatteryType))) 54 return true; 55 } 56 return false; 57 }(); 58 } 44 59 45 RetainPtr<CFTypeRef> powerSourcesInfo = adoptCF(IOPSCopyPowerSourcesInfo()); 46 if (!powerSourcesInfo) 47 return false; 48 RetainPtr<CFArrayRef> powerSourcesList = adoptCF(IOPSCopyPowerSourcesList(powerSourcesInfo.get())); 49 if (!powerSourcesList) 50 return false; 51 for (CFIndex i = 0, count = CFArrayGetCount(powerSourcesList.get()); i < count; ++i) { 52 CFDictionaryRef description = IOPSGetPowerSourceDescription(powerSourcesInfo.get(), CFArrayGetValueAtIndex(powerSourcesList.get(), i)); 53 CFTypeRef value = CFDictionaryGetValue(description, CFSTR(kIOPSTypeKey)); 54 if (!value || CFEqual(value, CFSTR(kIOPSInternalBatteryType))) 55 return true; 56 } 57 return false; 60 return *hasBattery; 58 61 } 59 62
Note:
See TracChangeset
for help on using the changeset viewer.