OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 5 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: | 131 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: |
132 return true; | 132 return true; |
133 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: | 133 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: |
134 return true; | 134 return true; |
135 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: | 135 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: |
136 return false; | 136 return false; |
137 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: | 137 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: |
138 return false; | 138 return false; |
139 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: | 139 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: |
140 return true; | 140 return true; |
| 141 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: |
| 142 return true; |
141 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: | 143 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: |
142 return false; | 144 return false; |
143 default: | 145 default: |
144 break; | 146 break; |
145 } | 147 } |
146 return false; | 148 return false; |
147 } | 149 } |
148 #endif | 150 #endif |
149 | 151 |
150 // This function returns the local data container associated with a leaf tree | 152 // This function returns the local data container associated with a leaf tree |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 252 } |
251 | 253 |
252 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitServiceWorker( | 254 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitServiceWorker( |
253 const content::ServiceWorkerUsageInfo* service_worker_info) { | 255 const content::ServiceWorkerUsageInfo* service_worker_info) { |
254 Init(TYPE_SERVICE_WORKER); | 256 Init(TYPE_SERVICE_WORKER); |
255 this->service_worker_info = service_worker_info; | 257 this->service_worker_info = service_worker_info; |
256 this->origin = service_worker_info->origin; | 258 this->origin = service_worker_info->origin; |
257 return *this; | 259 return *this; |
258 } | 260 } |
259 | 261 |
| 262 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitCacheStorage( |
| 263 const content::CacheStorageUsageInfo* cache_storage_info) { |
| 264 Init(TYPE_CACHE_STORAGE); |
| 265 this->cache_storage_info = cache_storage_info; |
| 266 this->origin = cache_storage_info->origin; |
| 267 return *this; |
| 268 } |
| 269 |
260 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitFlashLSO( | 270 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitFlashLSO( |
261 const std::string& flash_lso_domain) { | 271 const std::string& flash_lso_domain) { |
262 Init(TYPE_FLASH_LSO); | 272 Init(TYPE_FLASH_LSO); |
263 this->flash_lso_domain = flash_lso_domain; | 273 this->flash_lso_domain = flash_lso_domain; |
264 return *this; | 274 return *this; |
265 } | 275 } |
266 | 276 |
267 /////////////////////////////////////////////////////////////////////////////// | 277 /////////////////////////////////////////////////////////////////////////////// |
268 // CookieTreeNode, public: | 278 // CookieTreeNode, public: |
269 | 279 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 container->service_worker_info_list_.erase(service_worker_info_); | 552 container->service_worker_info_list_.erase(service_worker_info_); |
543 } | 553 } |
544 } | 554 } |
545 | 555 |
546 CookieTreeNode::DetailedInfo CookieTreeServiceWorkerNode::GetDetailedInfo() | 556 CookieTreeNode::DetailedInfo CookieTreeServiceWorkerNode::GetDetailedInfo() |
547 const { | 557 const { |
548 return DetailedInfo().InitServiceWorker(&*service_worker_info_); | 558 return DetailedInfo().InitServiceWorker(&*service_worker_info_); |
549 } | 559 } |
550 | 560 |
551 /////////////////////////////////////////////////////////////////////////////// | 561 /////////////////////////////////////////////////////////////////////////////// |
| 562 // CookieTreeCacheStorageNode, public: |
| 563 |
| 564 CookieTreeCacheStorageNode::CookieTreeCacheStorageNode( |
| 565 std::list<content::CacheStorageUsageInfo>::iterator cache_storage_info) |
| 566 : CookieTreeNode(base::UTF8ToUTF16(cache_storage_info->origin.spec())), |
| 567 cache_storage_info_(cache_storage_info) {} |
| 568 |
| 569 CookieTreeCacheStorageNode::~CookieTreeCacheStorageNode() {} |
| 570 |
| 571 void CookieTreeCacheStorageNode::DeleteStoredObjects() { |
| 572 LocalDataContainer* container = GetLocalDataContainerForNode(this); |
| 573 |
| 574 if (container) { |
| 575 container->cache_storage_helper_->DeleteCacheStorage( |
| 576 cache_storage_info_->origin); |
| 577 container->cache_storage_info_list_.erase(cache_storage_info_); |
| 578 } |
| 579 } |
| 580 |
| 581 CookieTreeNode::DetailedInfo CookieTreeCacheStorageNode::GetDetailedInfo() |
| 582 const { |
| 583 return DetailedInfo().InitCacheStorage(&*cache_storage_info_); |
| 584 } |
| 585 |
| 586 /////////////////////////////////////////////////////////////////////////////// |
552 // CookieTreeRootNode, public: | 587 // CookieTreeRootNode, public: |
553 | 588 |
554 CookieTreeRootNode::CookieTreeRootNode(CookiesTreeModel* model) | 589 CookieTreeRootNode::CookieTreeRootNode(CookiesTreeModel* model) |
555 : model_(model) { | 590 : model_(model) { |
556 } | 591 } |
557 | 592 |
558 CookieTreeRootNode::~CookieTreeRootNode() {} | 593 CookieTreeRootNode::~CookieTreeRootNode() {} |
559 | 594 |
560 CookieTreeHostNode* CookieTreeRootNode::GetOrCreateHostNode( | 595 CookieTreeHostNode* CookieTreeRootNode::GetOrCreateHostNode( |
561 const GURL& url) { | 596 const GURL& url) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 | 726 |
692 CookieTreeServiceWorkersNode* | 727 CookieTreeServiceWorkersNode* |
693 CookieTreeHostNode::GetOrCreateServiceWorkersNode() { | 728 CookieTreeHostNode::GetOrCreateServiceWorkersNode() { |
694 if (service_workers_child_) | 729 if (service_workers_child_) |
695 return service_workers_child_; | 730 return service_workers_child_; |
696 service_workers_child_ = new CookieTreeServiceWorkersNode; | 731 service_workers_child_ = new CookieTreeServiceWorkersNode; |
697 AddChildSortedByTitle(service_workers_child_); | 732 AddChildSortedByTitle(service_workers_child_); |
698 return service_workers_child_; | 733 return service_workers_child_; |
699 } | 734 } |
700 | 735 |
| 736 CookieTreeCacheStoragesNode* |
| 737 CookieTreeHostNode::GetOrCreateCacheStoragesNode() { |
| 738 if (cache_storages_child_) |
| 739 return cache_storages_child_; |
| 740 cache_storages_child_ = new CookieTreeCacheStoragesNode; |
| 741 AddChildSortedByTitle(cache_storages_child_); |
| 742 return cache_storages_child_; |
| 743 } |
| 744 |
701 CookieTreeFlashLSONode* CookieTreeHostNode::GetOrCreateFlashLSONode( | 745 CookieTreeFlashLSONode* CookieTreeHostNode::GetOrCreateFlashLSONode( |
702 const std::string& domain) { | 746 const std::string& domain) { |
703 DCHECK_EQ(GetHost(), domain); | 747 DCHECK_EQ(GetHost(), domain); |
704 if (flash_lso_child_) | 748 if (flash_lso_child_) |
705 return flash_lso_child_; | 749 return flash_lso_child_; |
706 flash_lso_child_ = new CookieTreeFlashLSONode(domain); | 750 flash_lso_child_ = new CookieTreeFlashLSONode(domain); |
707 AddChildSortedByTitle(flash_lso_child_); | 751 AddChildSortedByTitle(flash_lso_child_); |
708 return flash_lso_child_; | 752 return flash_lso_child_; |
709 } | 753 } |
710 | 754 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 | 901 |
858 CookieTreeServiceWorkersNode::~CookieTreeServiceWorkersNode() { | 902 CookieTreeServiceWorkersNode::~CookieTreeServiceWorkersNode() { |
859 } | 903 } |
860 | 904 |
861 CookieTreeNode::DetailedInfo CookieTreeServiceWorkersNode::GetDetailedInfo() | 905 CookieTreeNode::DetailedInfo CookieTreeServiceWorkersNode::GetDetailedInfo() |
862 const { | 906 const { |
863 return DetailedInfo().Init(DetailedInfo::TYPE_SERVICE_WORKERS); | 907 return DetailedInfo().Init(DetailedInfo::TYPE_SERVICE_WORKERS); |
864 } | 908 } |
865 | 909 |
866 /////////////////////////////////////////////////////////////////////////////// | 910 /////////////////////////////////////////////////////////////////////////////// |
| 911 // CookieTreeCacheStoragesNode, public: |
| 912 |
| 913 CookieTreeCacheStoragesNode::CookieTreeCacheStoragesNode() |
| 914 : CookieTreeNode(l10n_util::GetStringUTF16(IDS_COOKIES_CACHE_STORAGE)) {} |
| 915 |
| 916 CookieTreeCacheStoragesNode::~CookieTreeCacheStoragesNode() {} |
| 917 |
| 918 CookieTreeNode::DetailedInfo CookieTreeCacheStoragesNode::GetDetailedInfo() |
| 919 const { |
| 920 return DetailedInfo().Init(DetailedInfo::TYPE_CACHE_STORAGES); |
| 921 } |
| 922 |
| 923 /////////////////////////////////////////////////////////////////////////////// |
867 // CookieTreeFlashLSONode | 924 // CookieTreeFlashLSONode |
868 CookieTreeFlashLSONode::CookieTreeFlashLSONode( | 925 CookieTreeFlashLSONode::CookieTreeFlashLSONode( |
869 const std::string& domain) | 926 const std::string& domain) |
870 : domain_(domain) {} | 927 : domain_(domain) {} |
871 CookieTreeFlashLSONode::~CookieTreeFlashLSONode() {} | 928 CookieTreeFlashLSONode::~CookieTreeFlashLSONode() {} |
872 | 929 |
873 void CookieTreeFlashLSONode::DeleteStoredObjects() { | 930 void CookieTreeFlashLSONode::DeleteStoredObjects() { |
874 // We are one level below the host node. | 931 // We are one level below the host node. |
875 CookieTreeHostNode* host = static_cast<CookieTreeHostNode*>(parent()); | 932 CookieTreeHostNode* host = static_cast<CookieTreeHostNode*>(parent()); |
876 CHECK_EQ(host->GetDetailedInfo().node_type, | 933 CHECK_EQ(host->GetDetailedInfo().node_type, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: | 1033 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: |
977 return DATABASE; // ditto | 1034 return DATABASE; // ditto |
978 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: | 1035 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: |
979 return DATABASE; // ditto | 1036 return DATABASE; // ditto |
980 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: | 1037 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: |
981 return -1; | 1038 return -1; |
982 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: | 1039 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: |
983 return COOKIE; // It's kinda like a cookie? | 1040 return COOKIE; // It's kinda like a cookie? |
984 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: | 1041 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: |
985 return DATABASE; // Just like appcache | 1042 return DATABASE; // Just like appcache |
| 1043 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: |
| 1044 return DATABASE; // ditto |
986 default: | 1045 default: |
987 break; | 1046 break; |
988 } | 1047 } |
989 return -1; | 1048 return -1; |
990 } | 1049 } |
991 | 1050 |
992 void CookiesTreeModel::DeleteAllStoredObjects() { | 1051 void CookiesTreeModel::DeleteAllStoredObjects() { |
993 NotifyObserverBeginBatch(); | 1052 NotifyObserverBeginBatch(); |
994 CookieTreeNode* root = GetRoot(); | 1053 CookieTreeNode* root = GetRoot(); |
995 root->DeleteStoredObjects(); | 1054 root->DeleteStoredObjects(); |
(...skipping 26 matching lines...) Expand all Loading... |
1022 PopulateCookieInfoWithFilter(data_container(), ¬ifier, filter); | 1081 PopulateCookieInfoWithFilter(data_container(), ¬ifier, filter); |
1023 PopulateDatabaseInfoWithFilter(data_container(), ¬ifier, filter); | 1082 PopulateDatabaseInfoWithFilter(data_container(), ¬ifier, filter); |
1024 PopulateLocalStorageInfoWithFilter(data_container(), ¬ifier, filter); | 1083 PopulateLocalStorageInfoWithFilter(data_container(), ¬ifier, filter); |
1025 PopulateSessionStorageInfoWithFilter(data_container(), ¬ifier, filter); | 1084 PopulateSessionStorageInfoWithFilter(data_container(), ¬ifier, filter); |
1026 PopulateAppCacheInfoWithFilter(data_container(), ¬ifier, filter); | 1085 PopulateAppCacheInfoWithFilter(data_container(), ¬ifier, filter); |
1027 PopulateIndexedDBInfoWithFilter(data_container(), ¬ifier, filter); | 1086 PopulateIndexedDBInfoWithFilter(data_container(), ¬ifier, filter); |
1028 PopulateFileSystemInfoWithFilter(data_container(), ¬ifier, filter); | 1087 PopulateFileSystemInfoWithFilter(data_container(), ¬ifier, filter); |
1029 PopulateQuotaInfoWithFilter(data_container(), ¬ifier, filter); | 1088 PopulateQuotaInfoWithFilter(data_container(), ¬ifier, filter); |
1030 PopulateChannelIDInfoWithFilter(data_container(), ¬ifier, filter); | 1089 PopulateChannelIDInfoWithFilter(data_container(), ¬ifier, filter); |
1031 PopulateServiceWorkerUsageInfoWithFilter(data_container(), ¬ifier, filter); | 1090 PopulateServiceWorkerUsageInfoWithFilter(data_container(), ¬ifier, filter); |
| 1091 PopulateCacheStorageUsageInfoWithFilter(data_container(), ¬ifier, filter); |
1032 } | 1092 } |
1033 | 1093 |
1034 #if defined(ENABLE_EXTENSIONS) | 1094 #if defined(ENABLE_EXTENSIONS) |
1035 const extensions::ExtensionSet* CookiesTreeModel::ExtensionsProtectingNode( | 1095 const extensions::ExtensionSet* CookiesTreeModel::ExtensionsProtectingNode( |
1036 const CookieTreeNode& cookie_node) { | 1096 const CookieTreeNode& cookie_node) { |
1037 if (!special_storage_policy_.get()) | 1097 if (!special_storage_policy_.get()) |
1038 return nullptr; | 1098 return nullptr; |
1039 | 1099 |
1040 CookieTreeNode::DetailedInfo info = cookie_node.GetDetailedInfo(); | 1100 CookieTreeNode::DetailedInfo info = cookie_node.GetDetailedInfo(); |
1041 | 1101 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 PopulateChannelIDInfoWithFilter(container, ¬ifier, base::string16()); | 1166 PopulateChannelIDInfoWithFilter(container, ¬ifier, base::string16()); |
1107 } | 1167 } |
1108 | 1168 |
1109 void CookiesTreeModel::PopulateServiceWorkerUsageInfo( | 1169 void CookiesTreeModel::PopulateServiceWorkerUsageInfo( |
1110 LocalDataContainer* container) { | 1170 LocalDataContainer* container) { |
1111 ScopedBatchUpdateNotifier notifier(this, GetRoot()); | 1171 ScopedBatchUpdateNotifier notifier(this, GetRoot()); |
1112 PopulateServiceWorkerUsageInfoWithFilter( | 1172 PopulateServiceWorkerUsageInfoWithFilter( |
1113 container, ¬ifier, base::string16()); | 1173 container, ¬ifier, base::string16()); |
1114 } | 1174 } |
1115 | 1175 |
| 1176 void CookiesTreeModel::PopulateCacheStorageUsageInfo( |
| 1177 LocalDataContainer* container) { |
| 1178 ScopedBatchUpdateNotifier notifier(this, GetRoot()); |
| 1179 PopulateCacheStorageUsageInfoWithFilter(container, ¬ifier, |
| 1180 base::string16()); |
| 1181 } |
| 1182 |
1116 void CookiesTreeModel::PopulateFlashLSOInfo( | 1183 void CookiesTreeModel::PopulateFlashLSOInfo( |
1117 LocalDataContainer* container) { | 1184 LocalDataContainer* container) { |
1118 ScopedBatchUpdateNotifier notifier(this, GetRoot()); | 1185 ScopedBatchUpdateNotifier notifier(this, GetRoot()); |
1119 PopulateFlashLSOInfoWithFilter(container, ¬ifier, base::string16()); | 1186 PopulateFlashLSOInfoWithFilter(container, ¬ifier, base::string16()); |
1120 } | 1187 } |
1121 | 1188 |
1122 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( | 1189 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( |
1123 LocalDataContainer* container, | 1190 LocalDataContainer* container, |
1124 ScopedBatchUpdateNotifier* notifier, | 1191 ScopedBatchUpdateNotifier* notifier, |
1125 const base::string16& filter) { | 1192 const base::string16& filter) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 .find(filter) != base::string16::npos)) { | 1407 .find(filter) != base::string16::npos)) { |
1341 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); | 1408 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); |
1342 CookieTreeServiceWorkersNode* service_workers_node = | 1409 CookieTreeServiceWorkersNode* service_workers_node = |
1343 host_node->GetOrCreateServiceWorkersNode(); | 1410 host_node->GetOrCreateServiceWorkersNode(); |
1344 service_workers_node->AddServiceWorkerNode( | 1411 service_workers_node->AddServiceWorkerNode( |
1345 new CookieTreeServiceWorkerNode(service_worker_info)); | 1412 new CookieTreeServiceWorkerNode(service_worker_info)); |
1346 } | 1413 } |
1347 } | 1414 } |
1348 } | 1415 } |
1349 | 1416 |
| 1417 void CookiesTreeModel::PopulateCacheStorageUsageInfoWithFilter( |
| 1418 LocalDataContainer* container, |
| 1419 ScopedBatchUpdateNotifier* notifier, |
| 1420 const base::string16& filter) { |
| 1421 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 1422 |
| 1423 if (container->cache_storage_info_list_.empty()) |
| 1424 return; |
| 1425 |
| 1426 notifier->StartBatchUpdate(); |
| 1427 for (CacheStorageUsageInfoList::iterator cache_storage_info = |
| 1428 container->cache_storage_info_list_.begin(); |
| 1429 cache_storage_info != container->cache_storage_info_list_.end(); |
| 1430 ++cache_storage_info) { |
| 1431 const GURL& origin = cache_storage_info->origin; |
| 1432 |
| 1433 if (filter.empty() || (CookieTreeHostNode::TitleForUrl(origin) |
| 1434 .find(filter) != base::string16::npos)) { |
| 1435 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); |
| 1436 CookieTreeCacheStoragesNode* cache_storages_node = |
| 1437 host_node->GetOrCreateCacheStoragesNode(); |
| 1438 cache_storages_node->AddCacheStorageNode( |
| 1439 new CookieTreeCacheStorageNode(cache_storage_info)); |
| 1440 } |
| 1441 } |
| 1442 } |
| 1443 |
1350 void CookiesTreeModel::PopulateFileSystemInfoWithFilter( | 1444 void CookiesTreeModel::PopulateFileSystemInfoWithFilter( |
1351 LocalDataContainer* container, | 1445 LocalDataContainer* container, |
1352 ScopedBatchUpdateNotifier* notifier, | 1446 ScopedBatchUpdateNotifier* notifier, |
1353 const base::string16& filter) { | 1447 const base::string16& filter) { |
1354 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 1448 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
1355 | 1449 |
1356 if (container->file_system_info_list_.empty()) | 1450 if (container->file_system_info_list_.empty()) |
1357 return; | 1451 return; |
1358 | 1452 |
1359 notifier->StartBatchUpdate(); | 1453 notifier->StartBatchUpdate(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 void CookiesTreeModel::MaybeNotifyBatchesEnded() { | 1545 void CookiesTreeModel::MaybeNotifyBatchesEnded() { |
1452 // Only notify the observers if this is the outermost call to EndBatch() if | 1546 // Only notify the observers if this is the outermost call to EndBatch() if |
1453 // called in a nested manner. | 1547 // called in a nested manner. |
1454 if (batches_ended_ == batches_started_ && | 1548 if (batches_ended_ == batches_started_ && |
1455 batches_seen_ == batches_expected_) { | 1549 batches_seen_ == batches_expected_) { |
1456 FOR_EACH_OBSERVER(Observer, | 1550 FOR_EACH_OBSERVER(Observer, |
1457 cookies_observer_list_, | 1551 cookies_observer_list_, |
1458 TreeModelEndBatch(this)); | 1552 TreeModelEndBatch(this)); |
1459 } | 1553 } |
1460 } | 1554 } |
OLD | NEW |