Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / browsing_data / cookies_tree_model.h
blobdb89183206107d6950ed8404635bbb7f48c7467a
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/browsing_data_service_worker_helper.h"
27 #include "chrome/browser/browsing_data/local_data_container.h"
28 #include "components/content_settings/core/common/content_settings.h"
29 #include "net/ssl/channel_id_store.h"
30 #include "ui/base/models/tree_node_model.h"
32 class BrowsingDataChannelIDHelper;
33 class BrowsingDataCookieHelper;
34 class CookieSettings;
35 class CookiesTreeModel;
36 class CookieTreeAppCacheNode;
37 class CookieTreeAppCachesNode;
38 class CookieTreeChannelIDNode;
39 class CookieTreeChannelIDsNode;
40 class CookieTreeCookieNode;
41 class CookieTreeCookiesNode;
42 class CookieTreeDatabaseNode;
43 class CookieTreeDatabasesNode;
44 class CookieTreeFileSystemNode;
45 class CookieTreeFileSystemsNode;
46 class CookieTreeFlashLSONode;
47 class CookieTreeHostNode;
48 class CookieTreeIndexedDBNode;
49 class CookieTreeIndexedDBsNode;
50 class CookieTreeLocalStorageNode;
51 class CookieTreeLocalStoragesNode;
52 class CookieTreeQuotaNode;
53 class CookieTreeServiceWorkerNode;
54 class CookieTreeServiceWorkersNode;
55 class CookieTreeSessionStorageNode;
56 class CookieTreeSessionStoragesNode;
57 class ExtensionSpecialStoragePolicy;
59 namespace extensions {
60 class ExtensionSet;
63 namespace net {
64 class CanonicalCookie;
67 // CookieTreeNode -------------------------------------------------------------
68 // The base node type in the Cookies, Databases, and Local Storage options
69 // view, from which all other types are derived. Specialized from TreeNode in
70 // that it has a notion of deleting objects stored in the profile, and being
71 // able to have its children do the same.
72 class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
73 public:
74 // Used to pull out information for the InfoView (the details display below
75 // the tree control.)
76 struct DetailedInfo {
77 // NodeType corresponds to the various CookieTreeNode types.
78 enum NodeType {
79 TYPE_NONE,
80 TYPE_ROOT, // This is used for CookieTreeRootNode nodes.
81 TYPE_HOST, // This is used for CookieTreeHostNode nodes.
82 TYPE_COOKIES, // This is used for CookieTreeCookiesNode nodes.
83 TYPE_COOKIE, // This is used for CookieTreeCookieNode nodes.
84 TYPE_DATABASES, // This is used for CookieTreeDatabasesNode.
85 TYPE_DATABASE, // This is used for CookieTreeDatabaseNode.
86 TYPE_LOCAL_STORAGES, // This is used for CookieTreeLocalStoragesNode.
87 TYPE_LOCAL_STORAGE, // This is used for CookieTreeLocalStorageNode.
88 TYPE_SESSION_STORAGES, // This is used for CookieTreeSessionStoragesNode.
89 TYPE_SESSION_STORAGE, // This is used for CookieTreeSessionStorageNode.
90 TYPE_APPCACHES, // This is used for CookieTreeAppCachesNode.
91 TYPE_APPCACHE, // This is used for CookieTreeAppCacheNode.
92 TYPE_INDEXED_DBS, // This is used for CookieTreeIndexedDBsNode.
93 TYPE_INDEXED_DB, // This is used for CookieTreeIndexedDBNode.
94 TYPE_FILE_SYSTEMS, // This is used for CookieTreeFileSystemsNode.
95 TYPE_FILE_SYSTEM, // This is used for CookieTreeFileSystemNode.
96 TYPE_QUOTA, // This is used for CookieTreeQuotaNode.
97 TYPE_CHANNEL_IDS, // Used for CookieTreeChannelIDsNode.
98 TYPE_CHANNEL_ID, // Used for CookieTreeChannelIDNode.
99 TYPE_SERVICE_WORKERS, // This is used for CookieTreeServiceWorkersNode.
100 TYPE_SERVICE_WORKER, // This is used for CookieTreeServiceWorkerNode.
101 TYPE_FLASH_LSO, // This is used for CookieTreeFlashLSONode.
104 DetailedInfo();
105 ~DetailedInfo();
107 DetailedInfo& Init(NodeType type);
108 DetailedInfo& InitHost();
109 DetailedInfo& InitCookie(const net::CanonicalCookie* cookie);
110 DetailedInfo& InitDatabase(
111 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info);
112 DetailedInfo& InitLocalStorage(
113 const BrowsingDataLocalStorageHelper::LocalStorageInfo*
114 local_storage_info);
115 DetailedInfo& InitSessionStorage(
116 const BrowsingDataLocalStorageHelper::LocalStorageInfo*
117 session_storage_info);
118 DetailedInfo& InitAppCache(const GURL& origin,
119 const content::AppCacheInfo* appcache_info);
120 DetailedInfo& InitIndexedDB(
121 const content::IndexedDBInfo* indexed_db_info);
122 DetailedInfo& InitFileSystem(
123 const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info);
124 DetailedInfo& InitQuota(
125 const BrowsingDataQuotaHelper::QuotaInfo* quota_info);
126 DetailedInfo& InitChannelID(
127 const net::ChannelIDStore::ChannelID* channel_id);
128 DetailedInfo& InitServiceWorker(
129 const content::ServiceWorkerUsageInfo* service_worker_info);
130 DetailedInfo& InitFlashLSO(const std::string& flash_lso_domain);
132 NodeType node_type;
133 GURL origin;
134 const net::CanonicalCookie* cookie;
135 const BrowsingDataDatabaseHelper::DatabaseInfo* database_info;
136 const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info;
137 const BrowsingDataLocalStorageHelper::LocalStorageInfo*
138 session_storage_info;
139 const content::AppCacheInfo* appcache_info;
140 const content::IndexedDBInfo* indexed_db_info;
141 const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info;
142 const BrowsingDataQuotaHelper::QuotaInfo* quota_info;
143 const net::ChannelIDStore::ChannelID* channel_id;
144 const content::ServiceWorkerUsageInfo* service_worker_info;
145 std::string flash_lso_domain;
148 CookieTreeNode() {}
149 explicit CookieTreeNode(const base::string16& title)
150 : ui::TreeNode<CookieTreeNode>(title) {}
151 virtual ~CookieTreeNode() {}
153 // Delete backend storage for this node, and any children nodes. (E.g. delete
154 // the cookie from CookieMonster, clear the database, and so forth.)
155 virtual void DeleteStoredObjects();
157 // Gets a pointer back to the associated model for the tree we are in.
158 virtual CookiesTreeModel* GetModel() const;
160 // Returns a struct with detailed information used to populate the details
161 // part of the view.
162 virtual DetailedInfo GetDetailedInfo() const = 0;
164 protected:
165 void AddChildSortedByTitle(CookieTreeNode* new_child);
167 private:
168 DISALLOW_COPY_AND_ASSIGN(CookieTreeNode);
171 // CookieTreeRootNode ---------------------------------------------------------
172 // The node at the root of the CookieTree that gets inserted into the view.
173 class CookieTreeRootNode : public CookieTreeNode {
174 public:
175 explicit CookieTreeRootNode(CookiesTreeModel* model);
176 virtual ~CookieTreeRootNode();
178 CookieTreeHostNode* GetOrCreateHostNode(const GURL& url);
180 // CookieTreeNode methods:
181 virtual CookiesTreeModel* GetModel() const OVERRIDE;
182 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
184 private:
185 CookiesTreeModel* model_;
187 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode);
190 // CookieTreeHostNode -------------------------------------------------------
191 class CookieTreeHostNode : public CookieTreeNode {
192 public:
193 // Returns the host node's title to use for a given URL.
194 static base::string16 TitleForUrl(const GURL& url);
196 explicit CookieTreeHostNode(const GURL& url);
197 virtual ~CookieTreeHostNode();
199 // CookieTreeNode methods:
200 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
202 // CookieTreeHostNode methods:
203 CookieTreeCookiesNode* GetOrCreateCookiesNode();
204 CookieTreeDatabasesNode* GetOrCreateDatabasesNode();
205 CookieTreeLocalStoragesNode* GetOrCreateLocalStoragesNode();
206 CookieTreeSessionStoragesNode* GetOrCreateSessionStoragesNode();
207 CookieTreeAppCachesNode* GetOrCreateAppCachesNode();
208 CookieTreeIndexedDBsNode* GetOrCreateIndexedDBsNode();
209 CookieTreeFileSystemsNode* GetOrCreateFileSystemsNode();
210 CookieTreeChannelIDsNode* GetOrCreateChannelIDsNode();
211 CookieTreeServiceWorkersNode* GetOrCreateServiceWorkersNode();
212 CookieTreeQuotaNode* UpdateOrCreateQuotaNode(
213 std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info);
214 CookieTreeFlashLSONode* GetOrCreateFlashLSONode(const std::string& domain);
216 std::string canonicalized_host() const { return canonicalized_host_; }
218 // Creates an content exception for this origin of type
219 // CONTENT_SETTINGS_TYPE_COOKIES.
220 void CreateContentException(CookieSettings* cookie_settings,
221 ContentSetting setting) const;
223 // True if a content exception can be created for this origin.
224 bool CanCreateContentException() const;
226 const std::string GetHost() const;
228 private:
229 // Pointers to the cookies, databases, local and session storage and appcache
230 // nodes. When we build up the tree we need to quickly get a reference to
231 // the COOKIES node to add children. Checking each child and interrogating
232 // them to see if they are a COOKIES, APPCACHES, DATABASES etc node seems
233 // less preferable than storing an extra pointer per origin.
234 CookieTreeCookiesNode* cookies_child_;
235 CookieTreeDatabasesNode* databases_child_;
236 CookieTreeLocalStoragesNode* local_storages_child_;
237 CookieTreeSessionStoragesNode* session_storages_child_;
238 CookieTreeAppCachesNode* appcaches_child_;
239 CookieTreeIndexedDBsNode* indexed_dbs_child_;
240 CookieTreeFileSystemsNode* file_systems_child_;
241 CookieTreeQuotaNode* quota_child_;
242 CookieTreeChannelIDsNode* channel_ids_child_;
243 CookieTreeServiceWorkersNode* service_workers_child_;
244 CookieTreeFlashLSONode* flash_lso_child_;
246 // The URL for which this node was initially created.
247 GURL url_;
249 std::string canonicalized_host_;
251 DISALLOW_COPY_AND_ASSIGN(CookieTreeHostNode);
254 // CookieTreeCookieNode ------------------------------------------------------
255 class CookieTreeCookieNode : public CookieTreeNode {
256 public:
257 friend class CookieTreeCookiesNode;
259 // The cookie should remain valid at least as long as the
260 // CookieTreeCookieNode is valid.
261 explicit CookieTreeCookieNode(
262 std::list<net::CanonicalCookie>::iterator cookie);
263 virtual ~CookieTreeCookieNode();
265 // CookieTreeNode methods:
266 virtual void DeleteStoredObjects() OVERRIDE;
267 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
269 private:
270 // cookie_ is expected to remain valid as long as the CookieTreeCookieNode is
271 // valid.
272 std::list<net::CanonicalCookie>::iterator cookie_;
274 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode);
277 class CookieTreeCookiesNode : public CookieTreeNode {
278 public:
279 CookieTreeCookiesNode();
280 virtual ~CookieTreeCookiesNode();
282 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
284 void AddCookieNode(CookieTreeCookieNode* child) {
285 AddChildSortedByTitle(child);
288 private:
289 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode);
292 // CookieTreeAppCacheNode -----------------------------------------------------
293 class CookieTreeAppCacheNode : public CookieTreeNode {
294 public:
295 friend class CookieTreeAppCachesNode;
297 // appcache_info should remain valid at least as long as the
298 // CookieTreeAppCacheNode is valid.
299 explicit CookieTreeAppCacheNode(
300 const GURL& origin_url,
301 std::list<content::AppCacheInfo>::iterator appcache_info);
302 virtual ~CookieTreeAppCacheNode();
304 virtual void DeleteStoredObjects() OVERRIDE;
305 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
307 private:
308 GURL origin_url_;
309 std::list<content::AppCacheInfo>::iterator appcache_info_;
310 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCacheNode);
313 class CookieTreeAppCachesNode : public CookieTreeNode {
314 public:
315 CookieTreeAppCachesNode();
316 virtual ~CookieTreeAppCachesNode();
318 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
320 void AddAppCacheNode(CookieTreeAppCacheNode* child) {
321 AddChildSortedByTitle(child);
324 private:
325 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCachesNode);
328 // CookieTreeDatabaseNode -----------------------------------------------------
329 class CookieTreeDatabaseNode : public CookieTreeNode {
330 public:
331 friend class CookieTreeDatabasesNode;
333 // database_info should remain valid at least as long as the
334 // CookieTreeDatabaseNode is valid.
335 explicit CookieTreeDatabaseNode(
336 std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator
337 database_info);
338 virtual ~CookieTreeDatabaseNode();
340 virtual void DeleteStoredObjects() OVERRIDE;
341 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
343 private:
344 // database_info_ is expected to remain valid as long as the
345 // CookieTreeDatabaseNode is valid.
346 std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator
347 database_info_;
349 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabaseNode);
352 class CookieTreeDatabasesNode : public CookieTreeNode {
353 public:
354 CookieTreeDatabasesNode();
355 virtual ~CookieTreeDatabasesNode();
357 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
359 void AddDatabaseNode(CookieTreeDatabaseNode* child) {
360 AddChildSortedByTitle(child);
363 private:
364 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabasesNode);
367 // CookieTreeFileSystemNode --------------------------------------------------
368 class CookieTreeFileSystemNode : public CookieTreeNode {
369 public:
370 friend class CookieTreeFileSystemsNode;
372 // file_system_info should remain valid at least as long as the
373 // CookieTreeFileSystemNode is valid.
374 explicit CookieTreeFileSystemNode(
375 std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator
376 file_system_info);
377 virtual ~CookieTreeFileSystemNode();
379 virtual void DeleteStoredObjects() OVERRIDE;
380 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
382 private:
383 // file_system_info_ expected to remain valid as long as the
384 // CookieTreeFileSystemNode is valid.
385 std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator
386 file_system_info_;
388 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemNode);
391 class CookieTreeFileSystemsNode : public CookieTreeNode {
392 public:
393 CookieTreeFileSystemsNode();
394 virtual ~CookieTreeFileSystemsNode();
396 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
398 void AddFileSystemNode(CookieTreeFileSystemNode* child) {
399 AddChildSortedByTitle(child);
402 private:
403 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemsNode);
406 // CookieTreeLocalStorageNode -------------------------------------------------
407 class CookieTreeLocalStorageNode : public CookieTreeNode {
408 public:
409 // local_storage_info should remain valid at least as long as the
410 // CookieTreeLocalStorageNode is valid.
411 explicit CookieTreeLocalStorageNode(
412 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
413 local_storage_info);
414 virtual ~CookieTreeLocalStorageNode();
416 // CookieTreeNode methods:
417 virtual void DeleteStoredObjects() OVERRIDE;
418 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
420 private:
421 // local_storage_info_ is expected to remain valid as long as the
422 // CookieTreeLocalStorageNode is valid.
423 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
424 local_storage_info_;
426 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode);
429 class CookieTreeLocalStoragesNode : public CookieTreeNode {
430 public:
431 CookieTreeLocalStoragesNode();
432 virtual ~CookieTreeLocalStoragesNode();
434 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
436 void AddLocalStorageNode(CookieTreeLocalStorageNode* child) {
437 AddChildSortedByTitle(child);
440 private:
441 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode);
445 // CookieTreeSessionStorageNode -----------------------------------------------
446 class CookieTreeSessionStorageNode : public CookieTreeNode {
447 public:
448 // session_storage_info should remain valid at least as long as the
449 // CookieTreeSessionStorageNode is valid.
450 explicit CookieTreeSessionStorageNode(
451 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
452 session_storage_info);
453 virtual ~CookieTreeSessionStorageNode();
455 // CookieTreeNode methods:
456 virtual void DeleteStoredObjects() OVERRIDE;
457 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
459 private:
460 // session_storage_info_ is expected to remain valid as long as the
461 // CookieTreeSessionStorageNode is valid.
462 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
463 session_storage_info_;
465 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStorageNode);
468 class CookieTreeSessionStoragesNode : public CookieTreeNode {
469 public:
470 CookieTreeSessionStoragesNode();
471 virtual ~CookieTreeSessionStoragesNode();
473 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
475 void AddSessionStorageNode(CookieTreeSessionStorageNode* child) {
476 AddChildSortedByTitle(child);
479 private:
480 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStoragesNode);
483 // CookieTreeIndexedDBNode -----------------------------------------------
484 class CookieTreeIndexedDBNode : public CookieTreeNode {
485 public:
486 // indexed_db_info should remain valid at least as long as the
487 // CookieTreeIndexedDBNode is valid.
488 explicit CookieTreeIndexedDBNode(
489 std::list<content::IndexedDBInfo>::iterator
490 indexed_db_info);
491 virtual ~CookieTreeIndexedDBNode();
493 // CookieTreeNode methods:
494 virtual void DeleteStoredObjects() OVERRIDE;
495 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
497 private:
498 // indexed_db_info_ is expected to remain valid as long as the
499 // CookieTreeIndexedDBNode is valid.
500 std::list<content::IndexedDBInfo>::iterator
501 indexed_db_info_;
503 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBNode);
506 class CookieTreeIndexedDBsNode : public CookieTreeNode {
507 public:
508 CookieTreeIndexedDBsNode();
509 virtual ~CookieTreeIndexedDBsNode();
511 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
513 void AddIndexedDBNode(CookieTreeIndexedDBNode* child) {
514 AddChildSortedByTitle(child);
517 private:
518 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBsNode);
521 // CookieTreeQuotaNode --------------------------------------------------
522 class CookieTreeQuotaNode : public CookieTreeNode {
523 public:
524 // quota_info should remain valid at least as long as the CookieTreeQuotaNode
525 // is valid.
526 explicit CookieTreeQuotaNode(
527 std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info);
528 virtual ~CookieTreeQuotaNode();
530 virtual void DeleteStoredObjects() OVERRIDE;
531 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
533 private:
534 // quota_info_ is expected to remain valid as long as the CookieTreeQuotaNode
535 // is valid.
536 std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info_;
538 DISALLOW_COPY_AND_ASSIGN(CookieTreeQuotaNode);
541 // CookieTreeChannelIDNode ---------------------------------------------
542 class CookieTreeChannelIDNode : public CookieTreeNode {
543 public:
544 friend class CookieTreeChannelIDsNode;
546 // The iterator should remain valid at least as long as the
547 // CookieTreeChannelIDNode is valid.
548 explicit CookieTreeChannelIDNode(
549 net::ChannelIDStore::ChannelIDList::iterator cert);
550 virtual ~CookieTreeChannelIDNode();
552 // CookieTreeNode methods:
553 virtual void DeleteStoredObjects() OVERRIDE;
554 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
556 private:
557 // channel_id_ is expected to remain valid as long as the
558 // CookieTreeChannelIDNode is valid.
559 net::ChannelIDStore::ChannelIDList::iterator channel_id_;
561 DISALLOW_COPY_AND_ASSIGN(CookieTreeChannelIDNode);
564 class CookieTreeChannelIDsNode : public CookieTreeNode {
565 public:
566 CookieTreeChannelIDsNode();
567 virtual ~CookieTreeChannelIDsNode();
569 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
571 void AddChannelIDNode(CookieTreeChannelIDNode* child) {
572 AddChildSortedByTitle(child);
575 private:
576 DISALLOW_COPY_AND_ASSIGN(CookieTreeChannelIDsNode);
579 // CookieTreeServiceWorkerNode -----------------------------------------------
580 class CookieTreeServiceWorkerNode : public CookieTreeNode {
581 public:
582 // service_worker_info should remain valid at least as long as the
583 // CookieTreeServiceWorkerNode is valid.
584 explicit CookieTreeServiceWorkerNode(
585 std::list<content::ServiceWorkerUsageInfo>::iterator service_worker_info);
586 virtual ~CookieTreeServiceWorkerNode();
588 // CookieTreeNode methods:
589 virtual void DeleteStoredObjects() OVERRIDE;
590 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
592 private:
593 // service_worker_info_ is expected to remain valid as long as the
594 // CookieTreeServiceWorkerNode is valid.
595 std::list<content::ServiceWorkerUsageInfo>::iterator service_worker_info_;
597 DISALLOW_COPY_AND_ASSIGN(CookieTreeServiceWorkerNode);
600 class CookieTreeServiceWorkersNode : public CookieTreeNode {
601 public:
602 CookieTreeServiceWorkersNode();
603 virtual ~CookieTreeServiceWorkersNode();
605 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
607 void AddServiceWorkerNode(CookieTreeServiceWorkerNode* child) {
608 AddChildSortedByTitle(child);
611 private:
612 DISALLOW_COPY_AND_ASSIGN(CookieTreeServiceWorkersNode);
615 // CookieTreeFlashLSONode ----------------------------------------------------
616 class CookieTreeFlashLSONode : public CookieTreeNode {
617 public:
618 explicit CookieTreeFlashLSONode(const std::string& domain);
619 virtual ~CookieTreeFlashLSONode();
621 // CookieTreeNode methods:
622 virtual void DeleteStoredObjects() OVERRIDE;
623 virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
625 private:
626 std::string domain_;
628 DISALLOW_COPY_AND_ASSIGN(CookieTreeFlashLSONode);
631 // CookiesTreeModel -----------------------------------------------------------
632 class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
633 public:
634 CookiesTreeModel(LocalDataContainer* data_container,
635 ExtensionSpecialStoragePolicy* special_storage_policy,
636 bool group_by_cookie_source);
637 virtual ~CookiesTreeModel();
639 // Because non-cookie nodes are fetched in a background thread, they are not
640 // present at the time the Model is created. The Model then notifies its
641 // observers for every item added from databases, local storage, and
642 // appcache. We extend the Observer interface to add notifications before and
643 // after these batch inserts.
644 class Observer : public ui::TreeModelObserver {
645 public:
646 virtual void TreeModelBeginBatch(CookiesTreeModel* model) {}
647 virtual void TreeModelEndBatch(CookiesTreeModel* model) {}
650 // This class defines the scope for batch updates. It can be created as a
651 // local variable and the destructor will terminate the batch update, if one
652 // has been started.
653 class ScopedBatchUpdateNotifier {
654 public:
655 ScopedBatchUpdateNotifier(CookiesTreeModel* model,
656 CookieTreeNode* node);
657 ~ScopedBatchUpdateNotifier();
659 void StartBatchUpdate();
661 private:
662 CookiesTreeModel* model_;
663 CookieTreeNode* node_;
664 bool batch_in_progress_;
667 // ui::TreeModel methods:
668 // Returns the set of icons for the nodes in the tree. You only need override
669 // this if you don't want to use the default folder icons.
670 virtual void GetIcons(std::vector<gfx::ImageSkia>* icons) OVERRIDE;
672 // Returns the index of the icon to use for |node|. Return -1 to use the
673 // default icon. The index is relative to the list of icons returned from
674 // GetIcons.
675 virtual int GetIconIndex(ui::TreeModelNode* node) OVERRIDE;
677 // CookiesTreeModel methods:
678 void DeleteAllStoredObjects();
680 // Deletes a specific node in the tree, identified by |cookie_node|, and its
681 // subtree.
682 void DeleteCookieNode(CookieTreeNode* cookie_node);
684 // Filter the origins to only display matched results.
685 void UpdateSearchResults(const base::string16& filter);
687 #if defined(ENABLE_EXTENSIONS)
688 // Returns the set of extensions which protect the data item represented by
689 // this node from deletion.
690 // Returns NULL if the node doesn't represent a protected data item or the
691 // special storage policy is NULL.
692 const extensions::ExtensionSet* ExtensionsProtectingNode(
693 const CookieTreeNode& cookie_node);
694 #endif
696 // Manages CookiesTreeModel::Observers. This will also call
697 // TreeNodeModel::AddObserver so that it gets all the proper notifications.
698 // Note that the converse is not true: simply adding a TreeModelObserver will
699 // not get CookiesTreeModel::Observer notifications.
700 virtual void AddCookiesTreeObserver(Observer* observer);
701 virtual void RemoveCookiesTreeObserver(Observer* observer);
703 // Methods that update the model based on the data retrieved by the browsing
704 // data helpers.
705 void PopulateAppCacheInfo(LocalDataContainer* container);
706 void PopulateCookieInfo(LocalDataContainer* container);
707 void PopulateDatabaseInfo(LocalDataContainer* container);
708 void PopulateLocalStorageInfo(LocalDataContainer* container);
709 void PopulateSessionStorageInfo(LocalDataContainer* container);
710 void PopulateIndexedDBInfo(LocalDataContainer* container);
711 void PopulateFileSystemInfo(LocalDataContainer* container);
712 void PopulateQuotaInfo(LocalDataContainer* container);
713 void PopulateChannelIDInfo(LocalDataContainer* container);
714 void PopulateServiceWorkerUsageInfo(LocalDataContainer* container);
715 void PopulateFlashLSOInfo(LocalDataContainer* container);
717 BrowsingDataCookieHelper* GetCookieHelper(const std::string& app_id);
718 LocalDataContainer* data_container() {
719 return data_container_.get();
722 private:
723 enum CookieIconIndex {
724 ORIGIN = 0,
725 COOKIE = 1,
726 DATABASE = 2
729 void NotifyObserverBeginBatch();
730 void NotifyObserverEndBatch();
732 void PopulateAppCacheInfoWithFilter(LocalDataContainer* container,
733 ScopedBatchUpdateNotifier* notifier,
734 const base::string16& filter);
735 void PopulateCookieInfoWithFilter(LocalDataContainer* container,
736 ScopedBatchUpdateNotifier* notifier,
737 const base::string16& filter);
738 void PopulateDatabaseInfoWithFilter(LocalDataContainer* container,
739 ScopedBatchUpdateNotifier* notifier,
740 const base::string16& filter);
741 void PopulateLocalStorageInfoWithFilter(LocalDataContainer* container,
742 ScopedBatchUpdateNotifier* notifier,
743 const base::string16& filter);
744 void PopulateSessionStorageInfoWithFilter(LocalDataContainer* container,
745 ScopedBatchUpdateNotifier* notifier,
746 const base::string16& filter);
747 void PopulateIndexedDBInfoWithFilter(LocalDataContainer* container,
748 ScopedBatchUpdateNotifier* notifier,
749 const base::string16& filter);
750 void PopulateFileSystemInfoWithFilter(LocalDataContainer* container,
751 ScopedBatchUpdateNotifier* notifier,
752 const base::string16& filter);
753 void PopulateQuotaInfoWithFilter(LocalDataContainer* container,
754 ScopedBatchUpdateNotifier* notifier,
755 const base::string16& filter);
756 void PopulateChannelIDInfoWithFilter(
757 LocalDataContainer* container,
758 ScopedBatchUpdateNotifier* notifier,
759 const base::string16& filter);
760 void PopulateServiceWorkerUsageInfoWithFilter(
761 LocalDataContainer* container,
762 ScopedBatchUpdateNotifier* notifier,
763 const base::string16& filter);
764 void PopulateFlashLSOInfoWithFilter(LocalDataContainer* container,
765 ScopedBatchUpdateNotifier* notifier,
766 const base::string16& filter);
768 // Map of app ids to LocalDataContainer objects to use when retrieving
769 // locally stored data.
770 scoped_ptr<LocalDataContainer> data_container_;
772 #if defined(ENABLE_EXTENSIONS)
773 // The extension special storage policy; see ExtensionsProtectingNode() above.
774 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
775 #endif
777 // The CookiesTreeModel maintains a separate list of observers that are
778 // specifically of the type CookiesTreeModel::Observer.
779 ObserverList<Observer> cookies_observer_list_;
781 // If true, use the CanonicalCookie::Source attribute to group cookies.
782 // Otherwise, use the CanonicalCookie::Domain attribute.
783 bool group_by_cookie_source_;
785 // If this is non-zero, then this model is batching updates (there's a lot of
786 // notifications coming down the pipe). This is an integer is used to balance
787 // calls to Begin/EndBatch() if they're called in a nested manner.
788 int batch_update_;
791 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_