Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / browsing_data / cookies_tree_model.h
blob106a8fef68d8e1348a7a6c09543377ce7255d134
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_
6 #define CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_
8 // TODO(viettrungluu): This header file #includes far too much and has too much
9 // inline code (which shouldn't be inline).
11 #include <list>
12 #include <string>
13 #include <vector>
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/observer_list.h"
18 #include "base/strings/string16.h"
19 #include "base/strings/utf_string_conversions.h"
20 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
21 #include "chrome/browser/browsing_data/browsing_data_database_helper.h"
22 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
23 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
24 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
25 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h"
26 #include "chrome/browser/browsing_data/local_data_container.h"
27 #include "chrome/common/content_settings.h"
28 #include "net/ssl/server_bound_cert_store.h"
29 #include "ui/base/models/tree_node_model.h"
31 class BrowsingDataCookieHelper;
32 class BrowsingDataServerBoundCertHelper;
33 class CookieSettings;
34 class CookiesTreeModel;
35 class CookieTreeAppCacheNode;
36 class CookieTreeAppCachesNode;
37 class CookieTreeCookieNode;
38 class CookieTreeCookiesNode;
39 class CookieTreeDatabaseNode;
40 class CookieTreeDatabasesNode;
41 class CookieTreeFileSystemNode;
42 class CookieTreeFileSystemsNode;
43 class CookieTreeFlashLSONode;
44 class CookieTreeHostNode;
45 class CookieTreeIndexedDBNode;
46 class CookieTreeIndexedDBsNode;
47 class CookieTreeLocalStorageNode;
48 class CookieTreeLocalStoragesNode;
49 class CookieTreeQuotaNode;
50 class CookieTreeServerBoundCertNode;
51 class CookieTreeServerBoundCertsNode;
52 class CookieTreeSessionStorageNode;
53 class CookieTreeSessionStoragesNode;
54 class ExtensionSpecialStoragePolicy;
56 namespace extensions {
57 class ExtensionSet;
60 namespace net {
61 class CanonicalCookie;
64 // CookieTreeNode -------------------------------------------------------------
65 // The base node type in the Cookies, Databases, and Local Storage options
66 // view, from which all other types are derived. Specialized from TreeNode in
67 // that it has a notion of deleting objects stored in the profile, and being
68 // able to have its children do the same.
69 class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
70 public:
71 // Used to pull out information for the InfoView (the details display below
72 // the tree control.)
73 struct DetailedInfo {
74 // NodeType corresponds to the various CookieTreeNode types.
75 enum NodeType {
76 TYPE_NONE,
77 TYPE_ROOT, // This is used for CookieTreeRootNode nodes.
78 TYPE_HOST, // This is used for CookieTreeHostNode nodes.
79 TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes.
80 TYPE_COOKIE, // This is used for CookieTreeCookieNode nodes.
81 TYPE_DATABASES, // This is used for CookieTreeDatabasesNode.
82 TYPE_DATABASE, // This is used for CookieTreeDatabaseNode.
83 TYPE_LOCAL_STORAGES, // This is used for CookieTreeLocalStoragesNode.
84 TYPE_LOCAL_STORAGE, // This is used for CookieTreeLocalStorageNode.
85 TYPE_SESSION_STORAGES, // This is used for CookieTreeSessionStoragesNode.
86 TYPE_SESSION_STORAGE, // This is used for CookieTreeSessionStorageNode.
87 TYPE_APPCACHES, // This is used for CookieTreeAppCachesNode.
88 TYPE_APPCACHE, // This is used for CookieTreeAppCacheNode.
89 TYPE_INDEXED_DBS, // This is used for CookieTreeIndexedDBsNode.
90 TYPE_INDEXED_DB, // This is used for CookieTreeIndexedDBNode.
91 TYPE_FILE_SYSTEMS, // This is used for CookieTreeFileSystemsNode.
92 TYPE_FILE_SYSTEM, // This is used for CookieTreeFileSystemNode.
93 TYPE_QUOTA, // This is used for CookieTreeQuotaNode.
94 TYPE_SERVER_BOUND_CERTS, // Used for CookieTreeServerBoundCertsNode.
95 TYPE_SERVER_BOUND_CERT, // Used for CookieTreeServerBoundCertNode.
96 TYPE_FLASH_LSO, // This is used for CookieTreeFlashLSONode.
99 DetailedInfo();
100 ~DetailedInfo();
102 DetailedInfo& Init(NodeType type);
103 DetailedInfo& InitHost();
104 DetailedInfo& InitCookie(const net::CanonicalCookie* cookie);
105 DetailedInfo& InitDatabase(
106 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info);
107 DetailedInfo& InitLocalStorage(
108 const BrowsingDataLocalStorageHelper::LocalStorageInfo*
109 local_storage_info);
110 DetailedInfo& InitSessionStorage(
111 const BrowsingDataLocalStorageHelper::LocalStorageInfo*
112 session_storage_info);
113 DetailedInfo& InitAppCache(const GURL& origin,
114 const appcache::AppCacheInfo* appcache_info);
115 DetailedInfo& InitIndexedDB(
116 const content::IndexedDBInfo* indexed_db_info);
117 DetailedInfo& InitFileSystem(
118 const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info);
119 DetailedInfo& InitQuota(
120 const BrowsingDataQuotaHelper::QuotaInfo* quota_info);
121 DetailedInfo& InitServerBoundCert(
122 const net::ServerBoundCertStore::ServerBoundCert* server_bound_cert);
123 DetailedInfo& InitFlashLSO(const std::string& flash_lso_domain);
125 NodeType node_type;
126 GURL origin;
127 const net::CanonicalCookie* cookie;
128 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info;
129 const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info;
130 const BrowsingDataLocalStorageHelper::LocalStorageInfo*
131 session_storage_info;
132 const appcache::AppCacheInfo* appcache_info;
133 const content::IndexedDBInfo* indexed_db_info;
134 const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info;
135 const BrowsingDataQuotaHelper::QuotaInfo* quota_info;
136 const net::ServerBoundCertStore::ServerBoundCert* server_bound_cert;
137 std::string flash_lso_domain;
140 CookieTreeNode() {}
141 explicit CookieTreeNode(const base::string16& title)
142 : ui::TreeNode<CookieTreeNode>(title) {}
143 virtual ~CookieTreeNode() {}
145 // Delete backend storage for this node, and any children nodes. (E.g. delete
146 // the cookie from CookieMonster, clear the database, and so forth.)
147 virtual void DeleteStoredObjects();
149 // Gets a pointer back to the associated model for the tree we are in.
150 virtual CookiesTreeModel* GetModel() const;
152 // Returns a struct with detailed information used to populate the details
153 // part of the view.
154 virtual DetailedInfo GetDetailedInfo() const = 0;
156 protected:
157 void AddChildSortedByTitle(CookieTreeNode* new_child);
159 private:
160 DISALLOW_COPY_AND_ASSIGN(CookieTreeNode);
163 // CookieTreeRootNode ---------------------------------------------------------
164 // The node at the root of the CookieTree that gets inserted into the view.
165 class CookieTreeRootNode : public CookieTreeNode {
166 public:
167 explicit CookieTreeRootNode(CookiesTreeModel* model);
168 virtual ~CookieTreeRootNode();
170 CookieTreeHostNode* GetOrCreateHostNode(const GURL& url);
172 // CookieTreeNode methods:
173 virtual CookiesTreeModel* GetModel() const OVERRIDE;
174 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
176 private:
177 CookiesTreeModel* model_;
179 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode);
182 // CookieTreeHostNode -------------------------------------------------------
183 class CookieTreeHostNode : public CookieTreeNode {
184 public:
185 // Returns the host node's title to use for a given URL.
186 static base::string16 TitleForUrl(const GURL& url);
188 explicit CookieTreeHostNode(const GURL& url);
189 virtual ~CookieTreeHostNode();
191 // CookieTreeNode methods:
192 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
194 // CookieTreeHostNode methods:
195 CookieTreeCookiesNode* GetOrCreateCookiesNode();
196 CookieTreeDatabasesNode* GetOrCreateDatabasesNode();
197 CookieTreeLocalStoragesNode* GetOrCreateLocalStoragesNode();
198 CookieTreeSessionStoragesNode* GetOrCreateSessionStoragesNode();
199 CookieTreeAppCachesNode* GetOrCreateAppCachesNode();
200 CookieTreeIndexedDBsNode* GetOrCreateIndexedDBsNode();
201 CookieTreeFileSystemsNode* GetOrCreateFileSystemsNode();
202 CookieTreeServerBoundCertsNode* GetOrCreateServerBoundCertsNode();
203 CookieTreeQuotaNode* UpdateOrCreateQuotaNode(
204 std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info);
205 CookieTreeFlashLSONode* GetOrCreateFlashLSONode(const std::string& domain);
207 std::string canonicalized_host() const { return canonicalized_host_; }
209 // Creates an content exception for this origin of type
210 // CONTENT_SETTINGS_TYPE_COOKIES.
211 void CreateContentException(CookieSettings* cookie_settings,
212 ContentSetting setting) const;
214 // True if a content exception can be created for this origin.
215 bool CanCreateContentException() const;
217 const std::string GetHost() const;
219 private:
220 // Pointers to the cookies, databases, local and session storage and appcache
221 // nodes. When we build up the tree we need to quickly get a reference to
222 // the COOKIES node to add children. Checking each child and interrogating
223 // them to see if they are a COOKIES, APPCACHES, DATABASES etc node seems
224 // less preferable than storing an extra pointer per origin.
225 CookieTreeCookiesNode* cookies_child_;
226 CookieTreeDatabasesNode* databases_child_;
227 CookieTreeLocalStoragesNode* local_storages_child_;
228 CookieTreeSessionStoragesNode* session_storages_child_;
229 CookieTreeAppCachesNode* appcaches_child_;
230 CookieTreeIndexedDBsNode* indexed_dbs_child_;
231 CookieTreeFileSystemsNode* file_systems_child_;
232 CookieTreeQuotaNode* quota_child_;
233 CookieTreeServerBoundCertsNode* server_bound_certs_child_;
234 CookieTreeFlashLSONode* flash_lso_child_;
236 // The URL for which this node was initially created.
237 GURL url_;
239 std::string canonicalized_host_;
241 DISALLOW_COPY_AND_ASSIGN(CookieTreeHostNode);
244 // CookieTreeCookieNode ------------------------------------------------------
245 class CookieTreeCookieNode : public CookieTreeNode {
246 public:
247 friend class CookieTreeCookiesNode;
249 // The cookie should remain valid at least as long as the
250 // CookieTreeCookieNode is valid.
251 explicit CookieTreeCookieNode(
252 std::list<net::CanonicalCookie>::iterator cookie);
253 virtual ~CookieTreeCookieNode();
255 // CookieTreeNode methods:
256 virtual void DeleteStoredObjects() OVERRIDE;
257 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
259 private:
260 // cookie_ is expected to remain valid as long as the CookieTreeCookieNode is
261 // valid.
262 std::list<net::CanonicalCookie>::iterator cookie_;
264 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode);
267 class CookieTreeCookiesNode : public CookieTreeNode {
268 public:
269 CookieTreeCookiesNode();
270 virtual ~CookieTreeCookiesNode();
272 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
274 void AddCookieNode(CookieTreeCookieNode* child) {
275 AddChildSortedByTitle(child);
278 private:
279 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode);
282 // CookieTreeAppCacheNode -----------------------------------------------------
283 class CookieTreeAppCacheNode : public CookieTreeNode {
284 public:
285 friend class CookieTreeAppCachesNode;
287 // appcache_info should remain valid at least as long as the
288 // CookieTreeAppCacheNode is valid.
289 explicit CookieTreeAppCacheNode(
290 const GURL& origin_url,
291 std::list<appcache::AppCacheInfo>::iterator appcache_info);
292 virtual ~CookieTreeAppCacheNode();
294 virtual void DeleteStoredObjects() OVERRIDE;
295 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
297 private:
298 GURL origin_url_;
299 std::list<appcache::AppCacheInfo>::iterator appcache_info_;
300 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCacheNode);
303 class CookieTreeAppCachesNode : public CookieTreeNode {
304 public:
305 CookieTreeAppCachesNode();
306 virtual ~CookieTreeAppCachesNode();
308 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
310 void AddAppCacheNode(CookieTreeAppCacheNode* child) {
311 AddChildSortedByTitle(child);
314 private:
315 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCachesNode);
318 // CookieTreeDatabaseNode -----------------------------------------------------
319 class CookieTreeDatabaseNode : public CookieTreeNode {
320 public:
321 friend class CookieTreeDatabasesNode;
323 // database_info should remain valid at least as long as the
324 // CookieTreeDatabaseNode is valid.
325 explicit CookieTreeDatabaseNode(
326 std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator
327 database_info);
328 virtual ~CookieTreeDatabaseNode();
330 virtual void DeleteStoredObjects() OVERRIDE;
331 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
333 private:
334 // database_info_ is expected to remain valid as long as the
335 // CookieTreeDatabaseNode is valid.
336 std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator
337 database_info_;
339 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabaseNode);
342 class CookieTreeDatabasesNode : public CookieTreeNode {
343 public:
344 CookieTreeDatabasesNode();
345 virtual ~CookieTreeDatabasesNode();
347 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
349 void AddDatabaseNode(CookieTreeDatabaseNode* child) {
350 AddChildSortedByTitle(child);
353 private:
354 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabasesNode);
357 // CookieTreeFileSystemNode --------------------------------------------------
358 class CookieTreeFileSystemNode : public CookieTreeNode {
359 public:
360 friend class CookieTreeFileSystemsNode;
362 // file_system_info should remain valid at least as long as the
363 // CookieTreeFileSystemNode is valid.
364 explicit CookieTreeFileSystemNode(
365 std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator
366 file_system_info);
367 virtual ~CookieTreeFileSystemNode();
369 virtual void DeleteStoredObjects() OVERRIDE;
370 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
372 private:
373 // file_system_info_ expected to remain valid as long as the
374 // CookieTreeFileSystemNode is valid.
375 std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator
376 file_system_info_;
378 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemNode);
381 class CookieTreeFileSystemsNode : public CookieTreeNode {
382 public:
383 CookieTreeFileSystemsNode();
384 virtual ~CookieTreeFileSystemsNode();
386 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
388 void AddFileSystemNode(CookieTreeFileSystemNode* child) {
389 AddChildSortedByTitle(child);
392 private:
393 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemsNode);
396 // CookieTreeLocalStorageNode -------------------------------------------------
397 class CookieTreeLocalStorageNode : public CookieTreeNode {
398 public:
399 // local_storage_info should remain valid at least as long as the
400 // CookieTreeLocalStorageNode is valid.
401 explicit CookieTreeLocalStorageNode(
402 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
403 local_storage_info);
404 virtual ~CookieTreeLocalStorageNode();
406 // CookieTreeNode methods:
407 virtual void DeleteStoredObjects() OVERRIDE;
408 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
410 private:
411 // local_storage_info_ is expected to remain valid as long as the
412 // CookieTreeLocalStorageNode is valid.
413 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
414 local_storage_info_;
416 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode);
419 class CookieTreeLocalStoragesNode : public CookieTreeNode {
420 public:
421 CookieTreeLocalStoragesNode();
422 virtual ~CookieTreeLocalStoragesNode();
424 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
426 void AddLocalStorageNode(CookieTreeLocalStorageNode* child) {
427 AddChildSortedByTitle(child);
430 private:
432 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode);
436 // CookieTreeSessionStorageNode -----------------------------------------------
437 class CookieTreeSessionStorageNode : public CookieTreeNode {
438 public:
439 // session_storage_info should remain valid at least as long as the
440 // CookieTreeSessionStorageNode is valid.
441 explicit CookieTreeSessionStorageNode(
442 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
443 session_storage_info);
444 virtual ~CookieTreeSessionStorageNode();
446 // CookieTreeNode methods:
447 virtual void DeleteStoredObjects() OVERRIDE;
448 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
450 private:
451 // session_storage_info_ is expected to remain valid as long as the
452 // CookieTreeSessionStorageNode is valid.
453 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
454 session_storage_info_;
456 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStorageNode);
459 class CookieTreeSessionStoragesNode : public CookieTreeNode {
460 public:
461 CookieTreeSessionStoragesNode();
462 virtual ~CookieTreeSessionStoragesNode();
464 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
466 void AddSessionStorageNode(CookieTreeSessionStorageNode* child) {
467 AddChildSortedByTitle(child);
470 private:
472 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStoragesNode);
475 // CookieTreeIndexedDBNode -----------------------------------------------
476 class CookieTreeIndexedDBNode : public CookieTreeNode {
477 public:
478 // indexed_db_info should remain valid at least as long as the
479 // CookieTreeIndexedDBNode is valid.
480 explicit CookieTreeIndexedDBNode(
481 std::list<content::IndexedDBInfo>::iterator
482 indexed_db_info);
483 virtual ~CookieTreeIndexedDBNode();
485 // CookieTreeNode methods:
486 virtual void DeleteStoredObjects() OVERRIDE;
487 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
489 private:
490 // indexed_db_info_ is expected to remain valid as long as the
491 // CookieTreeIndexedDBNode is valid.
492 std::list<content::IndexedDBInfo>::iterator
493 indexed_db_info_;
495 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBNode);
498 class CookieTreeIndexedDBsNode : public CookieTreeNode {
499 public:
500 CookieTreeIndexedDBsNode();
501 virtual ~CookieTreeIndexedDBsNode();
503 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
505 void AddIndexedDBNode(CookieTreeIndexedDBNode* child) {
506 AddChildSortedByTitle(child);
509 private:
510 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBsNode);
513 // CookieTreeQuotaNode --------------------------------------------------
514 class CookieTreeQuotaNode : public CookieTreeNode {
515 public:
516 // quota_info should remain valid at least as long as the CookieTreeQuotaNode
517 // is valid.
518 explicit CookieTreeQuotaNode(
519 std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info);
520 virtual ~CookieTreeQuotaNode();
522 virtual void DeleteStoredObjects() OVERRIDE;
523 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
525 private:
526 // quota_info_ is expected to remain valid as long as the CookieTreeQuotaNode
527 // is valid.
528 std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info_;
530 DISALLOW_COPY_AND_ASSIGN(CookieTreeQuotaNode);
533 // CookieTreeServerBoundCertNode ---------------------------------------------
534 class CookieTreeServerBoundCertNode : public CookieTreeNode {
535 public:
536 friend class CookieTreeServerBoundCertsNode;
538 // The iterator should remain valid at least as long as the
539 // CookieTreeServerBoundCertNode is valid.
540 explicit CookieTreeServerBoundCertNode(
541 net::ServerBoundCertStore::ServerBoundCertList::iterator cert);
542 virtual ~CookieTreeServerBoundCertNode();
544 // CookieTreeNode methods:
545 virtual void DeleteStoredObjects() OVERRIDE;
546 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
548 private:
549 // server_bound_cert_ is expected to remain valid as long as the
550 // CookieTreeServerBoundCertNode is valid.
551 net::ServerBoundCertStore::ServerBoundCertList::iterator server_bound_cert_;
553 DISALLOW_COPY_AND_ASSIGN(CookieTreeServerBoundCertNode);
556 class CookieTreeServerBoundCertsNode : public CookieTreeNode {
557 public:
558 CookieTreeServerBoundCertsNode();
559 virtual ~CookieTreeServerBoundCertsNode();
561 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
563 void AddServerBoundCertNode(CookieTreeServerBoundCertNode* child) {
564 AddChildSortedByTitle(child);
567 private:
568 DISALLOW_COPY_AND_ASSIGN(CookieTreeServerBoundCertsNode);
571 // CookieTreeFlashLSONode ----------------------------------------------------
572 class CookieTreeFlashLSONode : public CookieTreeNode {
573 public:
574 explicit CookieTreeFlashLSONode(const std::string& domain);
575 virtual ~CookieTreeFlashLSONode();
577 // CookieTreeNode methods:
578 virtual void DeleteStoredObjects() OVERRIDE;
579 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
581 private:
582 std::string domain_;
584 DISALLOW_COPY_AND_ASSIGN(CookieTreeFlashLSONode);
587 // CookiesTreeModel -----------------------------------------------------------
588 class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
589 public:
590 CookiesTreeModel(LocalDataContainer* data_container,
591 ExtensionSpecialStoragePolicy* special_storage_policy,
592 bool group_by_cookie_source);
593 virtual ~CookiesTreeModel();
595 // Because non-cookie nodes are fetched in a background thread, they are not
596 // present at the time the Model is created. The Model then notifies its
597 // observers for every item added from databases, local storage, and
598 // appcache. We extend the Observer interface to add notifications before and
599 // after these batch inserts.
600 class Observer : public ui::TreeModelObserver {
601 public:
602 virtual void TreeModelBeginBatch(CookiesTreeModel* model) {}
603 virtual void TreeModelEndBatch(CookiesTreeModel* model) {}
606 // This class defines the scope for batch updates. It can be created as a
607 // local variable and the destructor will terminate the batch update, if one
608 // has been started.
609 class ScopedBatchUpdateNotifier {
610 public:
611 ScopedBatchUpdateNotifier(CookiesTreeModel* model,
612 CookieTreeNode* node);
613 ~ScopedBatchUpdateNotifier();
615 void StartBatchUpdate();
617 private:
618 CookiesTreeModel* model_;
619 CookieTreeNode* node_;
620 bool batch_in_progress_;
623 // ui::TreeModel methods:
624 // Returns the set of icons for the nodes in the tree. You only need override
625 // this if you don't want to use the default folder icons.
626 virtual void GetIcons(std::vector<gfx::ImageSkia>* icons) OVERRIDE;
628 // Returns the index of the icon to use for |node|. Return -1 to use the
629 // default icon. The index is relative to the list of icons returned from
630 // GetIcons.
631 virtual int GetIconIndex(ui::TreeModelNode* node) OVERRIDE;
633 // CookiesTreeModel methods:
634 void DeleteAllStoredObjects();
636 // Deletes a specific node in the tree, identified by |cookie_node|, and its
637 // subtree.
638 void DeleteCookieNode(CookieTreeNode* cookie_node);
640 // Filter the origins to only display matched results.
641 void UpdateSearchResults(const base::string16& filter);
643 // Returns the set of extensions which protect the data item represented by
644 // this node from deletion.
645 // Returns NULL if the node doesn't represent a protected data item or the
646 // special storage policy is NULL.
647 const extensions::ExtensionSet* ExtensionsProtectingNode(
648 const CookieTreeNode& cookie_node);
650 // Manages CookiesTreeModel::Observers. This will also call
651 // TreeNodeModel::AddObserver so that it gets all the proper notifications.
652 // Note that the converse is not true: simply adding a TreeModelObserver will
653 // not get CookiesTreeModel::Observer notifications.
654 virtual void AddCookiesTreeObserver(Observer* observer);
655 virtual void RemoveCookiesTreeObserver(Observer* observer);
657 // Methods that update the model based on the data retrieved by the browsing
658 // data helpers.
659 void PopulateAppCacheInfo(LocalDataContainer* container);
660 void PopulateCookieInfo(LocalDataContainer* container);
661 void PopulateDatabaseInfo(LocalDataContainer* container);
662 void PopulateLocalStorageInfo(LocalDataContainer* container);
663 void PopulateSessionStorageInfo(LocalDataContainer* container);
664 void PopulateIndexedDBInfo(LocalDataContainer* container);
665 void PopulateFileSystemInfo(LocalDataContainer* container);
666 void PopulateQuotaInfo(LocalDataContainer* container);
667 void PopulateServerBoundCertInfo(LocalDataContainer* container);
668 void PopulateFlashLSOInfo(LocalDataContainer* container);
670 BrowsingDataCookieHelper* GetCookieHelper(const std::string& app_id);
671 LocalDataContainer* data_container() {
672 return data_container_.get();
675 private:
676 enum CookieIconIndex {
677 ORIGIN = 0,
678 COOKIE = 1,
679 DATABASE = 2
682 void NotifyObserverBeginBatch();
683 void NotifyObserverEndBatch();
685 void PopulateAppCacheInfoWithFilter(LocalDataContainer* container,
686 ScopedBatchUpdateNotifier* notifier,
687 const base::string16& filter);
688 void PopulateCookieInfoWithFilter(LocalDataContainer* container,
689 ScopedBatchUpdateNotifier* notifier,
690 const base::string16& filter);
691 void PopulateDatabaseInfoWithFilter(LocalDataContainer* container,
692 ScopedBatchUpdateNotifier* notifier,
693 const base::string16& filter);
694 void PopulateLocalStorageInfoWithFilter(LocalDataContainer* container,
695 ScopedBatchUpdateNotifier* notifier,
696 const base::string16& filter);
697 void PopulateSessionStorageInfoWithFilter(LocalDataContainer* container,
698 ScopedBatchUpdateNotifier* notifier,
699 const base::string16& filter);
700 void PopulateIndexedDBInfoWithFilter(LocalDataContainer* container,
701 ScopedBatchUpdateNotifier* notifier,
702 const base::string16& filter);
703 void PopulateFileSystemInfoWithFilter(LocalDataContainer* container,
704 ScopedBatchUpdateNotifier* notifier,
705 const base::string16& filter);
706 void PopulateQuotaInfoWithFilter(LocalDataContainer* container,
707 ScopedBatchUpdateNotifier* notifier,
708 const base::string16& filter);
709 void PopulateServerBoundCertInfoWithFilter(
710 LocalDataContainer* container,
711 ScopedBatchUpdateNotifier* notifier,
712 const base::string16& filter);
713 void PopulateFlashLSOInfoWithFilter(LocalDataContainer* container,
714 ScopedBatchUpdateNotifier* notifier,
715 const base::string16& filter);
717 // Map of app ids to LocalDataContainer objects to use when retrieving
718 // locally stored data.
719 scoped_ptr<LocalDataContainer> data_container_;
721 // The extension special storage policy; see ExtensionsProtectingNode() above.
722 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
724 // The CookiesTreeModel maintains a separate list of observers that are
725 // specifically of the type CookiesTreeModel::Observer.
726 ObserverList<Observer> cookies_observer_list_;
728 // If true, use the CanonicalCookie::Source attribute to group cookies.
729 // Otherwise, use the CanonicalCookie::Domain attribute.
730 bool group_by_cookie_source_;
732 // If this is non-zero, then this model is batching updates (there's a lot of
733 // notifications coming down the pipe). This is an integer is used to balance
734 // calls to Begin/EndBatch() if they're called in a nested manner.
735 int batch_update_;
738 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_