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).
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 CookiesTreeModel
;
35 class CookieTreeAppCacheNode
;
36 class CookieTreeAppCachesNode
;
37 class CookieTreeChannelIDNode
;
38 class CookieTreeChannelIDsNode
;
39 class CookieTreeCookieNode
;
40 class CookieTreeCookiesNode
;
41 class CookieTreeDatabaseNode
;
42 class CookieTreeDatabasesNode
;
43 class CookieTreeFileSystemNode
;
44 class CookieTreeFileSystemsNode
;
45 class CookieTreeFlashLSONode
;
46 class CookieTreeHostNode
;
47 class CookieTreeIndexedDBNode
;
48 class CookieTreeIndexedDBsNode
;
49 class CookieTreeLocalStorageNode
;
50 class CookieTreeLocalStoragesNode
;
51 class CookieTreeQuotaNode
;
52 class CookieTreeServiceWorkerNode
;
53 class CookieTreeServiceWorkersNode
;
54 class CookieTreeSessionStorageNode
;
55 class CookieTreeSessionStoragesNode
;
56 class ExtensionSpecialStoragePolicy
;
58 namespace content_settings
{
62 namespace extensions
{
67 class CanonicalCookie
;
70 // CookieTreeNode -------------------------------------------------------------
71 // The base node type in the Cookies, Databases, and Local Storage options
72 // view, from which all other types are derived. Specialized from TreeNode in
73 // that it has a notion of deleting objects stored in the profile, and being
74 // able to have its children do the same.
75 class CookieTreeNode
: public ui::TreeNode
<CookieTreeNode
> {
77 // Used to pull out information for the InfoView (the details display below
80 // NodeType corresponds to the various CookieTreeNode types.
83 TYPE_ROOT
, // This is used for CookieTreeRootNode nodes.
84 TYPE_HOST
, // This is used for CookieTreeHostNode nodes.
85 TYPE_COOKIES
, // This is used for CookieTreeCookiesNode nodes.
86 TYPE_COOKIE
, // This is used for CookieTreeCookieNode nodes.
87 TYPE_DATABASES
, // This is used for CookieTreeDatabasesNode.
88 TYPE_DATABASE
, // This is used for CookieTreeDatabaseNode.
89 TYPE_LOCAL_STORAGES
, // This is used for CookieTreeLocalStoragesNode.
90 TYPE_LOCAL_STORAGE
, // This is used for CookieTreeLocalStorageNode.
91 TYPE_SESSION_STORAGES
, // This is used for CookieTreeSessionStoragesNode.
92 TYPE_SESSION_STORAGE
, // This is used for CookieTreeSessionStorageNode.
93 TYPE_APPCACHES
, // This is used for CookieTreeAppCachesNode.
94 TYPE_APPCACHE
, // This is used for CookieTreeAppCacheNode.
95 TYPE_INDEXED_DBS
, // This is used for CookieTreeIndexedDBsNode.
96 TYPE_INDEXED_DB
, // This is used for CookieTreeIndexedDBNode.
97 TYPE_FILE_SYSTEMS
, // This is used for CookieTreeFileSystemsNode.
98 TYPE_FILE_SYSTEM
, // This is used for CookieTreeFileSystemNode.
99 TYPE_QUOTA
, // This is used for CookieTreeQuotaNode.
100 TYPE_CHANNEL_IDS
, // Used for CookieTreeChannelIDsNode.
101 TYPE_CHANNEL_ID
, // Used for CookieTreeChannelIDNode.
102 TYPE_SERVICE_WORKERS
, // This is used for CookieTreeServiceWorkersNode.
103 TYPE_SERVICE_WORKER
, // This is used for CookieTreeServiceWorkerNode.
104 TYPE_FLASH_LSO
, // This is used for CookieTreeFlashLSONode.
110 DetailedInfo
& Init(NodeType type
);
111 DetailedInfo
& InitHost();
112 DetailedInfo
& InitCookie(const net::CanonicalCookie
* cookie
);
113 DetailedInfo
& InitDatabase(
114 const BrowsingDataDatabaseHelper::DatabaseInfo
* database_info
);
115 DetailedInfo
& InitLocalStorage(
116 const BrowsingDataLocalStorageHelper::LocalStorageInfo
*
118 DetailedInfo
& InitSessionStorage(
119 const BrowsingDataLocalStorageHelper::LocalStorageInfo
*
120 session_storage_info
);
121 DetailedInfo
& InitAppCache(const GURL
& origin
,
122 const content::AppCacheInfo
* appcache_info
);
123 DetailedInfo
& InitIndexedDB(
124 const content::IndexedDBInfo
* indexed_db_info
);
125 DetailedInfo
& InitFileSystem(
126 const BrowsingDataFileSystemHelper::FileSystemInfo
* file_system_info
);
127 DetailedInfo
& InitQuota(
128 const BrowsingDataQuotaHelper::QuotaInfo
* quota_info
);
129 DetailedInfo
& InitChannelID(
130 const net::ChannelIDStore::ChannelID
* channel_id
);
131 DetailedInfo
& InitServiceWorker(
132 const content::ServiceWorkerUsageInfo
* service_worker_info
);
133 DetailedInfo
& InitFlashLSO(const std::string
& flash_lso_domain
);
137 const net::CanonicalCookie
* cookie
= nullptr;
138 const BrowsingDataDatabaseHelper::DatabaseInfo
* database_info
= nullptr;
139 const BrowsingDataLocalStorageHelper::LocalStorageInfo
* local_storage_info
=
141 const BrowsingDataLocalStorageHelper::LocalStorageInfo
*
142 session_storage_info
= nullptr;
143 const content::AppCacheInfo
* appcache_info
= nullptr;
144 const content::IndexedDBInfo
* indexed_db_info
= nullptr;
145 const BrowsingDataFileSystemHelper::FileSystemInfo
* file_system_info
=
147 const BrowsingDataQuotaHelper::QuotaInfo
* quota_info
= nullptr;
148 const net::ChannelIDStore::ChannelID
* channel_id
= nullptr;
149 const content::ServiceWorkerUsageInfo
* service_worker_info
= nullptr;
150 std::string flash_lso_domain
;
154 explicit CookieTreeNode(const base::string16
& title
)
155 : ui::TreeNode
<CookieTreeNode
>(title
) {}
156 ~CookieTreeNode() override
{}
158 // Delete backend storage for this node, and any children nodes. (E.g. delete
159 // the cookie from CookieMonster, clear the database, and so forth.)
160 virtual void DeleteStoredObjects();
162 // Gets a pointer back to the associated model for the tree we are in.
163 virtual CookiesTreeModel
* GetModel() const;
165 // Returns a struct with detailed information used to populate the details
167 virtual DetailedInfo
GetDetailedInfo() const = 0;
170 void AddChildSortedByTitle(CookieTreeNode
* new_child
);
173 DISALLOW_COPY_AND_ASSIGN(CookieTreeNode
);
176 // CookieTreeRootNode ---------------------------------------------------------
177 // The node at the root of the CookieTree that gets inserted into the view.
178 class CookieTreeRootNode
: public CookieTreeNode
{
180 explicit CookieTreeRootNode(CookiesTreeModel
* model
);
181 ~CookieTreeRootNode() override
;
183 CookieTreeHostNode
* GetOrCreateHostNode(const GURL
& url
);
185 // CookieTreeNode methods:
186 CookiesTreeModel
* GetModel() const override
;
187 DetailedInfo
GetDetailedInfo() const override
;
190 CookiesTreeModel
* model_
;
192 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode
);
195 // CookieTreeHostNode -------------------------------------------------------
196 class CookieTreeHostNode
: public CookieTreeNode
{
198 // Returns the host node's title to use for a given URL.
199 static base::string16
TitleForUrl(const GURL
& url
);
201 explicit CookieTreeHostNode(const GURL
& url
);
202 ~CookieTreeHostNode() override
;
204 // CookieTreeNode methods:
205 DetailedInfo
GetDetailedInfo() const override
;
207 // CookieTreeHostNode methods:
208 CookieTreeCookiesNode
* GetOrCreateCookiesNode();
209 CookieTreeDatabasesNode
* GetOrCreateDatabasesNode();
210 CookieTreeLocalStoragesNode
* GetOrCreateLocalStoragesNode();
211 CookieTreeSessionStoragesNode
* GetOrCreateSessionStoragesNode();
212 CookieTreeAppCachesNode
* GetOrCreateAppCachesNode();
213 CookieTreeIndexedDBsNode
* GetOrCreateIndexedDBsNode();
214 CookieTreeFileSystemsNode
* GetOrCreateFileSystemsNode();
215 CookieTreeChannelIDsNode
* GetOrCreateChannelIDsNode();
216 CookieTreeServiceWorkersNode
* GetOrCreateServiceWorkersNode();
217 CookieTreeQuotaNode
* UpdateOrCreateQuotaNode(
218 std::list
<BrowsingDataQuotaHelper::QuotaInfo
>::iterator quota_info
);
219 CookieTreeFlashLSONode
* GetOrCreateFlashLSONode(const std::string
& domain
);
221 std::string
canonicalized_host() const { return canonicalized_host_
; }
223 // Creates an content exception for this origin of type
224 // CONTENT_SETTINGS_TYPE_COOKIES.
225 void CreateContentException(content_settings::CookieSettings
* cookie_settings
,
226 ContentSetting setting
) const;
228 // True if a content exception can be created for this origin.
229 bool CanCreateContentException() const;
231 const std::string
GetHost() const;
234 // Pointers to the cookies, databases, local and session storage and appcache
235 // nodes. When we build up the tree we need to quickly get a reference to
236 // the COOKIES node to add children. Checking each child and interrogating
237 // them to see if they are a COOKIES, APPCACHES, DATABASES etc node seems
238 // less preferable than storing an extra pointer per origin.
239 CookieTreeCookiesNode
* cookies_child_
= nullptr;
240 CookieTreeDatabasesNode
* databases_child_
= nullptr;
241 CookieTreeLocalStoragesNode
* local_storages_child_
= nullptr;
242 CookieTreeSessionStoragesNode
* session_storages_child_
= nullptr;
243 CookieTreeAppCachesNode
* appcaches_child_
= nullptr;
244 CookieTreeIndexedDBsNode
* indexed_dbs_child_
= nullptr;
245 CookieTreeFileSystemsNode
* file_systems_child_
= nullptr;
246 CookieTreeQuotaNode
* quota_child_
= nullptr;
247 CookieTreeChannelIDsNode
* channel_ids_child_
= nullptr;
248 CookieTreeServiceWorkersNode
* service_workers_child_
= nullptr;
249 CookieTreeFlashLSONode
* flash_lso_child_
= nullptr;
251 // The URL for which this node was initially created.
254 std::string canonicalized_host_
;
256 DISALLOW_COPY_AND_ASSIGN(CookieTreeHostNode
);
259 // CookieTreeCookieNode ------------------------------------------------------
260 class CookieTreeCookieNode
: public CookieTreeNode
{
262 friend class CookieTreeCookiesNode
;
264 // The cookie should remain valid at least as long as the
265 // CookieTreeCookieNode is valid.
266 explicit CookieTreeCookieNode(
267 std::list
<net::CanonicalCookie
>::iterator cookie
);
268 ~CookieTreeCookieNode() override
;
270 // CookieTreeNode methods:
271 void DeleteStoredObjects() override
;
272 DetailedInfo
GetDetailedInfo() const override
;
275 // cookie_ is expected to remain valid as long as the CookieTreeCookieNode is
277 std::list
<net::CanonicalCookie
>::iterator cookie_
;
279 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode
);
282 class CookieTreeCookiesNode
: public CookieTreeNode
{
284 CookieTreeCookiesNode();
285 ~CookieTreeCookiesNode() override
;
287 DetailedInfo
GetDetailedInfo() const override
;
289 void AddCookieNode(CookieTreeCookieNode
* child
) {
290 AddChildSortedByTitle(child
);
294 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode
);
297 // CookieTreeAppCacheNode -----------------------------------------------------
298 class CookieTreeAppCacheNode
: public CookieTreeNode
{
300 friend class CookieTreeAppCachesNode
;
302 // appcache_info should remain valid at least as long as the
303 // CookieTreeAppCacheNode is valid.
304 explicit CookieTreeAppCacheNode(
305 const GURL
& origin_url
,
306 std::list
<content::AppCacheInfo
>::iterator appcache_info
);
307 ~CookieTreeAppCacheNode() override
;
309 void DeleteStoredObjects() override
;
310 DetailedInfo
GetDetailedInfo() const override
;
314 std::list
<content::AppCacheInfo
>::iterator appcache_info_
;
315 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCacheNode
);
318 class CookieTreeAppCachesNode
: public CookieTreeNode
{
320 CookieTreeAppCachesNode();
321 ~CookieTreeAppCachesNode() override
;
323 DetailedInfo
GetDetailedInfo() const override
;
325 void AddAppCacheNode(CookieTreeAppCacheNode
* child
) {
326 AddChildSortedByTitle(child
);
330 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCachesNode
);
333 // CookieTreeDatabaseNode -----------------------------------------------------
334 class CookieTreeDatabaseNode
: public CookieTreeNode
{
336 friend class CookieTreeDatabasesNode
;
338 // database_info should remain valid at least as long as the
339 // CookieTreeDatabaseNode is valid.
340 explicit CookieTreeDatabaseNode(
341 std::list
<BrowsingDataDatabaseHelper::DatabaseInfo
>::iterator
343 ~CookieTreeDatabaseNode() override
;
345 void DeleteStoredObjects() override
;
346 DetailedInfo
GetDetailedInfo() const override
;
349 // database_info_ is expected to remain valid as long as the
350 // CookieTreeDatabaseNode is valid.
351 std::list
<BrowsingDataDatabaseHelper::DatabaseInfo
>::iterator
354 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabaseNode
);
357 class CookieTreeDatabasesNode
: public CookieTreeNode
{
359 CookieTreeDatabasesNode();
360 ~CookieTreeDatabasesNode() override
;
362 DetailedInfo
GetDetailedInfo() const override
;
364 void AddDatabaseNode(CookieTreeDatabaseNode
* child
) {
365 AddChildSortedByTitle(child
);
369 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabasesNode
);
372 // CookieTreeFileSystemNode --------------------------------------------------
373 class CookieTreeFileSystemNode
: public CookieTreeNode
{
375 friend class CookieTreeFileSystemsNode
;
377 // file_system_info should remain valid at least as long as the
378 // CookieTreeFileSystemNode is valid.
379 explicit CookieTreeFileSystemNode(
380 std::list
<BrowsingDataFileSystemHelper::FileSystemInfo
>::iterator
382 ~CookieTreeFileSystemNode() override
;
384 void DeleteStoredObjects() override
;
385 DetailedInfo
GetDetailedInfo() const override
;
388 // file_system_info_ expected to remain valid as long as the
389 // CookieTreeFileSystemNode is valid.
390 std::list
<BrowsingDataFileSystemHelper::FileSystemInfo
>::iterator
393 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemNode
);
396 class CookieTreeFileSystemsNode
: public CookieTreeNode
{
398 CookieTreeFileSystemsNode();
399 ~CookieTreeFileSystemsNode() override
;
401 DetailedInfo
GetDetailedInfo() const override
;
403 void AddFileSystemNode(CookieTreeFileSystemNode
* child
) {
404 AddChildSortedByTitle(child
);
408 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemsNode
);
411 // CookieTreeLocalStorageNode -------------------------------------------------
412 class CookieTreeLocalStorageNode
: public CookieTreeNode
{
414 // local_storage_info should remain valid at least as long as the
415 // CookieTreeLocalStorageNode is valid.
416 explicit CookieTreeLocalStorageNode(
417 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
419 ~CookieTreeLocalStorageNode() override
;
421 // CookieTreeNode methods:
422 void DeleteStoredObjects() override
;
423 DetailedInfo
GetDetailedInfo() const override
;
426 // local_storage_info_ is expected to remain valid as long as the
427 // CookieTreeLocalStorageNode is valid.
428 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
431 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode
);
434 class CookieTreeLocalStoragesNode
: public CookieTreeNode
{
436 CookieTreeLocalStoragesNode();
437 ~CookieTreeLocalStoragesNode() override
;
439 DetailedInfo
GetDetailedInfo() const override
;
441 void AddLocalStorageNode(CookieTreeLocalStorageNode
* child
) {
442 AddChildSortedByTitle(child
);
446 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode
);
450 // CookieTreeSessionStorageNode -----------------------------------------------
451 class CookieTreeSessionStorageNode
: public CookieTreeNode
{
453 // session_storage_info should remain valid at least as long as the
454 // CookieTreeSessionStorageNode is valid.
455 explicit CookieTreeSessionStorageNode(
456 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
457 session_storage_info
);
458 ~CookieTreeSessionStorageNode() override
;
460 // CookieTreeNode methods:
461 void DeleteStoredObjects() override
;
462 DetailedInfo
GetDetailedInfo() const override
;
465 // session_storage_info_ is expected to remain valid as long as the
466 // CookieTreeSessionStorageNode is valid.
467 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
468 session_storage_info_
;
470 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStorageNode
);
473 class CookieTreeSessionStoragesNode
: public CookieTreeNode
{
475 CookieTreeSessionStoragesNode();
476 ~CookieTreeSessionStoragesNode() override
;
478 DetailedInfo
GetDetailedInfo() const override
;
480 void AddSessionStorageNode(CookieTreeSessionStorageNode
* child
) {
481 AddChildSortedByTitle(child
);
485 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStoragesNode
);
488 // CookieTreeIndexedDBNode -----------------------------------------------
489 class CookieTreeIndexedDBNode
: public CookieTreeNode
{
491 // indexed_db_info should remain valid at least as long as the
492 // CookieTreeIndexedDBNode is valid.
493 explicit CookieTreeIndexedDBNode(
494 std::list
<content::IndexedDBInfo
>::iterator
496 ~CookieTreeIndexedDBNode() override
;
498 // CookieTreeNode methods:
499 void DeleteStoredObjects() override
;
500 DetailedInfo
GetDetailedInfo() const override
;
503 // indexed_db_info_ is expected to remain valid as long as the
504 // CookieTreeIndexedDBNode is valid.
505 std::list
<content::IndexedDBInfo
>::iterator
508 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBNode
);
511 class CookieTreeIndexedDBsNode
: public CookieTreeNode
{
513 CookieTreeIndexedDBsNode();
514 ~CookieTreeIndexedDBsNode() override
;
516 DetailedInfo
GetDetailedInfo() const override
;
518 void AddIndexedDBNode(CookieTreeIndexedDBNode
* child
) {
519 AddChildSortedByTitle(child
);
523 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBsNode
);
526 // CookieTreeQuotaNode --------------------------------------------------
527 class CookieTreeQuotaNode
: public CookieTreeNode
{
529 // quota_info should remain valid at least as long as the CookieTreeQuotaNode
531 explicit CookieTreeQuotaNode(
532 std::list
<BrowsingDataQuotaHelper::QuotaInfo
>::iterator quota_info
);
533 ~CookieTreeQuotaNode() override
;
535 void DeleteStoredObjects() override
;
536 DetailedInfo
GetDetailedInfo() const override
;
539 // quota_info_ is expected to remain valid as long as the CookieTreeQuotaNode
541 std::list
<BrowsingDataQuotaHelper::QuotaInfo
>::iterator quota_info_
;
543 DISALLOW_COPY_AND_ASSIGN(CookieTreeQuotaNode
);
546 // CookieTreeChannelIDNode ---------------------------------------------
547 class CookieTreeChannelIDNode
: public CookieTreeNode
{
549 friend class CookieTreeChannelIDsNode
;
551 // The iterator should remain valid at least as long as the
552 // CookieTreeChannelIDNode is valid.
553 explicit CookieTreeChannelIDNode(
554 net::ChannelIDStore::ChannelIDList::iterator cert
);
555 ~CookieTreeChannelIDNode() override
;
557 // CookieTreeNode methods:
558 void DeleteStoredObjects() override
;
559 DetailedInfo
GetDetailedInfo() const override
;
562 // channel_id_ is expected to remain valid as long as the
563 // CookieTreeChannelIDNode is valid.
564 net::ChannelIDStore::ChannelIDList::iterator channel_id_
;
566 DISALLOW_COPY_AND_ASSIGN(CookieTreeChannelIDNode
);
569 class CookieTreeChannelIDsNode
: public CookieTreeNode
{
571 CookieTreeChannelIDsNode();
572 ~CookieTreeChannelIDsNode() override
;
574 DetailedInfo
GetDetailedInfo() const override
;
576 void AddChannelIDNode(CookieTreeChannelIDNode
* child
) {
577 AddChildSortedByTitle(child
);
581 DISALLOW_COPY_AND_ASSIGN(CookieTreeChannelIDsNode
);
584 // CookieTreeServiceWorkerNode -----------------------------------------------
585 class CookieTreeServiceWorkerNode
: public CookieTreeNode
{
587 // service_worker_info should remain valid at least as long as the
588 // CookieTreeServiceWorkerNode is valid.
589 explicit CookieTreeServiceWorkerNode(
590 std::list
<content::ServiceWorkerUsageInfo
>::iterator service_worker_info
);
591 ~CookieTreeServiceWorkerNode() override
;
593 // CookieTreeNode methods:
594 void DeleteStoredObjects() override
;
595 DetailedInfo
GetDetailedInfo() const override
;
598 // service_worker_info_ is expected to remain valid as long as the
599 // CookieTreeServiceWorkerNode is valid.
600 std::list
<content::ServiceWorkerUsageInfo
>::iterator service_worker_info_
;
602 DISALLOW_COPY_AND_ASSIGN(CookieTreeServiceWorkerNode
);
605 class CookieTreeServiceWorkersNode
: public CookieTreeNode
{
607 CookieTreeServiceWorkersNode();
608 ~CookieTreeServiceWorkersNode() override
;
610 DetailedInfo
GetDetailedInfo() const override
;
612 void AddServiceWorkerNode(CookieTreeServiceWorkerNode
* child
) {
613 AddChildSortedByTitle(child
);
617 DISALLOW_COPY_AND_ASSIGN(CookieTreeServiceWorkersNode
);
620 // CookieTreeFlashLSONode ----------------------------------------------------
621 class CookieTreeFlashLSONode
: public CookieTreeNode
{
623 explicit CookieTreeFlashLSONode(const std::string
& domain
);
624 ~CookieTreeFlashLSONode() override
;
626 // CookieTreeNode methods:
627 void DeleteStoredObjects() override
;
628 DetailedInfo
GetDetailedInfo() const override
;
633 DISALLOW_COPY_AND_ASSIGN(CookieTreeFlashLSONode
);
636 // CookiesTreeModel -----------------------------------------------------------
637 class CookiesTreeModel
: public ui::TreeNodeModel
<CookieTreeNode
> {
639 CookiesTreeModel(LocalDataContainer
* data_container
,
640 ExtensionSpecialStoragePolicy
* special_storage_policy
,
641 bool group_by_cookie_source
);
642 ~CookiesTreeModel() override
;
644 // Given a CanonicalCookie, return the ID of the message which should be
645 // displayed in various ports' "Send for:" UI.
646 static int GetSendForMessageID(const net::CanonicalCookie
& cookie
);
648 // Because non-cookie nodes are fetched in a background thread, they are not
649 // present at the time the Model is created. The Model then notifies its
650 // observers for every item added from databases, local storage, and
651 // appcache. We extend the Observer interface to add notifications before and
652 // after these batch inserts.
653 class Observer
: public ui::TreeModelObserver
{
655 virtual void TreeModelBeginBatch(CookiesTreeModel
* model
) {}
656 virtual void TreeModelEndBatch(CookiesTreeModel
* model
) {}
659 // This class defines the scope for batch updates. It can be created as a
660 // local variable and the destructor will terminate the batch update, if one
662 class ScopedBatchUpdateNotifier
{
664 ScopedBatchUpdateNotifier(CookiesTreeModel
* model
,
665 CookieTreeNode
* node
);
666 ~ScopedBatchUpdateNotifier();
668 void StartBatchUpdate();
671 CookiesTreeModel
* model_
;
672 CookieTreeNode
* node_
;
673 bool batch_in_progress_
= false;
676 // ui::TreeModel methods:
677 // Returns the set of icons for the nodes in the tree. You only need override
678 // this if you don't want to use the default folder icons.
679 void GetIcons(std::vector
<gfx::ImageSkia
>* icons
) override
;
681 // Returns the index of the icon to use for |node|. Return -1 to use the
682 // default icon. The index is relative to the list of icons returned from
684 int GetIconIndex(ui::TreeModelNode
* node
) override
;
686 // CookiesTreeModel methods:
687 void DeleteAllStoredObjects();
689 // Deletes a specific node in the tree, identified by |cookie_node|, and its
691 void DeleteCookieNode(CookieTreeNode
* cookie_node
);
693 // Filter the origins to only display matched results.
694 void UpdateSearchResults(const base::string16
& filter
);
696 #if defined(ENABLE_EXTENSIONS)
697 // Returns the set of extensions which protect the data item represented by
698 // this node from deletion.
699 // Returns nullptr if the node doesn't represent a protected data item or the
700 // special storage policy is nullptr.
701 const extensions::ExtensionSet
* ExtensionsProtectingNode(
702 const CookieTreeNode
& cookie_node
);
705 // Manages CookiesTreeModel::Observers. This will also call
706 // TreeNodeModel::AddObserver so that it gets all the proper notifications.
707 // Note that the converse is not true: simply adding a TreeModelObserver will
708 // not get CookiesTreeModel::Observer notifications.
709 virtual void AddCookiesTreeObserver(Observer
* observer
);
710 virtual void RemoveCookiesTreeObserver(Observer
* observer
);
712 // Methods that update the model based on the data retrieved by the browsing
714 void PopulateAppCacheInfo(LocalDataContainer
* container
);
715 void PopulateCookieInfo(LocalDataContainer
* container
);
716 void PopulateDatabaseInfo(LocalDataContainer
* container
);
717 void PopulateLocalStorageInfo(LocalDataContainer
* container
);
718 void PopulateSessionStorageInfo(LocalDataContainer
* container
);
719 void PopulateIndexedDBInfo(LocalDataContainer
* container
);
720 void PopulateFileSystemInfo(LocalDataContainer
* container
);
721 void PopulateQuotaInfo(LocalDataContainer
* container
);
722 void PopulateChannelIDInfo(LocalDataContainer
* container
);
723 void PopulateServiceWorkerUsageInfo(LocalDataContainer
* container
);
724 void PopulateFlashLSOInfo(LocalDataContainer
* container
);
726 BrowsingDataCookieHelper
* GetCookieHelper(const std::string
& app_id
);
727 LocalDataContainer
* data_container() {
728 return data_container_
.get();
731 // Set the number of |batches_expected| this class should expect to receive.
732 // If |reset| is true, then this is a new set of batches, but if false, then
733 // this is a revised number (batches originally counted should no longer be
735 void SetBatchExpectation(int batches_expected
, bool reset
);
738 enum CookieIconIndex
{
744 // Reset the counters for batches.
747 // Record that one batch has been delivered.
748 void RecordBatchSeen();
750 // Record that one batch has begun processing. If this is the first batch then
751 // observers will be notified that batch processing has started.
752 void NotifyObserverBeginBatch();
754 // Record that one batch has finished processing. If this is the last batch
755 // then observers will be notified that batch processing has ended.
756 void NotifyObserverEndBatch();
758 // Notifies observers if expected batch count has been delievered and all
759 // batches have finished processing.
760 void MaybeNotifyBatchesEnded();
762 void PopulateAppCacheInfoWithFilter(LocalDataContainer
* container
,
763 ScopedBatchUpdateNotifier
* notifier
,
764 const base::string16
& filter
);
765 void PopulateCookieInfoWithFilter(LocalDataContainer
* container
,
766 ScopedBatchUpdateNotifier
* notifier
,
767 const base::string16
& filter
);
768 void PopulateDatabaseInfoWithFilter(LocalDataContainer
* container
,
769 ScopedBatchUpdateNotifier
* notifier
,
770 const base::string16
& filter
);
771 void PopulateLocalStorageInfoWithFilter(LocalDataContainer
* container
,
772 ScopedBatchUpdateNotifier
* notifier
,
773 const base::string16
& filter
);
774 void PopulateSessionStorageInfoWithFilter(LocalDataContainer
* container
,
775 ScopedBatchUpdateNotifier
* notifier
,
776 const base::string16
& filter
);
777 void PopulateIndexedDBInfoWithFilter(LocalDataContainer
* container
,
778 ScopedBatchUpdateNotifier
* notifier
,
779 const base::string16
& filter
);
780 void PopulateFileSystemInfoWithFilter(LocalDataContainer
* container
,
781 ScopedBatchUpdateNotifier
* notifier
,
782 const base::string16
& filter
);
783 void PopulateQuotaInfoWithFilter(LocalDataContainer
* container
,
784 ScopedBatchUpdateNotifier
* notifier
,
785 const base::string16
& filter
);
786 void PopulateChannelIDInfoWithFilter(
787 LocalDataContainer
* container
,
788 ScopedBatchUpdateNotifier
* notifier
,
789 const base::string16
& filter
);
790 void PopulateServiceWorkerUsageInfoWithFilter(
791 LocalDataContainer
* container
,
792 ScopedBatchUpdateNotifier
* notifier
,
793 const base::string16
& filter
);
794 void PopulateFlashLSOInfoWithFilter(LocalDataContainer
* container
,
795 ScopedBatchUpdateNotifier
* notifier
,
796 const base::string16
& filter
);
798 // Map of app ids to LocalDataContainer objects to use when retrieving
799 // locally stored data.
800 scoped_ptr
<LocalDataContainer
> data_container_
;
802 #if defined(ENABLE_EXTENSIONS)
803 // The extension special storage policy; see ExtensionsProtectingNode() above.
804 scoped_refptr
<ExtensionSpecialStoragePolicy
> special_storage_policy_
;
807 // The CookiesTreeModel maintains a separate list of observers that are
808 // specifically of the type CookiesTreeModel::Observer.
809 base::ObserverList
<Observer
> cookies_observer_list_
;
811 // If true, use the CanonicalCookie::Source attribute to group cookies.
812 // Otherwise, use the CanonicalCookie::Domain attribute.
813 bool group_by_cookie_source_
;
815 // Keeps track of how many batches the consumer of this class says it is going
817 int batches_expected_
= 0;
819 // Keeps track of how many batches we've seen.
820 int batches_seen_
= 0;
822 // Counts how many batches have started already. If this is non-zero and lower
823 // than batches_ended_, then this model is still batching updates.
824 int batches_started_
= 0;
826 // Counts how many batches have finished.
827 int batches_ended_
= 0;
830 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_