diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 22:02:54 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-02 22:02:54 +0000 |
commit | 702126c6af7e854d09274cc9540b909f4e0f3249 (patch) | |
tree | 794761e5d94ebfc7c37d39bcf20f5b022513cd2c /chrome/browser/cookies_tree_model.h | |
parent | ab9d7a06c05e3aa36a558a0b7e1f0bf9a20767ee (diff) | |
download | chromium_src-702126c6af7e854d09274cc9540b909f4e0f3249.zip chromium_src-702126c6af7e854d09274cc9540b909f4e0f3249.tar.gz chromium_src-702126c6af7e854d09274cc9540b909f4e0f3249.tar.bz2 |
[Mac] Reduce jank in the cookie manager by batching updates from the model.
Subclass TreeModelObserver specifically for the CookiesTreeModel so that we can
send TreeModelBatchBegin() and BatchEnd() notifications before and after local
storage, databases, and appcache entries load, respectively.
This also rewrites CookiesTreeModelObserverBridge::FindCocoaNode() to do
breadth-first search, rather than a pre-order traversal as we most often search
for origin nodes, which are at depth 1.
BUG=35134
TEST=Get a profile with 1K local storage entries. Chromium-->Preferences-->Under the Hood-->Content Settings-->Cookies should not be slow/janky.
Review URL: http://codereview.chromium.org/660251
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40444 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cookies_tree_model.h')
-rw-r--r-- | chrome/browser/cookies_tree_model.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/chrome/browser/cookies_tree_model.h b/chrome/browser/cookies_tree_model.h index 3fabbaf..056fe5f 100644 --- a/chrome/browser/cookies_tree_model.h +++ b/chrome/browser/cookies_tree_model.h @@ -9,6 +9,7 @@ #include <vector> #include "app/tree_node_model.h" +#include "base/observer_list.h" #include "base/scoped_ptr.h" #include "chrome/browser/browsing_data_appcache_helper.h" #include "chrome/browser/browsing_data_database_helper.h" @@ -344,6 +345,17 @@ class CookieTreeLocalStoragesNode : public CookieTreeNode { class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { public: + // Because non-cookie nodes are fetched in a background thread, they are not + // present at the time the Model is created. The Model then notifies its + // observers for every item added from databases, local storage, and + // appcache. We extend the Observer interface to add notifications before and + // after these batch inserts. + class Observer : public TreeModelObserver { + public: + virtual void TreeModelBeginBatch(CookiesTreeModel* model) {} + virtual void TreeModelEndBatch(CookiesTreeModel* model) {} + }; + CookiesTreeModel( Profile* profile, BrowsingDataDatabaseHelper* database_helper, @@ -368,6 +380,16 @@ class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { // Filter the origins to only display matched results. void UpdateSearchResults(const std::wstring& filter); + // Overload the Add/Remove observer methods so we can notify about + // CookiesTreeModel-specific things. Note that this is NOT overriding the + // method by the same name in TreeNodeModel because the argument type is + // different. Therefore, if this AddObserver(TreeModelObserver*) is called, + // the observer will NOT be notified about batching. This is also why we + // maintain a separate list of observers that are specifically Observer* + // objects. + virtual void AddObserver(Observer* observer); + virtual void RemoveObserver(Observer* observer); + private: enum CookieIconIndex { ORIGIN = 0, @@ -396,6 +418,9 @@ class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { std::wstring FormExtensionNodeName(const std::string& extension_id); + void NotifyObserverBeginBatch(); + void NotifyObserverEndBatch(); + // The profile from which this model sources cookies. Profile* profile_; CookieList all_cookies_; @@ -407,6 +432,15 @@ class CookiesTreeModel : public TreeNodeModel<CookieTreeNode> { scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper_; LocalStorageInfoList local_storage_info_list_; + // The CookiesTreeModel maintains a separate list of observers that are + // specifically of the type CookiesTreeModel::Observer. + ObserverList<Observer> cookies_observer_list_; + + // If this is non-zero, then this model is batching updates (there's a lot of + // notifications coming down the pipe). This is an integer is used to balance + // calls to Begin/EndBatch() if they're called in a nested manner. + int batch_update_; + friend class CookieTreeAppCacheNode; friend class CookieTreeCookieNode; friend class CookieTreeDatabaseNode; |