⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 259827 in webkit


Ignore:
Timestamp:
Apr 9, 2020, 2:04:46 PM (6 years ago)
Author:
pvollan@apple.com
Message:

[Cocoa] The function WebCore::systemHasBattery() should cache the result.
https://bugs.webkit.org/show_bug.cgi?id=210296
<rdar://problem/61331536>

Reviewed by Darin Adler.

The function WebCore::systemHasBattery() should cache the result, since the return value of this function
will be the same on a specific device.

No new tests, since there is no change in behavior.

  • platform/cocoa/SystemBattery.mm:

(WebCore::systemHasBattery):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r259826 r259827  
     12020-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
    1172020-04-09  Keith Rollin  <krollin@apple.com>
    218
  • trunk/Source/WebCore/platform/cocoa/SystemBattery.mm

    r254995 r259827  
    4040bool systemHasBattery()
    4141{
    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    }
    4459
    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;
    5861}
    5962
Note: See TracChangeset for help on using the changeset viewer.