| 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: | 137 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: |
| 138 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: | 138 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: |
| 139 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: | 139 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: |
| 140 return true; | 140 return true; |
| 141 | 141 |
| 142 // Fall through each below cases to return false. | 142 // Fall through each below cases to return false. |
| 143 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: | 143 case CookieTreeNode::DetailedInfo::TYPE_COOKIE: |
| 144 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: | 144 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: |
| 145 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: | 145 case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: |
| 146 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: | 146 case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: |
| 147 case CookieTreeNode::DetailedInfo::TYPE_MEDIA_LICENSE: |
| 147 return false; | 148 return false; |
| 148 default: | 149 default: |
| 149 break; | 150 break; |
| 150 } | 151 } |
| 151 return false; | 152 return false; |
| 152 } | 153 } |
| 153 #endif | 154 #endif |
| 154 | 155 |
| 155 // This function returns the local data container associated with a leaf tree | 156 // This function returns the local data container associated with a leaf tree |
| 156 // node. The app node is assumed to be 3 levels above the leaf because of the | 157 // 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... |
| 272 return *this; | 273 return *this; |
| 273 } | 274 } |
| 274 | 275 |
| 275 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitFlashLSO( | 276 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitFlashLSO( |
| 276 const std::string& flash_lso_domain) { | 277 const std::string& flash_lso_domain) { |
| 277 Init(TYPE_FLASH_LSO); | 278 Init(TYPE_FLASH_LSO); |
| 278 this->flash_lso_domain = flash_lso_domain; | 279 this->flash_lso_domain = flash_lso_domain; |
| 279 return *this; | 280 return *this; |
| 280 } | 281 } |
| 281 | 282 |
| 283 CookieTreeNode::DetailedInfo& CookieTreeNode::DetailedInfo::InitMediaLicense( |
| 284 const BrowsingDataMediaLicenseHelper::MediaLicenseInfo* |
| 285 media_license_info) { |
| 286 Init(TYPE_MEDIA_LICENSE); |
| 287 this->media_license_info = media_license_info; |
| 288 this->origin = media_license_info->origin; |
| 289 return *this; |
| 290 } |
| 291 |
| 282 /////////////////////////////////////////////////////////////////////////////// | 292 /////////////////////////////////////////////////////////////////////////////// |
| 283 // CookieTreeNode, public: | 293 // CookieTreeNode, public: |
| 284 | 294 |
| 285 void CookieTreeNode::DeleteStoredObjects() { | 295 void CookieTreeNode::DeleteStoredObjects() { |
| 286 for (const auto& child : children()) | 296 for (const auto& child : children()) |
| 287 child->DeleteStoredObjects(); | 297 child->DeleteStoredObjects(); |
| 288 } | 298 } |
| 289 | 299 |
| 290 CookiesTreeModel* CookieTreeNode::GetModel() const { | 300 CookiesTreeModel* CookieTreeNode::GetModel() const { |
| 291 if (parent()) | 301 if (parent()) |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 container->cache_storage_info_list_.erase(cache_storage_info_); | 586 container->cache_storage_info_list_.erase(cache_storage_info_); |
| 577 } | 587 } |
| 578 } | 588 } |
| 579 | 589 |
| 580 CookieTreeNode::DetailedInfo CookieTreeCacheStorageNode::GetDetailedInfo() | 590 CookieTreeNode::DetailedInfo CookieTreeCacheStorageNode::GetDetailedInfo() |
| 581 const { | 591 const { |
| 582 return DetailedInfo().InitCacheStorage(&*cache_storage_info_); | 592 return DetailedInfo().InitCacheStorage(&*cache_storage_info_); |
| 583 } | 593 } |
| 584 | 594 |
| 585 /////////////////////////////////////////////////////////////////////////////// | 595 /////////////////////////////////////////////////////////////////////////////// |
| 596 // CookieTreeMediaLicenseNode, public: |
| 597 |
| 598 CookieTreeMediaLicenseNode::CookieTreeMediaLicenseNode( |
| 599 const std::list<BrowsingDataMediaLicenseHelper::MediaLicenseInfo>::iterator |
| 600 media_license_info) |
| 601 : CookieTreeNode(base::UTF8ToUTF16(media_license_info->origin.spec())), |
| 602 media_license_info_(media_license_info) {} |
| 603 |
| 604 CookieTreeMediaLicenseNode::~CookieTreeMediaLicenseNode() {} |
| 605 |
| 606 void CookieTreeMediaLicenseNode::DeleteStoredObjects() { |
| 607 LocalDataContainer* container = GetLocalDataContainerForNode(this); |
| 608 |
| 609 if (container) { |
| 610 container->media_license_helper_->DeleteMediaLicenseOrigin( |
| 611 media_license_info_->origin); |
| 612 container->media_license_info_list_.erase(media_license_info_); |
| 613 } |
| 614 } |
| 615 |
| 616 CookieTreeNode::DetailedInfo CookieTreeMediaLicenseNode::GetDetailedInfo() |
| 617 const { |
| 618 return DetailedInfo().InitMediaLicense(&*media_license_info_); |
| 619 } |
| 620 |
| 621 /////////////////////////////////////////////////////////////////////////////// |
| 586 // CookieTreeRootNode, public: | 622 // CookieTreeRootNode, public: |
| 587 | 623 |
| 588 CookieTreeRootNode::CookieTreeRootNode(CookiesTreeModel* model) | 624 CookieTreeRootNode::CookieTreeRootNode(CookiesTreeModel* model) |
| 589 : model_(model) { | 625 : model_(model) { |
| 590 } | 626 } |
| 591 | 627 |
| 592 CookieTreeRootNode::~CookieTreeRootNode() {} | 628 CookieTreeRootNode::~CookieTreeRootNode() {} |
| 593 | 629 |
| 594 CookieTreeHostNode* CookieTreeRootNode::GetOrCreateHostNode(const GURL& url) { | 630 CookieTreeHostNode* CookieTreeRootNode::GetOrCreateHostNode(const GURL& url) { |
| 595 std::unique_ptr<CookieTreeHostNode> host_node = | 631 std::unique_ptr<CookieTreeHostNode> host_node = |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 CookieTreeFlashLSONode* CookieTreeHostNode::GetOrCreateFlashLSONode( | 778 CookieTreeFlashLSONode* CookieTreeHostNode::GetOrCreateFlashLSONode( |
| 743 const std::string& domain) { | 779 const std::string& domain) { |
| 744 DCHECK_EQ(GetHost(), domain); | 780 DCHECK_EQ(GetHost(), domain); |
| 745 if (flash_lso_child_) | 781 if (flash_lso_child_) |
| 746 return flash_lso_child_; | 782 return flash_lso_child_; |
| 747 flash_lso_child_ = new CookieTreeFlashLSONode(domain); | 783 flash_lso_child_ = new CookieTreeFlashLSONode(domain); |
| 748 AddChildSortedByTitle(base::WrapUnique(flash_lso_child_)); | 784 AddChildSortedByTitle(base::WrapUnique(flash_lso_child_)); |
| 749 return flash_lso_child_; | 785 return flash_lso_child_; |
| 750 } | 786 } |
| 751 | 787 |
| 788 CookieTreeMediaLicensesNode* |
| 789 CookieTreeHostNode::GetOrCreateMediaLicensesNode() { |
| 790 if (media_licenses_child_) |
| 791 return media_licenses_child_; |
| 792 media_licenses_child_ = new CookieTreeMediaLicensesNode(); |
| 793 AddChildSortedByTitle(base::WrapUnique(media_licenses_child_)); |
| 794 return media_licenses_child_; |
| 795 } |
| 796 |
| 752 void CookieTreeHostNode::CreateContentException( | 797 void CookieTreeHostNode::CreateContentException( |
| 753 content_settings::CookieSettings* cookie_settings, | 798 content_settings::CookieSettings* cookie_settings, |
| 754 ContentSetting setting) const { | 799 ContentSetting setting) const { |
| 755 DCHECK(setting == CONTENT_SETTING_ALLOW || | 800 DCHECK(setting == CONTENT_SETTING_ALLOW || |
| 756 setting == CONTENT_SETTING_BLOCK || | 801 setting == CONTENT_SETTING_BLOCK || |
| 757 setting == CONTENT_SETTING_SESSION_ONLY); | 802 setting == CONTENT_SETTING_SESSION_ONLY); |
| 758 if (CanCreateContentException()) { | 803 if (CanCreateContentException()) { |
| 759 cookie_settings->ResetCookieSetting(url_); | 804 cookie_settings->ResetCookieSetting(url_); |
| 760 cookie_settings->SetCookieSetting(url_, setting); | 805 cookie_settings->SetCookieSetting(url_, setting); |
| 761 } | 806 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 LocalDataContainer* container = GetModel()->data_container(); | 973 LocalDataContainer* container = GetModel()->data_container(); |
| 929 container->flash_lso_helper_->DeleteFlashLSOsForSite( | 974 container->flash_lso_helper_->DeleteFlashLSOsForSite( |
| 930 domain_, base::Closure()); | 975 domain_, base::Closure()); |
| 931 } | 976 } |
| 932 | 977 |
| 933 CookieTreeNode::DetailedInfo CookieTreeFlashLSONode::GetDetailedInfo() const { | 978 CookieTreeNode::DetailedInfo CookieTreeFlashLSONode::GetDetailedInfo() const { |
| 934 return DetailedInfo().InitFlashLSO(domain_); | 979 return DetailedInfo().InitFlashLSO(domain_); |
| 935 } | 980 } |
| 936 | 981 |
| 937 /////////////////////////////////////////////////////////////////////////////// | 982 /////////////////////////////////////////////////////////////////////////////// |
| 983 // CookieTreeMediaLicensesNode |
| 984 CookieTreeMediaLicensesNode::CookieTreeMediaLicensesNode() |
| 985 : CookieTreeNode(l10n_util::GetStringUTF16(IDS_COOKIES_MEDIA_LICENSES)) {} |
| 986 |
| 987 CookieTreeMediaLicensesNode::~CookieTreeMediaLicensesNode() {} |
| 988 |
| 989 CookieTreeNode::DetailedInfo CookieTreeMediaLicensesNode::GetDetailedInfo() |
| 990 const { |
| 991 return DetailedInfo().Init(DetailedInfo::TYPE_MEDIA_LICENSES); |
| 992 } |
| 993 |
| 994 /////////////////////////////////////////////////////////////////////////////// |
| 938 // ScopedBatchUpdateNotifier | 995 // ScopedBatchUpdateNotifier |
| 939 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier( | 996 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier( |
| 940 CookiesTreeModel* model, | 997 CookiesTreeModel* model, |
| 941 CookieTreeNode* node) | 998 CookieTreeNode* node) |
| 942 : model_(model), node_(node) { | 999 : model_(model), node_(node) { |
| 943 model_->RecordBatchSeen(); | 1000 model_->RecordBatchSeen(); |
| 944 } | 1001 } |
| 945 | 1002 |
| 946 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() { | 1003 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() { |
| 947 if (batch_in_progress_) { | 1004 if (batch_in_progress_) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1078 |
| 1022 // Fall through each below cases to return DATABASE. | 1079 // Fall through each below cases to return DATABASE. |
| 1023 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: | 1080 case CookieTreeNode::DetailedInfo::TYPE_DATABASE: |
| 1024 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: | 1081 case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: |
| 1025 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: | 1082 case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: |
| 1026 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: | 1083 case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: |
| 1027 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: | 1084 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: |
| 1028 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: | 1085 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: |
| 1029 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: | 1086 case CookieTreeNode::DetailedInfo::TYPE_SERVICE_WORKER: |
| 1030 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: | 1087 case CookieTreeNode::DetailedInfo::TYPE_CACHE_STORAGE: |
| 1088 case CookieTreeNode::DetailedInfo::TYPE_MEDIA_LICENSE: |
| 1031 return DATABASE; | 1089 return DATABASE; |
| 1032 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: | 1090 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: |
| 1033 return -1; | 1091 return -1; |
| 1034 default: | 1092 default: |
| 1035 break; | 1093 break; |
| 1036 } | 1094 } |
| 1037 return -1; | 1095 return -1; |
| 1038 } | 1096 } |
| 1039 | 1097 |
| 1040 void CookiesTreeModel::DeleteAllStoredObjects() { | 1098 void CookiesTreeModel::DeleteAllStoredObjects() { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 PopulateCacheStorageUsageInfoWithFilter(container, ¬ifier, | 1222 PopulateCacheStorageUsageInfoWithFilter(container, ¬ifier, |
| 1165 base::string16()); | 1223 base::string16()); |
| 1166 } | 1224 } |
| 1167 | 1225 |
| 1168 void CookiesTreeModel::PopulateFlashLSOInfo( | 1226 void CookiesTreeModel::PopulateFlashLSOInfo( |
| 1169 LocalDataContainer* container) { | 1227 LocalDataContainer* container) { |
| 1170 ScopedBatchUpdateNotifier notifier(this, GetRoot()); | 1228 ScopedBatchUpdateNotifier notifier(this, GetRoot()); |
| 1171 PopulateFlashLSOInfoWithFilter(container, ¬ifier, base::string16()); | 1229 PopulateFlashLSOInfoWithFilter(container, ¬ifier, base::string16()); |
| 1172 } | 1230 } |
| 1173 | 1231 |
| 1232 void CookiesTreeModel::PopulateMediaLicenseInfo(LocalDataContainer* container) { |
| 1233 ScopedBatchUpdateNotifier notifier(this, GetRoot()); |
| 1234 PopulateMediaLicenseInfoWithFilter(container, ¬ifier, base::string16()); |
| 1235 } |
| 1236 |
| 1174 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( | 1237 void CookiesTreeModel::PopulateAppCacheInfoWithFilter( |
| 1175 LocalDataContainer* container, | 1238 LocalDataContainer* container, |
| 1176 ScopedBatchUpdateNotifier* notifier, | 1239 ScopedBatchUpdateNotifier* notifier, |
| 1177 const base::string16& filter) { | 1240 const base::string16& filter) { |
| 1178 using content::AppCacheInfo; | 1241 using content::AppCacheInfo; |
| 1179 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 1242 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 1180 | 1243 |
| 1181 if (container->appcache_info_.empty()) | 1244 if (container->appcache_info_.empty()) |
| 1182 return; | 1245 return; |
| 1183 | 1246 |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 it != container->flash_lso_domain_list_.end(); ++it) { | 1549 it != container->flash_lso_domain_list_.end(); ++it) { |
| 1487 if (filter_utf8.empty() || it->find(filter_utf8) != std::string::npos) { | 1550 if (filter_utf8.empty() || it->find(filter_utf8) != std::string::npos) { |
| 1488 // Create a fake origin for GetOrCreateHostNode(). | 1551 // Create a fake origin for GetOrCreateHostNode(). |
| 1489 GURL origin("http://" + *it); | 1552 GURL origin("http://" + *it); |
| 1490 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); | 1553 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); |
| 1491 host_node->GetOrCreateFlashLSONode(*it); | 1554 host_node->GetOrCreateFlashLSONode(*it); |
| 1492 } | 1555 } |
| 1493 } | 1556 } |
| 1494 } | 1557 } |
| 1495 | 1558 |
| 1559 void CookiesTreeModel::PopulateMediaLicenseInfoWithFilter( |
| 1560 LocalDataContainer* container, |
| 1561 ScopedBatchUpdateNotifier* notifier, |
| 1562 const base::string16& filter) { |
| 1563 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 1564 |
| 1565 if (container->media_license_info_list_.empty()) |
| 1566 return; |
| 1567 |
| 1568 notifier->StartBatchUpdate(); |
| 1569 for (MediaLicenseInfoList::iterator media_license_info = |
| 1570 container->media_license_info_list_.begin(); |
| 1571 media_license_info != container->media_license_info_list_.end(); |
| 1572 ++media_license_info) { |
| 1573 GURL origin(media_license_info->origin); |
| 1574 |
| 1575 if (filter.empty() || (CookieTreeHostNode::TitleForUrl(origin).find( |
| 1576 filter) != base::string16::npos)) { |
| 1577 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); |
| 1578 CookieTreeMediaLicensesNode* media_licenses_node = |
| 1579 host_node->GetOrCreateMediaLicensesNode(); |
| 1580 media_licenses_node->AddMediaLicenseNode( |
| 1581 base::MakeUnique<CookieTreeMediaLicenseNode>(media_license_info)); |
| 1582 } |
| 1583 } |
| 1584 } |
| 1585 |
| 1496 void CookiesTreeModel::SetBatchExpectation(int batches_expected, bool reset) { | 1586 void CookiesTreeModel::SetBatchExpectation(int batches_expected, bool reset) { |
| 1497 batches_expected_ = batches_expected; | 1587 batches_expected_ = batches_expected; |
| 1498 if (reset) { | 1588 if (reset) { |
| 1499 batches_seen_ = 0; | 1589 batches_seen_ = 0; |
| 1500 batches_started_ = 0; | 1590 batches_started_ = 0; |
| 1501 batches_ended_ = 0; | 1591 batches_ended_ = 0; |
| 1502 } else { | 1592 } else { |
| 1503 MaybeNotifyBatchesEnded(); | 1593 MaybeNotifyBatchesEnded(); |
| 1504 } | 1594 } |
| 1505 } | 1595 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1526 // Only notify the observers if this is the outermost call to EndBatch() if | 1616 // Only notify the observers if this is the outermost call to EndBatch() if |
| 1527 // called in a nested manner. | 1617 // called in a nested manner. |
| 1528 if (batches_ended_ == batches_started_ && | 1618 if (batches_ended_ == batches_started_ && |
| 1529 batches_seen_ == batches_expected_) { | 1619 batches_seen_ == batches_expected_) { |
| 1530 FOR_EACH_OBSERVER(Observer, | 1620 FOR_EACH_OBSERVER(Observer, |
| 1531 cookies_observer_list_, | 1621 cookies_observer_list_, |
| 1532 TreeModelEndBatch(this)); | 1622 TreeModelEndBatch(this)); |
| 1533 SetBatchExpectation(0, true); | 1623 SetBatchExpectation(0, true); |
| 1534 } | 1624 } |
| 1535 } | 1625 } |
| OLD | NEW |