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_cache_storage_helper.h"
22 #include "chrome/browser/browsing_data/browsing_data_database_helper.h"
23 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
24 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
25 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
26 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h"
27 #include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h"
28 #include "chrome/browser/browsing_data/local_data_container.h"
29 #include "components/content_settings/core/common/content_settings.h"
30 #include "net/ssl/channel_id_store.h"
31 #include "ui/base/models/tree_node_model.h"
33 class BrowsingDataChannelIDHelper
;
34 class BrowsingDataCookieHelper
;
35 class CookiesTreeModel
;
36 class CookieTreeAppCacheNode
;
37 class CookieTreeAppCachesNode
;
38 class CookieTreeCacheStorageNode
;
39 class CookieTreeCacheStoragesNode
;
40 class CookieTreeChannelIDNode
;
41 class CookieTreeChannelIDsNode
;
42 class CookieTreeCookieNode
;
43 class CookieTreeCookiesNode
;
44 class CookieTreeDatabaseNode
;
45 class CookieTreeDatabasesNode
;
46 class CookieTreeFileSystemNode
;
47 class CookieTreeFileSystemsNode
;
48 class CookieTreeFlashLSONode
;
49 class CookieTreeHostNode
;
50 class CookieTreeIndexedDBNode
;
51 class CookieTreeIndexedDBsNode
;
52 class CookieTreeLocalStorageNode
;
53 class CookieTreeLocalStoragesNode
;
54 class CookieTreeQuotaNode
;
55 class CookieTreeServiceWorkerNode
;
56 class CookieTreeServiceWorkersNode
;
57 class CookieTreeSessionStorageNode
;
58 class CookieTreeSessionStoragesNode
;
59 class ExtensionSpecialStoragePolicy
;
61 namespace content_settings
{
65 namespace extensions
{
70 class CanonicalCookie
;
73 // CookieTreeNode -------------------------------------------------------------
74 // The base node type in the Cookies, Databases, and Local Storage options
75 // view, from which all other types are derived. Specialized from TreeNode in
76 // that it has a notion of deleting objects stored in the profile, and being
77 // able to have its children do the same.
78 class CookieTreeNode
: public ui::TreeNode
<CookieTreeNode
> {
80 // Used to pull out information for the InfoView (the details display below
83 // NodeType corresponds to the various CookieTreeNode types.
86 TYPE_ROOT
, // This is used for CookieTreeRootNode nodes.
87 TYPE_HOST
, // This is used for CookieTreeHostNode nodes.
88 TYPE_COOKIES
, // This is used for CookieTreeCookiesNode nodes.
89 TYPE_COOKIE
, // This is used for CookieTreeCookieNode nodes.
90 TYPE_DATABASES
, // This is used for CookieTreeDatabasesNode.
91 TYPE_DATABASE
, // This is used for CookieTreeDatabaseNode.
92 TYPE_LOCAL_STORAGES
, // This is used for CookieTreeLocalStoragesNode.
93 TYPE_LOCAL_STORAGE
, // This is used for CookieTreeLocalStorageNode.
94 TYPE_SESSION_STORAGES
, // This is used for CookieTreeSessionStoragesNode.
95 TYPE_SESSION_STORAGE
, // This is used for CookieTreeSessionStorageNode.
96 TYPE_APPCACHES
, // This is used for CookieTreeAppCachesNode.
97 TYPE_APPCACHE
, // This is used for CookieTreeAppCacheNode.
98 TYPE_INDEXED_DBS
, // This is used for CookieTreeIndexedDBsNode.
99 TYPE_INDEXED_DB
, // This is used for CookieTreeIndexedDBNode.
100 TYPE_FILE_SYSTEMS
, // This is used for CookieTreeFileSystemsNode.
101 TYPE_FILE_SYSTEM
, // This is used for CookieTreeFileSystemNode.
102 TYPE_QUOTA
, // This is used for CookieTreeQuotaNode.
103 TYPE_CHANNEL_IDS
, // Used for CookieTreeChannelIDsNode.
104 TYPE_CHANNEL_ID
, // Used for CookieTreeChannelIDNode.
105 TYPE_SERVICE_WORKERS
, // This is used for CookieTreeServiceWorkersNode.
106 TYPE_SERVICE_WORKER
, // This is used for CookieTreeServiceWorkerNode.
107 TYPE_CACHE_STORAGES
, // This is used for CookieTreeCacheStoragesNode.
108 TYPE_CACHE_STORAGE
, // This is used for CookieTreeCacheStorageNode.
109 TYPE_FLASH_LSO
, // This is used for CookieTreeFlashLSONode.
115 DetailedInfo
& Init(NodeType type
);
116 DetailedInfo
& InitHost();
117 DetailedInfo
& InitCookie(const net::CanonicalCookie
* cookie
);
118 DetailedInfo
& InitDatabase(
119 const BrowsingDataDatabaseHelper::DatabaseInfo
* database_info
);
120 DetailedInfo
& InitLocalStorage(
121 const BrowsingDataLocalStorageHelper::LocalStorageInfo
*
123 DetailedInfo
& InitSessionStorage(
124 const BrowsingDataLocalStorageHelper::LocalStorageInfo
*
125 session_storage_info
);
126 DetailedInfo
& InitAppCache(const GURL
& origin
,
127 const content::AppCacheInfo
* appcache_info
);
128 DetailedInfo
& InitIndexedDB(
129 const content::IndexedDBInfo
* indexed_db_info
);
130 DetailedInfo
& InitFileSystem(
131 const BrowsingDataFileSystemHelper::FileSystemInfo
* file_system_info
);
132 DetailedInfo
& InitQuota(
133 const BrowsingDataQuotaHelper::QuotaInfo
* quota_info
);
134 DetailedInfo
& InitChannelID(
135 const net::ChannelIDStore::ChannelID
* channel_id
);
136 DetailedInfo
& InitServiceWorker(
137 const content::ServiceWorkerUsageInfo
* service_worker_info
);
138 DetailedInfo
& InitCacheStorage(
139 const content::CacheStorageUsageInfo
* cache_storage_info
);
140 DetailedInfo
& InitFlashLSO(const std::string
& flash_lso_domain
);
144 const net::CanonicalCookie
* cookie
= nullptr;
145 const BrowsingDataDatabaseHelper::DatabaseInfo
* database_info
= nullptr;
146 const BrowsingDataLocalStorageHelper::LocalStorageInfo
* local_storage_info
=
148 const BrowsingDataLocalStorageHelper::LocalStorageInfo
*
149 session_storage_info
= nullptr;
150 const content::AppCacheInfo
* appcache_info
= nullptr;
151 const content::IndexedDBInfo
* indexed_db_info
= nullptr;
152 const BrowsingDataFileSystemHelper::FileSystemInfo
* file_system_info
=
154 const BrowsingDataQuotaHelper::QuotaInfo
* quota_info
= nullptr;
155 const net::ChannelIDStore::ChannelID
* channel_id
= nullptr;
156 const content::ServiceWorkerUsageInfo
* service_worker_info
= nullptr;
157 const content::CacheStorageUsageInfo
* cache_storage_info
= nullptr;
158 std::string flash_lso_domain
;
162 explicit CookieTreeNode(const base::string16
& title
)
163 : ui::TreeNode
<CookieTreeNode
>(title
) {}
164 ~CookieTreeNode() override
{}
166 // Delete backend storage for this node, and any children nodes. (E.g. delete
167 // the cookie from CookieMonster, clear the database, and so forth.)
168 virtual void DeleteStoredObjects();
170 // Gets a pointer back to the associated model for the tree we are in.
171 virtual CookiesTreeModel
* GetModel() const;
173 // Returns a struct with detailed information used to populate the details
175 virtual DetailedInfo
GetDetailedInfo() const = 0;
178 void AddChildSortedByTitle(CookieTreeNode
* new_child
);
181 DISALLOW_COPY_AND_ASSIGN(CookieTreeNode
);
184 // CookieTreeRootNode ---------------------------------------------------------
185 // The node at the root of the CookieTree that gets inserted into the view.
186 class CookieTreeRootNode
: public CookieTreeNode
{
188 explicit CookieTreeRootNode(CookiesTreeModel
* model
);
189 ~CookieTreeRootNode() override
;
191 CookieTreeHostNode
* GetOrCreateHostNode(const GURL
& url
);
193 // CookieTreeNode methods:
194 CookiesTreeModel
* GetModel() const override
;
195 DetailedInfo
GetDetailedInfo() const override
;
198 CookiesTreeModel
* model_
;
200 DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode
);
203 // CookieTreeHostNode -------------------------------------------------------
204 class CookieTreeHostNode
: public CookieTreeNode
{
206 // Returns the host node's title to use for a given URL.
207 static base::string16
TitleForUrl(const GURL
& url
);
209 explicit CookieTreeHostNode(const GURL
& url
);
210 ~CookieTreeHostNode() override
;
212 // CookieTreeNode methods:
213 DetailedInfo
GetDetailedInfo() const override
;
215 // CookieTreeHostNode methods:
216 CookieTreeCookiesNode
* GetOrCreateCookiesNode();
217 CookieTreeDatabasesNode
* GetOrCreateDatabasesNode();
218 CookieTreeLocalStoragesNode
* GetOrCreateLocalStoragesNode();
219 CookieTreeSessionStoragesNode
* GetOrCreateSessionStoragesNode();
220 CookieTreeAppCachesNode
* GetOrCreateAppCachesNode();
221 CookieTreeIndexedDBsNode
* GetOrCreateIndexedDBsNode();
222 CookieTreeFileSystemsNode
* GetOrCreateFileSystemsNode();
223 CookieTreeChannelIDsNode
* GetOrCreateChannelIDsNode();
224 CookieTreeServiceWorkersNode
* GetOrCreateServiceWorkersNode();
225 CookieTreeCacheStoragesNode
* GetOrCreateCacheStoragesNode();
226 CookieTreeQuotaNode
* UpdateOrCreateQuotaNode(
227 std::list
<BrowsingDataQuotaHelper::QuotaInfo
>::iterator quota_info
);
228 CookieTreeFlashLSONode
* GetOrCreateFlashLSONode(const std::string
& domain
);
230 std::string
canonicalized_host() const { return canonicalized_host_
; }
232 // Creates an content exception for this origin of type
233 // CONTENT_SETTINGS_TYPE_COOKIES.
234 void CreateContentException(content_settings::CookieSettings
* cookie_settings
,
235 ContentSetting setting
) const;
237 // True if a content exception can be created for this origin.
238 bool CanCreateContentException() const;
240 const std::string
GetHost() const;
243 // Pointers to the cookies, databases, local and session storage and appcache
244 // nodes. When we build up the tree we need to quickly get a reference to
245 // the COOKIES node to add children. Checking each child and interrogating
246 // them to see if they are a COOKIES, APPCACHES, DATABASES etc node seems
247 // less preferable than storing an extra pointer per origin.
248 CookieTreeCookiesNode
* cookies_child_
= nullptr;
249 CookieTreeDatabasesNode
* databases_child_
= nullptr;
250 CookieTreeLocalStoragesNode
* local_storages_child_
= nullptr;
251 CookieTreeSessionStoragesNode
* session_storages_child_
= nullptr;
252 CookieTreeAppCachesNode
* appcaches_child_
= nullptr;
253 CookieTreeIndexedDBsNode
* indexed_dbs_child_
= nullptr;
254 CookieTreeFileSystemsNode
* file_systems_child_
= nullptr;
255 CookieTreeQuotaNode
* quota_child_
= nullptr;
256 CookieTreeChannelIDsNode
* channel_ids_child_
= nullptr;
257 CookieTreeServiceWorkersNode
* service_workers_child_
= nullptr;
258 CookieTreeCacheStoragesNode
* cache_storages_child_
= nullptr;
259 CookieTreeFlashLSONode
* flash_lso_child_
= nullptr;
261 // The URL for which this node was initially created.
264 std::string canonicalized_host_
;
266 DISALLOW_COPY_AND_ASSIGN(CookieTreeHostNode
);
269 // CookieTreeCookieNode ------------------------------------------------------
270 class CookieTreeCookieNode
: public CookieTreeNode
{
272 friend class CookieTreeCookiesNode
;
274 // The cookie should remain valid at least as long as the
275 // CookieTreeCookieNode is valid.
276 explicit CookieTreeCookieNode(
277 std::list
<net::CanonicalCookie
>::iterator cookie
);
278 ~CookieTreeCookieNode() override
;
280 // CookieTreeNode methods:
281 void DeleteStoredObjects() override
;
282 DetailedInfo
GetDetailedInfo() const override
;
285 // cookie_ is expected to remain valid as long as the CookieTreeCookieNode is
287 std::list
<net::CanonicalCookie
>::iterator cookie_
;
289 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode
);
292 class CookieTreeCookiesNode
: public CookieTreeNode
{
294 CookieTreeCookiesNode();
295 ~CookieTreeCookiesNode() override
;
297 DetailedInfo
GetDetailedInfo() const override
;
299 void AddCookieNode(CookieTreeCookieNode
* child
) {
300 AddChildSortedByTitle(child
);
304 DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode
);
307 // CookieTreeAppCacheNode -----------------------------------------------------
308 class CookieTreeAppCacheNode
: public CookieTreeNode
{
310 friend class CookieTreeAppCachesNode
;
312 // appcache_info should remain valid at least as long as the
313 // CookieTreeAppCacheNode is valid.
314 explicit CookieTreeAppCacheNode(
315 const GURL
& origin_url
,
316 std::list
<content::AppCacheInfo
>::iterator appcache_info
);
317 ~CookieTreeAppCacheNode() override
;
319 void DeleteStoredObjects() override
;
320 DetailedInfo
GetDetailedInfo() const override
;
324 std::list
<content::AppCacheInfo
>::iterator appcache_info_
;
325 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCacheNode
);
328 class CookieTreeAppCachesNode
: public CookieTreeNode
{
330 CookieTreeAppCachesNode();
331 ~CookieTreeAppCachesNode() override
;
333 DetailedInfo
GetDetailedInfo() const override
;
335 void AddAppCacheNode(CookieTreeAppCacheNode
* child
) {
336 AddChildSortedByTitle(child
);
340 DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCachesNode
);
343 // CookieTreeDatabaseNode -----------------------------------------------------
344 class CookieTreeDatabaseNode
: public CookieTreeNode
{
346 friend class CookieTreeDatabasesNode
;
348 // database_info should remain valid at least as long as the
349 // CookieTreeDatabaseNode is valid.
350 explicit CookieTreeDatabaseNode(
351 std::list
<BrowsingDataDatabaseHelper::DatabaseInfo
>::iterator
353 ~CookieTreeDatabaseNode() override
;
355 void DeleteStoredObjects() override
;
356 DetailedInfo
GetDetailedInfo() const override
;
359 // database_info_ is expected to remain valid as long as the
360 // CookieTreeDatabaseNode is valid.
361 std::list
<BrowsingDataDatabaseHelper::DatabaseInfo
>::iterator
364 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabaseNode
);
367 class CookieTreeDatabasesNode
: public CookieTreeNode
{
369 CookieTreeDatabasesNode();
370 ~CookieTreeDatabasesNode() override
;
372 DetailedInfo
GetDetailedInfo() const override
;
374 void AddDatabaseNode(CookieTreeDatabaseNode
* child
) {
375 AddChildSortedByTitle(child
);
379 DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabasesNode
);
382 // CookieTreeFileSystemNode --------------------------------------------------
383 class CookieTreeFileSystemNode
: public CookieTreeNode
{
385 friend class CookieTreeFileSystemsNode
;
387 // file_system_info should remain valid at least as long as the
388 // CookieTreeFileSystemNode is valid.
389 explicit CookieTreeFileSystemNode(
390 std::list
<BrowsingDataFileSystemHelper::FileSystemInfo
>::iterator
392 ~CookieTreeFileSystemNode() override
;
394 void DeleteStoredObjects() override
;
395 DetailedInfo
GetDetailedInfo() const override
;
398 // file_system_info_ expected to remain valid as long as the
399 // CookieTreeFileSystemNode is valid.
400 std::list
<BrowsingDataFileSystemHelper::FileSystemInfo
>::iterator
403 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemNode
);
406 class CookieTreeFileSystemsNode
: public CookieTreeNode
{
408 CookieTreeFileSystemsNode();
409 ~CookieTreeFileSystemsNode() override
;
411 DetailedInfo
GetDetailedInfo() const override
;
413 void AddFileSystemNode(CookieTreeFileSystemNode
* child
) {
414 AddChildSortedByTitle(child
);
418 DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemsNode
);
421 // CookieTreeLocalStorageNode -------------------------------------------------
422 class CookieTreeLocalStorageNode
: public CookieTreeNode
{
424 // local_storage_info should remain valid at least as long as the
425 // CookieTreeLocalStorageNode is valid.
426 explicit CookieTreeLocalStorageNode(
427 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
429 ~CookieTreeLocalStorageNode() override
;
431 // CookieTreeNode methods:
432 void DeleteStoredObjects() override
;
433 DetailedInfo
GetDetailedInfo() const override
;
436 // local_storage_info_ is expected to remain valid as long as the
437 // CookieTreeLocalStorageNode is valid.
438 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
441 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode
);
444 class CookieTreeLocalStoragesNode
: public CookieTreeNode
{
446 CookieTreeLocalStoragesNode();
447 ~CookieTreeLocalStoragesNode() override
;
449 DetailedInfo
GetDetailedInfo() const override
;
451 void AddLocalStorageNode(CookieTreeLocalStorageNode
* child
) {
452 AddChildSortedByTitle(child
);
456 DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode
);
460 // CookieTreeSessionStorageNode -----------------------------------------------
461 class CookieTreeSessionStorageNode
: public CookieTreeNode
{
463 // session_storage_info should remain valid at least as long as the
464 // CookieTreeSessionStorageNode is valid.
465 explicit CookieTreeSessionStorageNode(
466 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
467 session_storage_info
);
468 ~CookieTreeSessionStorageNode() override
;
470 // CookieTreeNode methods:
471 void DeleteStoredObjects() override
;
472 DetailedInfo
GetDetailedInfo() const override
;
475 // session_storage_info_ is expected to remain valid as long as the
476 // CookieTreeSessionStorageNode is valid.
477 std::list
<BrowsingDataLocalStorageHelper::LocalStorageInfo
>::iterator
478 session_storage_info_
;
480 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStorageNode
);
483 class CookieTreeSessionStoragesNode
: public CookieTreeNode
{
485 CookieTreeSessionStoragesNode();
486 ~CookieTreeSessionStoragesNode() override
;
488 DetailedInfo
GetDetailedInfo() const override
;
490 void AddSessionStorageNode(CookieTreeSessionStorageNode
* child
) {
491 AddChildSortedByTitle(child
);
495 DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStoragesNode
);
498 // CookieTreeIndexedDBNode -----------------------------------------------
499 class CookieTreeIndexedDBNode
: public CookieTreeNode
{
501 // indexed_db_info should remain valid at least as long as the
502 // CookieTreeIndexedDBNode is valid.
503 explicit CookieTreeIndexedDBNode(
504 std::list
<content::IndexedDBInfo
>::iterator
506 ~CookieTreeIndexedDBNode() override
;
508 // CookieTreeNode methods:
509 void DeleteStoredObjects() override
;
510 DetailedInfo
GetDetailedInfo() const override
;
513 // indexed_db_info_ is expected to remain valid as long as the
514 // CookieTreeIndexedDBNode is valid.
515 std::list
<content::IndexedDBInfo
>::iterator
518 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBNode
);
521 class CookieTreeIndexedDBsNode
: public CookieTreeNode
{
523 CookieTreeIndexedDBsNode();
524 ~CookieTreeIndexedDBsNode() override
;
526 DetailedInfo
GetDetailedInfo() const override
;
528 void AddIndexedDBNode(CookieTreeIndexedDBNode
* child
) {
529 AddChildSortedByTitle(child
);
533 DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBsNode
);
536 // CookieTreeQuotaNode --------------------------------------------------
537 class CookieTreeQuotaNode
: public CookieTreeNode
{
539 // quota_info should remain valid at least as long as the CookieTreeQuotaNode
541 explicit CookieTreeQuotaNode(
542 std::list
<BrowsingDataQuotaHelper::QuotaInfo
>::iterator quota_info
);
543 ~CookieTreeQuotaNode() override
;
545 void DeleteStoredObjects() override
;
546 DetailedInfo
GetDetailedInfo() const override
;
549 // quota_info_ is expected to remain valid as long as the CookieTreeQuotaNode
551 std::list
<BrowsingDataQuotaHelper::QuotaInfo
>::iterator quota_info_
;
553 DISALLOW_COPY_AND_ASSIGN(CookieTreeQuotaNode
);
556 // CookieTreeChannelIDNode ---------------------------------------------
557 class CookieTreeChannelIDNode
: public CookieTreeNode
{
559 friend class CookieTreeChannelIDsNode
;
561 // The iterator should remain valid at least as long as the
562 // CookieTreeChannelIDNode is valid.
563 explicit CookieTreeChannelIDNode(
564 net::ChannelIDStore::ChannelIDList::iterator cert
);
565 ~CookieTreeChannelIDNode() override
;
567 // CookieTreeNode methods:
568 void DeleteStoredObjects() override
;
569 DetailedInfo
GetDetailedInfo() const override
;
572 // channel_id_ is expected to remain valid as long as the
573 // CookieTreeChannelIDNode is valid.
574 net::ChannelIDStore::ChannelIDList::iterator channel_id_
;
576 DISALLOW_COPY_AND_ASSIGN(CookieTreeChannelIDNode
);
579 class CookieTreeChannelIDsNode
: public CookieTreeNode
{
581 CookieTreeChannelIDsNode();
582 ~CookieTreeChannelIDsNode() override
;
584 DetailedInfo
GetDetailedInfo() const override
;
586 void AddChannelIDNode(CookieTreeChannelIDNode
* child
) {
587 AddChildSortedByTitle(child
);
591 DISALLOW_COPY_AND_ASSIGN(CookieTreeChannelIDsNode
);
594 // CookieTreeServiceWorkerNode -----------------------------------------------
595 class CookieTreeServiceWorkerNode
: public CookieTreeNode
{
597 // service_worker_info should remain valid at least as long as the
598 // CookieTreeServiceWorkerNode is valid.
599 explicit CookieTreeServiceWorkerNode(
600 std::list
<content::ServiceWorkerUsageInfo
>::iterator service_worker_info
);
601 ~CookieTreeServiceWorkerNode() override
;
603 // CookieTreeNode methods:
604 void DeleteStoredObjects() override
;
605 DetailedInfo
GetDetailedInfo() const override
;
608 // service_worker_info_ is expected to remain valid as long as the
609 // CookieTreeServiceWorkerNode is valid.
610 std::list
<content::ServiceWorkerUsageInfo
>::iterator service_worker_info_
;
612 DISALLOW_COPY_AND_ASSIGN(CookieTreeServiceWorkerNode
);
615 class CookieTreeServiceWorkersNode
: public CookieTreeNode
{
617 CookieTreeServiceWorkersNode();
618 ~CookieTreeServiceWorkersNode() override
;
620 DetailedInfo
GetDetailedInfo() const override
;
622 void AddServiceWorkerNode(CookieTreeServiceWorkerNode
* child
) {
623 AddChildSortedByTitle(child
);
627 DISALLOW_COPY_AND_ASSIGN(CookieTreeServiceWorkersNode
);
630 // CookieTreeCacheStorageNode -----------------------------------------------
631 class CookieTreeCacheStorageNode
: public CookieTreeNode
{
633 // cache_storage_info should remain valid at least as long as the
634 // CookieTreeCacheStorageNode is valid.
635 explicit CookieTreeCacheStorageNode(
636 std::list
<content::CacheStorageUsageInfo
>::iterator cache_storage_info
);
637 ~CookieTreeCacheStorageNode() override
;
639 // CookieTreeNode methods:
640 void DeleteStoredObjects() override
;
641 DetailedInfo
GetDetailedInfo() const override
;
644 // cache_storage_info_ is expected to remain valid as long as the
645 // CookieTreeCacheStorageNode is valid.
646 std::list
<content::CacheStorageUsageInfo
>::iterator cache_storage_info_
;
648 DISALLOW_COPY_AND_ASSIGN(CookieTreeCacheStorageNode
);
651 class CookieTreeCacheStoragesNode
: public CookieTreeNode
{
653 CookieTreeCacheStoragesNode();
654 ~CookieTreeCacheStoragesNode() override
;
656 DetailedInfo
GetDetailedInfo() const override
;
658 void AddCacheStorageNode(CookieTreeCacheStorageNode
* child
) {
659 AddChildSortedByTitle(child
);
663 DISALLOW_COPY_AND_ASSIGN(CookieTreeCacheStoragesNode
);
666 // CookieTreeFlashLSONode ----------------------------------------------------
667 class CookieTreeFlashLSONode
: public CookieTreeNode
{
669 explicit CookieTreeFlashLSONode(const std::string
& domain
);
670 ~CookieTreeFlashLSONode() override
;
672 // CookieTreeNode methods:
673 void DeleteStoredObjects() override
;
674 DetailedInfo
GetDetailedInfo() const override
;
679 DISALLOW_COPY_AND_ASSIGN(CookieTreeFlashLSONode
);
682 // CookiesTreeModel -----------------------------------------------------------
683 class CookiesTreeModel
: public ui::TreeNodeModel
<CookieTreeNode
> {
685 CookiesTreeModel(LocalDataContainer
* data_container
,
686 ExtensionSpecialStoragePolicy
* special_storage_policy
,
687 bool group_by_cookie_source
);
688 ~CookiesTreeModel() override
;
690 // Given a CanonicalCookie, return the ID of the message which should be
691 // displayed in various ports' "Send for:" UI.
692 static int GetSendForMessageID(const net::CanonicalCookie
& cookie
);
694 // Because non-cookie nodes are fetched in a background thread, they are not
695 // present at the time the Model is created. The Model then notifies its
696 // observers for every item added from databases, local storage, and
697 // appcache. We extend the Observer interface to add notifications before and
698 // after these batch inserts.
699 class Observer
: public ui::TreeModelObserver
{
701 virtual void TreeModelBeginBatch(CookiesTreeModel
* model
) {}
702 virtual void TreeModelEndBatch(CookiesTreeModel
* model
) {}
705 // This class defines the scope for batch updates. It can be created as a
706 // local variable and the destructor will terminate the batch update, if one
708 class ScopedBatchUpdateNotifier
{
710 ScopedBatchUpdateNotifier(CookiesTreeModel
* model
,
711 CookieTreeNode
* node
);
712 ~ScopedBatchUpdateNotifier();
714 void StartBatchUpdate();
717 CookiesTreeModel
* model_
;
718 CookieTreeNode
* node_
;
719 bool batch_in_progress_
= false;
722 // ui::TreeModel methods:
723 // Returns the set of icons for the nodes in the tree. You only need override
724 // this if you don't want to use the default folder icons.
725 void GetIcons(std::vector
<gfx::ImageSkia
>* icons
) override
;
727 // Returns the index of the icon to use for |node|. Return -1 to use the
728 // default icon. The index is relative to the list of icons returned from
730 int GetIconIndex(ui::TreeModelNode
* node
) override
;
732 // CookiesTreeModel methods:
733 void DeleteAllStoredObjects();
735 // Deletes a specific node in the tree, identified by |cookie_node|, and its
737 void DeleteCookieNode(CookieTreeNode
* cookie_node
);
739 // Filter the origins to only display matched results.
740 void UpdateSearchResults(const base::string16
& filter
);
742 #if defined(ENABLE_EXTENSIONS)
743 // Returns the set of extensions which protect the data item represented by
744 // this node from deletion.
745 // Returns nullptr if the node doesn't represent a protected data item or the
746 // special storage policy is nullptr.
747 const extensions::ExtensionSet
* ExtensionsProtectingNode(
748 const CookieTreeNode
& cookie_node
);
751 // Manages CookiesTreeModel::Observers. This will also call
752 // TreeNodeModel::AddObserver so that it gets all the proper notifications.
753 // Note that the converse is not true: simply adding a TreeModelObserver will
754 // not get CookiesTreeModel::Observer notifications.
755 virtual void AddCookiesTreeObserver(Observer
* observer
);
756 virtual void RemoveCookiesTreeObserver(Observer
* observer
);
758 // Methods that update the model based on the data retrieved by the browsing
760 void PopulateAppCacheInfo(LocalDataContainer
* container
);
761 void PopulateCookieInfo(LocalDataContainer
* container
);
762 void PopulateDatabaseInfo(LocalDataContainer
* container
);
763 void PopulateLocalStorageInfo(LocalDataContainer
* container
);
764 void PopulateSessionStorageInfo(LocalDataContainer
* container
);
765 void PopulateIndexedDBInfo(LocalDataContainer
* container
);
766 void PopulateFileSystemInfo(LocalDataContainer
* container
);
767 void PopulateQuotaInfo(LocalDataContainer
* container
);
768 void PopulateChannelIDInfo(LocalDataContainer
* container
);
769 void PopulateServiceWorkerUsageInfo(LocalDataContainer
* container
);
770 void PopulateCacheStorageUsageInfo(LocalDataContainer
* container
);
771 void PopulateFlashLSOInfo(LocalDataContainer
* container
);
773 BrowsingDataCookieHelper
* GetCookieHelper(const std::string
& app_id
);
774 LocalDataContainer
* data_container() {
775 return data_container_
.get();
778 // Set the number of |batches_expected| this class should expect to receive.
779 // If |reset| is true, then this is a new set of batches, but if false, then
780 // this is a revised number (batches originally counted should no longer be
782 void SetBatchExpectation(int batches_expected
, bool reset
);
785 enum CookieIconIndex
{
791 // Reset the counters for batches.
794 // Record that one batch has been delivered.
795 void RecordBatchSeen();
797 // Record that one batch has begun processing. If this is the first batch then
798 // observers will be notified that batch processing has started.
799 void NotifyObserverBeginBatch();
801 // Record that one batch has finished processing. If this is the last batch
802 // then observers will be notified that batch processing has ended.
803 void NotifyObserverEndBatch();
805 // Notifies observers if expected batch count has been delievered and all
806 // batches have finished processing.
807 void MaybeNotifyBatchesEnded();
809 void PopulateAppCacheInfoWithFilter(LocalDataContainer
* container
,
810 ScopedBatchUpdateNotifier
* notifier
,
811 const base::string16
& filter
);
812 void PopulateCookieInfoWithFilter(LocalDataContainer
* container
,
813 ScopedBatchUpdateNotifier
* notifier
,
814 const base::string16
& filter
);
815 void PopulateDatabaseInfoWithFilter(LocalDataContainer
* container
,
816 ScopedBatchUpdateNotifier
* notifier
,
817 const base::string16
& filter
);
818 void PopulateLocalStorageInfoWithFilter(LocalDataContainer
* container
,
819 ScopedBatchUpdateNotifier
* notifier
,
820 const base::string16
& filter
);
821 void PopulateSessionStorageInfoWithFilter(LocalDataContainer
* container
,
822 ScopedBatchUpdateNotifier
* notifier
,
823 const base::string16
& filter
);
824 void PopulateIndexedDBInfoWithFilter(LocalDataContainer
* container
,
825 ScopedBatchUpdateNotifier
* notifier
,
826 const base::string16
& filter
);
827 void PopulateFileSystemInfoWithFilter(LocalDataContainer
* container
,
828 ScopedBatchUpdateNotifier
* notifier
,
829 const base::string16
& filter
);
830 void PopulateQuotaInfoWithFilter(LocalDataContainer
* container
,
831 ScopedBatchUpdateNotifier
* notifier
,
832 const base::string16
& filter
);
833 void PopulateChannelIDInfoWithFilter(
834 LocalDataContainer
* container
,
835 ScopedBatchUpdateNotifier
* notifier
,
836 const base::string16
& filter
);
837 void PopulateServiceWorkerUsageInfoWithFilter(
838 LocalDataContainer
* container
,
839 ScopedBatchUpdateNotifier
* notifier
,
840 const base::string16
& filter
);
841 void PopulateCacheStorageUsageInfoWithFilter(
842 LocalDataContainer
* container
,
843 ScopedBatchUpdateNotifier
* notifier
,
844 const base::string16
& filter
);
845 void PopulateFlashLSOInfoWithFilter(LocalDataContainer
* container
,
846 ScopedBatchUpdateNotifier
* notifier
,
847 const base::string16
& filter
);
849 // Map of app ids to LocalDataContainer objects to use when retrieving
850 // locally stored data.
851 scoped_ptr
<LocalDataContainer
> data_container_
;
853 #if defined(ENABLE_EXTENSIONS)
854 // The extension special storage policy; see ExtensionsProtectingNode() above.
855 scoped_refptr
<ExtensionSpecialStoragePolicy
> special_storage_policy_
;
858 // The CookiesTreeModel maintains a separate list of observers that are
859 // specifically of the type CookiesTreeModel::Observer.
860 base::ObserverList
<Observer
> cookies_observer_list_
;
862 // If true, use the CanonicalCookie::Source attribute to group cookies.
863 // Otherwise, use the CanonicalCookie::Domain attribute.
864 bool group_by_cookie_source_
;
866 // Keeps track of how many batches the consumer of this class says it is going
868 int batches_expected_
= 0;
870 // Keeps track of how many batches we've seen.
871 int batches_seen_
= 0;
873 // Counts how many batches have started already. If this is non-zero and lower
874 // than batches_ended_, then this model is still batching updates.
875 int batches_started_
= 0;
877 // Counts how many batches have finished.
878 int batches_ended_
= 0;
881 #endif // CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_