Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2519)

Unified Diff: chrome/browser/cookies_tree_model.h

Issue 10536017: Refactoring CookiesTreeModel to support multiple data sources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactoring common code and style fixes. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cookies_tree_model.h
diff --git a/chrome/browser/cookies_tree_model.h b/chrome/browser/cookies_tree_model.h
index e99fa7f5188930d2aab740e58e49744c74e18ac8..a1f160a50bf7ed9546e7c5e7f20c0d3d63cec7a1 100644
--- a/chrome/browser/cookies_tree_model.h
+++ b/chrome/browser/cookies_tree_model.h
@@ -35,22 +35,43 @@ class CookieSettings;
class CookiesTreeModel;
class CookieTreeAppCacheNode;
class CookieTreeAppCachesNode;
+class CookieTreeAppNode;
class CookieTreeCookieNode;
class CookieTreeCookiesNode;
class CookieTreeDatabaseNode;
class CookieTreeDatabasesNode;
-class CookieTreeFileSystemsNode;
class CookieTreeFileSystemNode;
+class CookieTreeFileSystemsNode;
+class CookieTreeIndexedDBNode;
+class CookieTreeIndexedDBsNode;
class CookieTreeLocalStorageNode;
class CookieTreeLocalStoragesNode;
+class CookieTreeOriginNode;
+class CookieTreeQuotaNode;
class CookieTreeServerBoundCertNode;
class CookieTreeServerBoundCertsNode;
-class CookieTreeQuotaNode;
class CookieTreeSessionStorageNode;
class CookieTreeSessionStoragesNode;
-class CookieTreeIndexedDBNode;
-class CookieTreeIndexedDBsNode;
-class CookieTreeOriginNode;
+class LocalDataContainer;
+
+// Friendly typedefs for the multiple types of lists used in the model.
+namespace {
+ typedef std::map<string16, LocalDataContainer*> ContainerMap;
+ typedef std::list<net::CookieMonster::CanonicalCookie> CookieList;
+ typedef std::list<BrowsingDataDatabaseHelper::DatabaseInfo> DatabaseInfoList;
+ typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
+ LocalStorageInfoList;
+ typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
+ SessionStorageInfoList;
+ typedef std::list<BrowsingDataIndexedDBHelper::IndexedDBInfo>
+ IndexedDBInfoList;
+ typedef std::list<BrowsingDataFileSystemHelper::FileSystemInfo>
+ FileSystemInfoList;
+ typedef std::list<BrowsingDataQuotaHelper::QuotaInfo> QuotaInfoList;
+ typedef net::ServerBoundCertStore::ServerBoundCertList ServerBoundCertList;
+
+ typedef std::map<GURL, std::list<appcache::AppCacheInfo> > AppCacheInfoMap;
+}
// CookieTreeNode -------------------------------------------------------------
// The base node type in the Cookies, Databases, and Local Storage options
@@ -66,6 +87,7 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
enum NodeType {
TYPE_NONE,
TYPE_ROOT, // This is used for CookieTreeRootNode nodes.
+ TYPE_APP, // This is used for CookieTreeAppNode nodes.
TYPE_ORIGIN, // This is used for CookieTreeOriginNode nodes.
TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes.
TYPE_COOKIE, // This is used for CookieTreeCookieNode nodes.
@@ -107,6 +129,13 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
return *this;
}
+ DetailedInfo& InitApp(const string16& app_name, const string16& app_id) {
+ Init(TYPE_APP);
+ this->app_name = app_name;
+ this->app_id = app_id;
+ return *this;
+ }
+
DetailedInfo& InitCookie(
const net::CookieMonster::CanonicalCookie* cookie) {
Init(TYPE_COOKIE);
@@ -171,6 +200,8 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
return *this;
}
+ string16 app_name;
+ string16 app_id;
string16 origin;
NodeType node_type;
const net::CookieMonster::CanonicalCookie* cookie;
@@ -207,6 +238,11 @@ class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs);
};
+ class AppNodeComparator {
+ public:
+ bool operator() (const CookieTreeNode* lhs, const CookieTreeNode* rhs);
+ };
+
void AddChildSortedByTitle(CookieTreeNode* new_child);
private:
@@ -221,7 +257,8 @@ class CookieTreeRootNode : public CookieTreeNode {
explicit CookieTreeRootNode(CookiesTreeModel* model);
virtual ~CookieTreeRootNode();
- CookieTreeOriginNode* GetOrCreateOriginNode(const GURL& url);
+ CookieTreeAppNode* GetOrCreateAppNode(const string16& app_name,
+ const string16& app_id);
// CookieTreeNode methods:
virtual CookiesTreeModel* GetModel() const OVERRIDE;
@@ -233,11 +270,31 @@ class CookieTreeRootNode : public CookieTreeNode {
DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode);
};
+// CookieTreeAppNode ----------------------------------------------------------
+class CookieTreeAppNode : public CookieTreeNode {
+ public:
+ explicit CookieTreeAppNode(const string16& app_name, const string16& app_id);
+ virtual ~CookieTreeAppNode();
+
+ CookieTreeOriginNode* GetOrCreateOriginNode(const GURL& url);
+
+ // CookieTreeNode methods:
+ virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
+
+ const string16& app_id() const { return app_id_; }
+
+ private:
+ string16 app_name_;
+ string16 app_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(CookieTreeAppNode);
+};
+
// CookieTreeOriginNode -------------------------------------------------------
class CookieTreeOriginNode : public CookieTreeNode {
public:
// Returns the origin node's title to use for a given URL.
- static std::wstring TitleForUrl(const GURL& url);
+ static string16 TitleForUrl(const GURL& url);
explicit CookieTreeOriginNode(const GURL& url);
virtual ~CookieTreeOriginNode();
@@ -613,10 +670,41 @@ class CookieTreeServerBoundCertsNode : public CookieTreeNode {
private:
DISALLOW_COPY_AND_ASSIGN(CookieTreeServerBoundCertsNode);
};
+// CookiesTreeModelDelegate ---------------------------------------------------
+// This is a delegate definition class. It is used by the CookiesTreeModel
+// to pass a pointer to itself to each of the LocalDataContainer objects, so
+// when resource fetching is complete, the objects can call back to the model
+// and update it. The CookiesTreeModel instance must outlive the
+// LocalDataContainer instances.
+class CookiesTreeModelDelegate {
+ public:
+ virtual void PopulateAppCacheInfoWithFilter(const string16* app,
+ const string16& filter) {}
+ virtual void PopulateCookieInfoWithFilter(const string16* app,
+ const string16& filter) {}
+ virtual void PopulateDatabaseInfoWithFilter(const string16* app,
+ const string16& filter) {}
+ virtual void PopulateLocalStorageInfoWithFilter(const string16* app,
+ const string16& filter) {}
+ virtual void PopulateSessionStorageInfoWithFilter(
+ const string16* app, const string16& filter) {}
+ virtual void PopulateIndexedDBInfoWithFilter(const string16* app,
+ const string16& filter) {}
+ virtual void PopulateFileSystemInfoWithFilter(const string16* app,
+ const string16& filter) {}
+ virtual void PopulateQuotaInfoWithFilter(const string16* app,
+ const string16& filter) {}
+ virtual void PopulateServerBoundCertInfoWithFilter(
+ const string16* app, const string16& filter) {}
+};
// CookiesTreeModel -----------------------------------------------------------
-class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
+class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode>,
+ public CookiesTreeModelDelegate {
public:
+ CookiesTreeModel(const ContainerMap& apps_map, bool use_cookie_source);
+ virtual ~CookiesTreeModel();
+
// 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
@@ -628,19 +716,6 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
virtual void TreeModelEndBatch(CookiesTreeModel* model) {}
};
- CookiesTreeModel(
- BrowsingDataCookieHelper* cookie_helper,
- BrowsingDataDatabaseHelper* database_helper,
- BrowsingDataLocalStorageHelper* local_storage_helper,
- BrowsingDataLocalStorageHelper* session_storage_helper,
- BrowsingDataAppCacheHelper* appcache_helper,
- BrowsingDataIndexedDBHelper* indexed_db_helper,
- BrowsingDataFileSystemHelper* file_system_helper,
- BrowsingDataQuotaHelper* quota_helper,
- BrowsingDataServerBoundCertHelper* server_bound_cert_helper,
- bool use_cookie_source);
- virtual ~CookiesTreeModel();
-
// ui::TreeModel methods:
// Returns the set of icons for the nodes in the tree. You only need override
// this if you don't want to use the default folder icons.
@@ -653,10 +728,13 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
// CookiesTreeModel methods:
void DeleteAllStoredObjects();
+
+ // Deletes all the stored objects for a specific app, identified by |app_id|.
+ void DeleteStoredObjectsForApp(const string16& app_id);
void DeleteCookieNode(CookieTreeNode* cookie_node);
// Filter the origins to only display matched results.
- void UpdateSearchResults(const std::wstring& filter);
+ void UpdateSearchResults(const string16& filter);
// Manages CookiesTreeModel::Observers. This will also call
// TreeNodeModel::AddObserver so that it gets all the proper notifications.
@@ -665,26 +743,87 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
virtual void AddCookiesTreeObserver(Observer* observer);
virtual void RemoveCookiesTreeObserver(Observer* observer);
+ // CookiesTreeModelDelegate methods:
+ virtual void PopulateAppCacheInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateCookieInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateDatabaseInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateLocalStorageInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateSessionStorageInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateIndexedDBInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateFileSystemInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateQuotaInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+ virtual void PopulateServerBoundCertInfoWithFilter(
+ const string16* app_id, const string16& filter) OVERRIDE;
+
+ BrowsingDataCookieHelper* GetCookieHelper(const string16& app_id);
+ LocalDataContainer* GetLocalDataContainer(const string16& app_id);
+
private:
enum CookieIconIndex {
ORIGIN = 0,
COOKIE = 1,
DATABASE = 2
};
- typedef std::list<net::CookieMonster::CanonicalCookie> CookieList;
- typedef std::list<BrowsingDataDatabaseHelper::DatabaseInfo>
- DatabaseInfoList;
- typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
- LocalStorageInfoList;
- typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
- SessionStorageInfoList;
- typedef std::list<BrowsingDataIndexedDBHelper::IndexedDBInfo>
- IndexedDBInfoList;
- typedef std::list<BrowsingDataFileSystemHelper::FileSystemInfo>
- FileSystemInfoList;
- typedef std::list<BrowsingDataQuotaHelper::QuotaInfo> QuotaInfoArray;
- typedef net::ServerBoundCertStore::ServerBoundCertList ServerBoundCertList;
+ void NotifyObserverBeginBatch();
+ void NotifyObserverEndBatch();
+
+ // Map of app ids to LocalDataContainer objects to use when retrieving
+ // locally stored data.
+ ContainerMap app_data_map_;
+
+ // The CookiesTreeModel maintains a separate list of observers that are
+ // specifically of the type CookiesTreeModel::Observer.
+ ObserverList<Observer> cookies_observer_list_;
+
+ // If true, use the CanonicalCookie::Source attribute to group cookies.
+ // Otherwise, use the CanonicalCookie::Domain attribute.
+ bool use_cookie_source_;
+
+ // 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_;
+};
+
+// LocalDataContainer ---------------------------------------------------------
Evan Stade 2012/06/19 23:43:50 please create a new file for this.
nasko 2012/06/20 15:49:37 Considering that all classes related to the cookie
Evan Stade 2012/06/20 21:06:30 feel free to separate all of them.
nasko 2012/06/20 22:32:32 I've split the LocalDataContainer.
+// This class is a wrapper around all the BrowsingData*Helper classes. Because
+// isolated applications have separate storage, we need different helper
+// instances. As such, this class contains the app name and id, along with the
+// helpers for all of the data types we need. The browser-wide "app id" will be
+// the empty string, as no app can have empty id.
+class LocalDataContainer {
+ public:
+ LocalDataContainer(
+ const string16& app_name,
+ const string16& app_id,
+ BrowsingDataCookieHelper* cookie_helper,
+ BrowsingDataDatabaseHelper* database_helper,
+ BrowsingDataLocalStorageHelper* local_storage_helper,
+ BrowsingDataLocalStorageHelper* session_storage_helper,
+ BrowsingDataAppCacheHelper* appcache_helper,
+ BrowsingDataIndexedDBHelper* indexed_db_helper,
+ BrowsingDataFileSystemHelper* file_system_helper,
+ BrowsingDataQuotaHelper* quota_helper,
+ BrowsingDataServerBoundCertHelper* server_bound_cert_helper);
+ virtual ~LocalDataContainer();
+
+ // This method must be called to start the process of fetching the resources.
+ // The delegate passed in is called back to deliver the updates.
+ void Init(CookiesTreeModelDelegate* delegate);
+
+ const string16& app_name() { return app_name_; }
+ const string16& app_id() { return app_id_; }
+
+ private:
void OnAppCacheModelInfoLoaded();
void OnCookiesModelInfoLoaded(const net::CookieList& cookie_list);
void OnDatabaseModelInfoLoaded(const DatabaseInfoList& database_info);
@@ -696,21 +835,11 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
const IndexedDBInfoList& indexed_db_info);
void OnFileSystemModelInfoLoaded(
const FileSystemInfoList& file_system_info);
- void OnQuotaModelInfoLoaded(const QuotaInfoArray& quota_info);
+ void OnQuotaModelInfoLoaded(const QuotaInfoList& quota_info);
void OnServerBoundCertModelInfoLoaded(const ServerBoundCertList& cert_list);
- void PopulateAppCacheInfoWithFilter(const std::wstring& filter);
- void PopulateCookieInfoWithFilter(const std::wstring& filter);
- void PopulateDatabaseInfoWithFilter(const std::wstring& filter);
- void PopulateLocalStorageInfoWithFilter(const std::wstring& filter);
- void PopulateSessionStorageInfoWithFilter(const std::wstring& filter);
- void PopulateIndexedDBInfoWithFilter(const std::wstring& filter);
- void PopulateFileSystemInfoWithFilter(const std::wstring& filter);
- void PopulateQuotaInfoWithFilter(const std::wstring& filter);
- void PopulateServerBoundCertInfoWithFilter(const std::wstring& filter);
-
- void NotifyObserverBeginBatch();
- void NotifyObserverEndBatch();
+ string16 app_name_;
Evan Stade 2012/06/19 23:43:50 aren't app names encoded in utf8? therefore this s
nasko 2012/06/20 15:49:37 The CookieTreeNode uses string16 for its ctor and
Evan Stade 2012/06/20 21:06:30 convert as late as possible.
nasko 2012/06/20 22:32:32 Done.
+ string16 app_id_;
Evan Stade 2012/06/19 23:43:50 this should probably also be a std::string
nasko 2012/06/20 15:49:37 Yes, this can be std::string, though for uniformit
Evan Stade 2012/06/20 21:06:30 I don't understand the uniformity argument. You wo
nasko 2012/06/20 22:32:32 Done.
scoped_refptr<BrowsingDataAppCacheHelper> appcache_helper_;
scoped_refptr<BrowsingDataCookieHelper> cookie_helper_;
@@ -722,31 +851,23 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
scoped_refptr<BrowsingDataQuotaHelper> quota_helper_;
scoped_refptr<BrowsingDataServerBoundCertHelper> server_bound_cert_helper_;
- std::map<GURL, std::list<appcache::AppCacheInfo> > appcache_info_;
+ AppCacheInfoMap appcache_info_;
CookieList cookie_list_;
DatabaseInfoList database_info_list_;
LocalStorageInfoList local_storage_info_list_;
LocalStorageInfoList session_storage_info_list_;
IndexedDBInfoList indexed_db_info_list_;
FileSystemInfoList file_system_info_list_;
- QuotaInfoArray quota_info_list_;
+ QuotaInfoList quota_info_list_;
ServerBoundCertList server_bound_cert_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_;
-
- // If true, use the CanonicalCookie::Source attribute to group cookies.
- // Otherwise, use the CanonicalCookie::Domain attribute.
- bool use_cookie_source_;
+ // A delegate, which must outlive this object. The update callbacks use the
+ // delegate to deliver the updated data to the CookieTreeModel.
+ CookiesTreeModelDelegate* delegate_;
- base::WeakPtrFactory<CookiesTreeModel> weak_ptr_factory_;
+ base::WeakPtrFactory<LocalDataContainer> weak_ptr_factory_;
+ friend class CookiesTreeModel;
friend class CookieTreeAppCacheNode;
friend class CookieTreeCookieNode;
friend class CookieTreeDatabaseNode;
@@ -757,7 +878,7 @@ class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
friend class CookieTreeQuotaNode;
friend class CookieTreeServerBoundCertNode;
- DISALLOW_COPY_AND_ASSIGN(CookiesTreeModel);
+ DISALLOW_COPY_AND_ASSIGN(LocalDataContainer);
};
#endif // CHROME_BROWSER_COOKIES_TREE_MODEL_H_
« no previous file with comments | « no previous file | chrome/browser/cookies_tree_model.cc » ('j') | chrome/browser/resources/options2/cookies_list.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698