Pref service: Add a ScopedDictionaryPrefUpdate to track value changes.

Currently, if a pref is changed and the pref service is enabled, the
entire value is sent to the pref service and other clients. For large
prefs used by extensions or content settings this can result
milliseconds of busy time on the UI thread.

ScopedDictionaryPrefUpdate tracks which components of a pref are changed
so only the changes need to be sent to the pref service and other pref
clients.

Bug: 654988
Change-Id: Ied5dc6d0fadaa04817330fddce08efdc8b1d0fce
Reviewed-on: https://chromium-review.googlesource.com/476370
Reviewed-by: Tom Sepez <[email protected]>
Reviewed-by: Bernhard Bauer <[email protected]>
Commit-Queue: Sam McNally <[email protected]>
Cr-Commit-Position: refs/heads/master@{#468484}
diff --git a/components/prefs/pref_service.h b/components/prefs/pref_service.h
index a08d7f8..a360afa4 100644
--- a/components/prefs/pref_service.h
+++ b/components/prefs/pref_service.h
@@ -39,6 +39,10 @@
 class FilePath;
 }
 
+namespace prefs {
+class ScopedDictionaryPrefUpdate;
+}
+
 namespace subtle {
 class PrefMemberBase;
 class ScopedUserPrefUpdateBase;
@@ -331,6 +335,7 @@
   // Give access to ReportUserPrefChanged() and GetMutableUserPref().
   friend class subtle::ScopedUserPrefUpdateBase;
   friend class PrefServiceTest_WriteablePrefStoreFlags_Test;
+  friend class prefs::ScopedDictionaryPrefUpdate;
 
   // Registration of pref change observers must be done using the
   // PrefChangeRegistrar, which is declared as a friend here to grant it
@@ -354,8 +359,12 @@
   virtual void RemovePrefObserver(const std::string& path, PrefObserver* obs);
 
   // Sends notification of a changed preference. This needs to be called by
-  // a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed.
+  // a ScopedUserPrefUpdate or ScopedDictionaryPrefUpdate if a DictionaryValue
+  // or ListValue is changed.
   void ReportUserPrefChanged(const std::string& key);
+  void ReportUserPrefChanged(
+      const std::string& key,
+      std::set<std::vector<std::string>> path_components);
 
   // Sets the value for this pref path in the user pref store and informs the
   // PrefNotifier of the change.