| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: | 129 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: |
| 130 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: | 130 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: |
| 131 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: | 131 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: |
| 132 return true; | 132 return true; |
| 133 | 133 |
| 134 // Fall through each below cases to return false. | 134 // Fall through each below cases to return false. |
| 135 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: | 135 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: |
| 136 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: | 136 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: |
| 137 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: | 137 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: |
| 138 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: | 138 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: |
| 139 case CookieTreeNode::DetailedInfo::TYPE_MEDIA_LICENSE: |
| 139 return false; | 140 return false; |
| 140 default: | 141 default: |
| 141 break; | 142 break; |
| 142 } | 143 } |
| 143 return false; | 144 return false; |
| 144 } | 145 } |
| 145 #endif | 146 #endif |
| 146 | 147 |
| 147 // This function returns the local data container associated with a leaf tree | 148 // This function returns the local data container associated with a leaf tree |
| 148 // node. The app node is assumed to be 3 levels above the leaf because of the | 149 // node. The app node is assumed to be 3 levels above the leaf because of the |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return *this; | 265 return *this; |
| 265 } | 266 } |
| 266 | 267 |
| 267 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitFlashLSO( | 268 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitFlashLSO( |
| 268 const std::string& flash_lso_domain) { | 269 const std::string& flash_lso_domain) { |
| 269 Init(TYPE_FLASH_LSO); | 270 Init(TYPE_FLASH_LSO); |
| 270 this->flash_lso_domain = flash_lso_domain; | 271 this->flash_lso_domain = flash_lso_domain; |
| 271 return *this; | 272 return *this; |
| 272 } | 273 } |
| 273 | 274 |
| 275 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitMediaLicense( |
| 276 const BrowsingDataMediaLicenseHelper::MediaLicenseInfo* |
| 277 media_license_info) { |
| 278 Init(TYPE_MEDIA_LICENSE); |
| 279 this->media_license_info = media_license_info; |
| 280 this->origin = media_license_info->origin; |
| 281 return *this; |
| 282 } |
| 283 |
| 274 /////////////////////////////////////////////////////////////////////////////// | 284 /////////////////////////////////////////////////////////////////////////////// |
| 275 // CookieTreeNode, public: | 285 // CookieTreeNode, public: |
| 276 | 286 |
| 277 void CookieTreeNode::DeleteStoredObjects() { | 287 void CookieTreeNode::DeleteStoredObjects() { |
| 278 for (const auto& child : children()) | 288 for (const auto& child : children()) |
| 279 child->DeleteStoredObjects(); | 289 child->DeleteStoredObjects(); |
| 280 } | 290 } |
| 281 | 291 |
| 282 CookiesTreeModel* CookieTreeNode::GetModel() const { | 292 CookiesTreeModel* CookieTreeNode::GetModel() const { |
| 283 if (parent()) | 293 if (parent()) |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 container->cache_storage_info_list_.erase(cache_storage_info_); | 578 container->cache_storage_info_list_.erase(cache_storage_info_); |
| 569 } | 579 } |
| 570 } | 580 } |
| 571 | 581 |
| 572 CookieTreeNode::DetailedInfo CookieTreeCacheStorageNode::GetDetailedInfo() | 582 CookieTreeNode::DetailedInfo CookieTreeCacheStorageNode::GetDetailedInfo() |
| 573 const { | 583 const { |
| 574 return DetailedInfo().InitCacheStorage(&*cache_storage_info_); | 584 return DetailedInfo().InitCacheStorage(&*cache_storage_info_); |
| 575 } | 585 } |
| 576 | 586 |
| 577 /////////////////////////////////////////////////////////////////////////////// | 587 /////////////////////////////////////////////////////////////////////////////// |
| 588 // CookieTreeMediaLicenseNode, public: |
| 589 |
| 590 CookieTreeMediaLicenseNode::CookieTreeMediaLicenseNode( |
| 591 const std::list<BrowsingDataMediaLicenseHelper::MediaLicenseInfo>::iterator |
| 592 media_license_info) |
| 593 : CookieTreeNode(base::UTF8ToUTF16(media_license_info->origin.spec())), |
| 594 media_license_info_(media_license_info) {} |
| 595 |
| 596 CookieTreeMediaLicenseNode::~CookieTreeMediaLicenseNode() {} |
| 597 |
| 598 void CookieTreeMediaLicenseNode::DeleteStoredObjects() { |
| 599 LocalDataContainer* container = GetLocalDataContainerForNode(this); |
| 600 |
| 601 if (container) { |
| 602 container->media_license_helper_->DeleteMediaLicenseOrigin( |
| 603 media_license_info_->origin); |
| 604 container->media_license_info_list_.erase(media_license_info_); |
| 605 } |
| 606 } |
| 607 |
| 608 CookieTreeNode::DetailedInfo CookieTreeMediaLicenseNode::GetDetailedInfo() |
| 609 const { |
| 610 return DetailedInfo().InitMediaLicense(&*media_license_info_); |
| 611 } |
| 612 |
| 613 /////////////////////////////////////////////////////////////////////////////// |
| 578 // CookieTreeRootNode, public: | 614 // CookieTreeRootNode, public: |
| 579 | 615 |
| 580 CookieTreeRootNode::CookieTreeRootNode(CookiesTreeModel* model) | 616 CookieTreeRootNode::CookieTreeRootNode(CookiesTreeModel* model) |
| 581 : model_(model) { | 617 : model_(model) { |
| 582 } | 618 } |
| 583 | 619 |
| 584 CookieTreeRootNode::~CookieTreeRootNode() {} | 620 CookieTreeRootNode::~CookieTreeRootNode() {} |
| 585 | 621 |
| 586 CookieTreeHostNode* CookieTreeRootNode::GetOrCreateHostNode(const GURL& url) { | 622 CookieTreeHostNode* CookieTreeRootNode::GetOrCreateHostNode(const GURL& url) { |
| 587 std::unique_ptr<CookieTreeHostNode> host_node = | 623 std::unique_ptr<CookieTreeHostNode> host_node = |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 CookieTreeFlashLSONode* CookieTreeHostNode::GetOrCreateFlashLSONode( | 769 CookieTreeFlashLSONode* CookieTreeHostNode::GetOrCreateFlashLSONode( |
| 734 const std::string& domain) { | 770 const std::string& domain) { |
| 735 DCHECK_EQ(GetHost(), domain); | 771 DCHECK_EQ(GetHost(), domain); |
| 736 if (flash_lso_child_) | 772 if (flash_lso_child_) |
| 737 return flash_lso_child_; | 773 return flash_lso_child_; |
| 738 flash_lso_child_ = new CookieTreeFlashLSONode(domain); | 774 flash_lso_child_ = new CookieTreeFlashLSONode(domain); |
| 739 AddChildSortedByTitle(base::WrapUnique(flash_lso_child_)); | 775 AddChildSortedByTitle(base::WrapUnique(flash_lso_child_)); |
| 740 return flash_lso_child_; | 776 return flash_lso_child_; |
| 741 } | 777 } |
| 742 | 778 |
| 779 CookieTreeMediaLicensesNode* |
| 780 CookieTreeHostNode::GetOrCreateMediaLicensesNode() { |
| 781 if (media_licenses_child_) |
| 782 return media_licenses_child_; |
| 783 media_licenses_child_ = new CookieTreeMediaLicensesNode(); |
| 784 AddChildSortedByTitle(base::WrapUnique(media_licenses_child_)); |
| 785 return media_licenses_child_; |
| 786 } |
| 787 |
| 743 void CookieTreeHostNode::CreateContentException( | 788 void CookieTreeHostNode::CreateContentException( |
| 744 content_settings::CookieSettings* cookie_settings, | 789 content_settings::CookieSettings* cookie_settings, |
| 745 ContentSetting setting) const { | 790 ContentSetting setting) const { |
| 746 DCHECK(setting == CONTENT_SETTING_ALLOW || | 791 DCHECK(setting == CONTENT_SETTING_ALLOW || |
| 747 setting == CONTENT_SETTING_BLOCK || | 792 setting == CONTENT_SETTING_BLOCK || |
| 748 setting == CONTENT_SETTING_SESSION_ONLY); | 793 setting == CONTENT_SETTING_SESSION_ONLY); |
| 749 if (CanCreateContentException()) { | 794 if (CanCreateContentException()) { |
| 750 cookie_settings->ResetCookieSetting(url_); | 795 cookie_settings->ResetCookieSetting(url_); |
| 751 cookie_settings->SetCookieSetting(url_, setting); | 796 cookie_settings->SetCookieSetting(url_, setting); |
| 752 } | 797 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 LocalDataContainer* container = GetModel()->data_container(); | 964 LocalDataContainer* container = GetModel()->data_container(); |
| 920 container->flash_lso_helper_->DeleteFlashLSOsForSite( | 965 container->flash_lso_helper_->DeleteFlashLSOsForSite( |
| 921 domain_, base::Closure()); | 966 domain_, base::Closure()); |
| 922 } | 967 } |
| 923 | 968 |
| 924 CookieTreeNode::DetailedInfo CookieTreeFlashLSONode::GetDetailedInfo() const { | 969 CookieTreeNode::DetailedInfo CookieTreeFlashLSONode::GetDetailedInfo() const { |
| 925 return DetailedInfo().InitFlashLSO(domain_); | 970 return DetailedInfo().InitFlashLSO(domain_); |
| 926 } | 971 } |
| 927 | 972 |
| 928 /////////////////////////////////////////////////////////////////////////////// | 973 /////////////////////////////////////////////////////////////////////////////// |
| 974 // CookieTreeMediaLicensesNode |
| 975 CookieTreeMediaLicensesNode::CookieTreeMediaLicensesNode() |
| 976 : CookieTreeNode(l10n_util::GetStringUTF16(IDS_COOKIES_MEDIA_LICENSES)) {} |
| 977 |
| 978 CookieTreeMediaLicensesNode::~CookieTreeMediaLicensesNode() {} |
| 979 |
| 980 CookieTreeNode::DetailedInfo CookieTreeMediaLicensesNode::GetDetailedInfo() |
| 981 const { |
| 982 return DetailedInfo().Init(DetailedInfo::TYPE_MEDIA_LICENSES); |
| 983 } |
| 984 |
| 985 /////////////////////////////////////////////////////////////////////////////// |
| 929 // ScopedBatchUpdateNotifier | 986 // ScopedBatchUpdateNotifier |
| 930 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier( | 987 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier( |
| 931 CookiesTreeModel* model, | 988 CookiesTreeModel* model, |
| 932 CookieTreeNode* node) | 989 CookieTreeNode* node) |
| 933 : model_(model), node_(node) { | 990 : model_(model), node_(node) { |
| 934 model_->RecordBatchSeen(); | 991 model_->RecordBatchSeen(); |
| 935 } | 992 } |
| 936 | 993 |
| 937 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() { | 994 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() { |
| 938 if (batch_in_progress_) { | 995 if (batch_in_progress_) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 | 1069 |
| 1013 // Fall through each below cases to return DATABASE. | 1070 // Fall through each below cases to return DATABASE. |
| 1014 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: | 1071 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: |
| 1015 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: | 1072 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: |
| 1016 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: | 1073 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: |
| 1017 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: | 1074 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: |
| 1018 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: | 1075 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: |
| 1019 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: | 1076 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: |
| 1020 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: | 1077 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: |
| 1021 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: | 1078 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: |
| 1079 case CookieTreeNode::DetailedInfo::TYPE_MEDIA_LICENSE: |
| 1022 return DATABASE; | 1080 return DATABASE; |
| 1023 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: | 1081 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: |
| 1024 return -1; | 1082 return -1; |
| 1025 default: | 1083 default: |
| 1026 break; | 1084 break; |
| 1027 } | 1085 } |
| 1028 return -1; | 1086 return -1; |
| 1029 } | 1087 } |
| 1030 | 1088 |
| 1031 void CookiesTreeModel::DeleteAllStoredObjects() { | 1089 void CookiesTreeModel::DeleteAllStoredObjects() { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 PopulateCacheStorageUsageInfoWithFilter(container, ¬ifier, | 1213 PopulateCacheStorageUsageInfoWithFilter(container, ¬ifier, |
| 1156 base::string16()); | 1214 base::string16()); |
| 1157 } | 1215 } |
| 1158 | 1216 |
| 1159 void CookiesTreeModel::PopulateFlashLSOInfo( | 1217 void CookiesTreeModel::PopulateFlashLSOInfo( |
| 1160 LocalDataContainer* container) { | 1218 LocalDataContainer* container) { |
| 1161 ScopedBatchUpdateNotifier notifier(this, GetRoot()); | 1219 ScopedBatchUpdateNotifier notifier(this, GetRoot()); |
| 1162 PopulateFlashLSOInfoWithFilter(container, ¬ifier, base::string16()); | 1220 PopulateFlashLSOInfoWithFilter(container, ¬ifier, base::string16()); |
| 1163 } | 1221 } |
| 1164 | 1222 |
| 1223 void CookiesTreeModel::PopulateMediaLicenseInfo(LocalDataContainer* container) { |
| 1224 ScopedBatchUpdateNotifier notifier(this, GetRoot()); |
| 1225 PopulateMediaLicenseInfoWithFilter(container, ¬ifier, base::string16()); |
| 1226 } |
| 1227 |
| 1165 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( | 1228 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( |
| 1166 LocalDataContainer* container, | 1229 LocalDataContainer* container, |
| 1167 ScopedBatchUpdateNotifier* notifier, | 1230 ScopedBatchUpdateNotifier* notifier, |
| 1168 const base::string16& filter) { | 1231 const base::string16& filter) { |
| 1169 using content::AppCacheInfo; | 1232 using content::AppCacheInfo; |
| 1170 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 1233 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 1171 | 1234 |
| 1172 if (container->appcache_info_.empty()) | 1235 if (container->appcache_info_.empty()) |
| 1173 return; | 1236 return; |
| 1174 | 1237 |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 it != container->flash_lso_domain_list_.end(); ++it) { | 1540 it != container->flash_lso_domain_list_.end(); ++it) { |
| 1478 if (filter_utf8.empty() || it->find(filter_utf8) != std::string::npos) { | 1541 if (filter_utf8.empty() || it->find(filter_utf8) != std::string::npos) { |
| 1479 // Create a fake origin for GetOrCreateHostNode(). | 1542 // Create a fake origin for GetOrCreateHostNode(). |
| 1480 GURL origin("http://" + *it); | 1543 GURL origin("http://" + *it); |
| 1481 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); | 1544 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); |
| 1482 host_node->GetOrCreateFlashLSONode(*it); | 1545 host_node->GetOrCreateFlashLSONode(*it); |
| 1483 } | 1546 } |
| 1484 } | 1547 } |
| 1485 } | 1548 } |
| 1486 | 1549 |
| 1550 void CookiesTreeModel::PopulateMediaLicenseInfoWithFilter( |
| 1551 LocalDataContainer* container, |
| 1552 ScopedBatchUpdateNotifier* notifier, |
| 1553 const base::string16& filter) { |
| 1554 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 1555 |
| 1556 if (container->media_license_info_list_.empty()) |
| 1557 return; |
| 1558 |
| 1559 notifier->StartBatchUpdate(); |
| 1560 for (MediaLicenseInfoList::iterator media_license_info = |
| 1561 container->media_license_info_list_.begin(); |
| 1562 media_license_info != container->media_license_info_list_.end(); |
| 1563 ++media_license_info) { |
| 1564 GURL origin(media_license_info->origin); |
| 1565 |
| 1566 if (filter.empty() || (CookieTreeHostNode::TitleForUrl(origin).find( |
| 1567 filter) != base::string16::npos)) { |
| 1568 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); |
| 1569 CookieTreeMediaLicensesNode* media_licenses_node = |
| 1570 host_node->GetOrCreateMediaLicensesNode(); |
| 1571 media_licenses_node->AddMediaLicenseNode( |
| 1572 base::MakeUnique<CookieTreeMediaLicenseNode>(media_license_info)); |
| 1573 } |
| 1574 } |
| 1575 } |
| 1576 |
| 1487 void CookiesTreeModel::SetBatchExpectation(int batches_expected, bool reset) { | 1577 void CookiesTreeModel::SetBatchExpectation(int batches_expected, bool reset) { |
| 1488 batches_expected_ = batches_expected; | 1578 batches_expected_ = batches_expected; |
| 1489 if (reset) { | 1579 if (reset) { |
| 1490 batches_seen_ = 0; | 1580 batches_seen_ = 0; |
| 1491 batches_started_ = 0; | 1581 batches_started_ = 0; |
| 1492 batches_ended_ = 0; | 1582 batches_ended_ = 0; |
| 1493 } else { | 1583 } else { |
| 1494 MaybeNotifyBatchesEnded(); | 1584 MaybeNotifyBatchesEnded(); |
| 1495 } | 1585 } |
| 1496 } | 1586 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1517 // Only notify the observers if this is the outermost call to EndBatch() if | 1607 // Only notify the observers if this is the outermost call to EndBatch() if |
| 1518 // called in a nested manner. | 1608 // called in a nested manner. |
| 1519 if (batches_ended_ == batches_started_ && | 1609 if (batches_ended_ == batches_started_ && |
| 1520 batches_seen_ == batches_expected_) { | 1610 batches_seen_ == batches_expected_) { |
| 1521 FOR_EACH_OBSERVER(Observer, | 1611 FOR_EACH_OBSERVER(Observer, |
| 1522 cookies_observer_list_, | 1612 cookies_observer_list_, |
| 1523 TreeModelEndBatch(this)); | 1613 TreeModelEndBatch(this)); |
| 1524 SetBatchExpectation(0, true); | 1614 SetBatchExpectation(0, true); |
| 1525 } | 1615 } |
| 1526 } | 1616 } |
| OLD | NEW |