Make SiteEngagementService::RecordMetrics less expensive on the UI thread.

RecordMetrics() is called after browser startup and then no more than
once per hour of browser use. It must fetch all site engagement content
settings and calculate statistics over them, and on some Android devices
it blocks the UI thread for 2500ms. This is bad since Android will kill
the browser if the UI thread is busy for more than 5 seconds.

This CL refactors the method to make it less expensive. In particular:

 - a duplicate call to SiteEngagementService::GetAllDetails is
   eliminated
 - SiteEngagementService::GetAllDetails (the fetch method) is refactored
   so that it may be run as a background task to free the UI thread.
   This involved eliminating all calls to
   HostContentSettingsMapFactory::GetForProfile as this method DCHECKs
   that it is on the UI thread.

After this CL, SiteEngagementService::GetAllDetails() is called once in
SiteEngagementService::RecordMetrics(), and that one call happens on a
background thread. Other callers to the method continue to call it on
the UI thread; future work may convert the method to be callback-driven
so that it is never called on the UI thread.

BUG=900022

Change-Id: Ie661b915891ddf981ac4a3049e8e96b73b23684d
Reviewed-on: https://chromium-review.googlesource.com/c/1307018
Commit-Queue: Dominick Ng <dominickn@chromium.org>
Reviewed-by: calamity <calamity@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604156}
3 files changed