Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / browsing_data / cookies_tree_model.h
blob29af2f5e2ad6caadef4e9a92f4f146f6e2f7c00e
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 ~CookieTreeNode() override {}
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 ~CookieTreeRootNode() override;
178 CookieTreeHostNode* GetOrCreateHostNode(const GURL& url);
180 // CookieTreeNode methods:
181 CookiesTreeModel* GetModel() const override;
182 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 ~CookieTreeHostNode() override;
199 // CookieTreeNode methods:
200 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 ~CookieTreeCookieNode() override;
265 // CookieTreeNode methods:
266 void DeleteStoredObjects() override;
267 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 ~CookieTreeCookiesNode() override;
282 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 ~CookieTreeAppCacheNode() override;
304 void DeleteStoredObjects() override;
305 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 ~CookieTreeAppCachesNode() override;
318 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 ~CookieTreeDatabaseNode() override;
340 void DeleteStoredObjects() override;
341 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 ~CookieTreeDatabasesNode() override;
357 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 ~CookieTreeFileSystemNode() override;
379 void DeleteStoredObjects() override;
380 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 ~CookieTreeFileSystemsNode() override;
396 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 ~CookieTreeLocalStorageNode() override;
416 // CookieTreeNode methods:
417 void DeleteStoredObjects() override;
418 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 ~CookieTreeLocalStoragesNode() override;
434 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 ~CookieTreeSessionStorageNode() override;
455 // CookieTreeNode methods:
456 void DeleteStoredObjects() override;
457 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 ~CookieTreeSessionStoragesNode() override;
473 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 ~CookieTreeIndexedDBNode() override;
493 // CookieTreeNode methods:
494 void DeleteStoredObjects() override;
495 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 ~CookieTreeIndexedDBsNode() override;
511 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 ~CookieTreeQuotaNode() override;
530 void DeleteStoredObjects() override;
531 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 ~CookieTreeChannelIDNode() override;
552 // CookieTreeNode methods:
553 void DeleteStoredObjects() override;
554 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 ~CookieTreeChannelIDsNode() override;
569 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 ~CookieTreeServiceWorkerNode() override;
588 // CookieTreeNode methods:
589 void DeleteStoredObjects() override;
590 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 ~CookieTreeServiceWorkersNode() override;
605 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 ~CookieTreeFlashLSONode() override;
621 // CookieTreeNode methods:
622 void DeleteStoredObjects() override;
623 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 ~CookiesTreeModel() override;
639 // Given a CanonicalCookie, return the ID of the message which should be
640 // displayed in various ports' "Send for:" UI.
641 static int GetSendForMessageID(const net::CanonicalCookie& cookie);
643 // Because non-cookie nodes are fetched in a background thread, they are not
644 // present at the time the Model is created. The Model then notifies its
645 // observers for every item added from databases, local storage, and
646 // appcache. We extend the Observer interface to add notifications before and
647 // after these batch inserts.
648 class Observer : public ui::TreeModelObserver {
649 public:
650 virtual void TreeModelBeginBatch(CookiesTreeModel* model) {}
651 virtual void TreeModelEndBatch(CookiesTreeModel* model) {}
654 // This class defines the scope for batch updates. It can be created as a
655 // local variable and the destructor will terminate the batch update, if one
656 // has been started.
657 class ScopedBatchUpdateNotifier {
658 public:
659 ScopedBatchUpdateNotifier(CookiesTreeModel* model,
660 CookieTreeNode* node);
661 ~ScopedBatchUpdateNotifier();
663 void StartBatchUpdate();
665 private:
666 CookiesTreeModel* model_;
667 CookieTreeNode* node_;
668 bool batch_in_progress_;
671 // ui::TreeModel methods:
672 // Returns the set of icons for the nodes in the tree. You only need override
673 // this if you don't want to use the default folder icons.
674 void GetIcons(std::vector<gfx::ImageSkia>* icons) override;
676 // Returns the index of the icon to use for |node|. Return -1 to use the
677 // default icon. The index is relative to the list of icons returned from
678 // GetIcons.
679 int GetIconIndex(ui::TreeModelNode* node) override;
681 // CookiesTreeModel methods:
682 void DeleteAllStoredObjects();
684 // Deletes a specific node in the tree, identified by |cookie_node|, and its
685 // subtree.
686 void DeleteCookieNode(CookieTreeNode* cookie_node);
688 // Filter the origins to only display matched results.
689 void UpdateSearchResults(const base::string16& filter);
691 #if defined(ENABLE_EXTENSIONS)
692 // Returns the set of extensions which protect the data item represented by
693 // this node from deletion.
694 // Returns NULL if the node doesn't represent a protected data item or the
695 // special storage policy is NULL.
696 const extensions::ExtensionSet* ExtensionsProtectingNode(
697 const CookieTreeNode& cookie_node);
698 #endif
700 // Manages CookiesTreeModel::Observers. This will also call
701 // TreeNodeModel::AddObserver so that it gets all the proper notifications.
702 // Note that the converse is not true: simply adding a TreeModelObserver will
703 // not get CookiesTreeModel::Observer notifications.
704 virtual void AddCookiesTreeObserver(Observer* observer);
705 virtual void RemoveCookiesTreeObserver(Observer* observer);
707 // Methods that update the model based on the data retrieved by the browsing
708 // data helpers.
709 void PopulateAppCacheInfo(LocalDataContainer* container);
710 void PopulateCookieInfo(LocalDataContainer* container);
711 void PopulateDatabaseInfo(LocalDataContainer* container);
712 void PopulateLocalStorageInfo(LocalDataContainer* container);
713 void PopulateSessionStorageInfo(LocalDataContainer* container);
714 void PopulateIndexedDBInfo(LocalDataContainer* container);
715 void PopulateFileSystemInfo(LocalDataContainer* container);
716 void PopulateQuotaInfo(LocalDataContainer* container);
717 void PopulateChannelIDInfo(LocalDataContainer* container);
718 void PopulateServiceWorkerUsageInfo(LocalDataContainer* container);
719 void PopulateFlashLSOInfo(LocalDataContainer* container);
721 BrowsingDataCookieHelper* GetCookieHelper(const std::string& app_id);
722 LocalDataContainer* data_container() {
723 return data_container_.get();
726 // Set the number of |batches_expected| this class should expect to receive.
727 // If |reset| is true, then this is a new set of batches, but if false, then
728 // this is a revised number (batches originally counted should no longer be
729 // expected).
730 void SetBatchExpectation(int batches_expected, bool reset);
732 private:
733 enum CookieIconIndex {
734 ORIGIN = 0,
735 COOKIE = 1,
736 DATABASE = 2
739 // Reset the counters for batches.
740 void ResetBatches();
742 // Record that one batch has been delivered.
743 void RecordBatchSeen();
745 // Record that one batch has begun processing. If this is the first batch then
746 // observers will be notified that batch processing has started.
747 void NotifyObserverBeginBatch();
749 // Record that one batch has finished processing. If this is the last batch
750 // then observers will be notified that batch processing has ended.
751 void NotifyObserverEndBatch();
753 // Notifies observers if expected batch count has been delievered and all
754 // batches have finished processing.
755 void MaybeNotifyBatchesEnded();
757 void PopulateAppCacheInfoWithFilter(LocalDataContainer* container,
758 ScopedBatchUpdateNotifier* notifier,
759 const base::string16& filter);
760 void PopulateCookieInfoWithFilter(LocalDataContainer* container,
761 ScopedBatchUpdateNotifier* notifier,
762 const base::string16& filter);
763 void PopulateDatabaseInfoWithFilter(LocalDataContainer* container,
764 ScopedBatchUpdateNotifier* notifier,
765 const base::string16& filter);
766 void PopulateLocalStorageInfoWithFilter(LocalDataContainer* container,
767 ScopedBatchUpdateNotifier* notifier,
768 const base::string16& filter);
769 void PopulateSessionStorageInfoWithFilter(LocalDataContainer* container,
770 ScopedBatchUpdateNotifier* notifier,
771 const base::string16& filter);
772 void PopulateIndexedDBInfoWithFilter(LocalDataContainer* container,
773 ScopedBatchUpdateNotifier* notifier,
774 const base::string16& filter);
775 void PopulateFileSystemInfoWithFilter(LocalDataContainer* container,
776 ScopedBatchUpdateNotifier* notifier,
777 const base::string16& filter);
778 void PopulateQuotaInfoWithFilter(LocalDataContainer* container,
779 ScopedBatchUpdateNotifier* notifier,
780 const base::string16& filter);
781 void PopulateChannelIDInfoWithFilter(
782 LocalDataContainer* container,
783 ScopedBatchUpdateNotifier* notifier,
784 const base::string16& filter);
785 void PopulateServiceWorkerUsageInfoWithFilter(
786 LocalDataContainer* container,
787 ScopedBatchUpdateNotifier* notifier,
788 const base::string16& filter);
789 void PopulateFlashLSOInfoWithFilter(LocalDataContainer* container,
790 ScopedBatchUpdateNotifier* notifier,
791 const base::string16& filter);
793 // Map of app ids to LocalDataContainer objects to use when retrieving
794 // locally stored data.
795 scoped_ptr<LocalDataContainer> data_container_;
797 #if defined(ENABLE_EXTENSIONS)
798 // The extension special storage policy; see ExtensionsProtectingNode() above.
799 scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
800 #endif
802 // The CookiesTreeModel maintains a separate list of observers that are
803 // specifically of the type CookiesTreeModel::Observer.
804 ObserverList<Observer> cookies_observer_list_;
806 // If true, use the CanonicalCookie::Source attribute to group cookies.
807 // Otherwise, use the CanonicalCookie::Domain attribute.
808 bool group_by_cookie_source_;
810 // Keeps track of how many batches the consumer of this class says it is going
811 // to send.
812 int batches_expected_;
814 // Keeps track of how many batches we've seen.
815 int batches_seen_;
817 // Counts how many batches have started already. If this is non-zero and lower
818 // than batches_ended_, then this model is still batching updates.
819 int batches_started_;
821 // Counts how many batches have finished.
822 int batches_ended_;
825 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_