Skip to content
  • Brett Wilson's avatar
    Add a separate way to notify about font changes. · 21cf626a
    Brett Wilson authored
    This allows code that needs to observe changes to font family preferences an
    efficient and convenient way to register for all font change preferences
    without registering for each one individually. This lowers the total number of
    preference change observers from ~1200 to 189 for a new profile.
    
    Previously this was very inefficient. For all ~1100 font pref names, there were
    three services that registered for each: the font extensions API, the font
    family cache, and the prefs tab helper.
    
    Each of these had a PrefRegistrar with a map of 1100 entries mapping strings to
    callabacks. The global notifier has a hash map mapping 1100 strings to
    unique_ptrs to ObserverList<PrefObserver> containing a vector of 3 pointers.
    The net allocation savings with this patch is about 500KB, with all of it
    occurring during startup.
    
    There were other designs considered. The most general would be to have a
    general prefix matching ability for observing changes. But this is difficult to
    make but efficient and support reentrant changes like the normal observers.
    Since there are less than 200 registered observers other than fonts, prefix
    matching seems not to be a common problem so this approach was avoided.
    
    Instead, this patch adds a single font changed observer (so that the prefix
    matching need only be done once globally for each pref change) that interested
    components registers with. This registers a new type of global low-level
    notification with the pref service. This could have been made more safe by
    adding a new registrar type in the prefs service for this purpose, but that
    would require an additional indirection and extra complexity for each
    preference change.
    
    Bug: 760255
    Change-Id: I4629a7e5c95261ad8b15addf663f20c68332d644
    Reviewed-on: https://chromium-review.googlesource.com/648617
    
    
    Commit-Queue: Brett Wilson <brettw@chromium.org>
    Reviewed-by: default avatarErik Chen <erikchen@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#500155}
    21cf626a