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 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 | 903 |
904 CookieTreeNode::DetailedInfo CookieTreeFlashLSONode::GetDetailedInfo() const { | 904 CookieTreeNode::DetailedInfo CookieTreeFlashLSONode::GetDetailedInfo() const { |
905 return DetailedInfo().InitFlashLSO(domain_); | 905 return DetailedInfo().InitFlashLSO(domain_); |
906 } | 906 } |
907 | 907 |
908 /////////////////////////////////////////////////////////////////////////////// | 908 /////////////////////////////////////////////////////////////////////////////// |
909 // ScopedBatchUpdateNotifier | 909 // ScopedBatchUpdateNotifier |
910 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier( | 910 CookiesTreeModel::ScopedBatchUpdateNotifier::ScopedBatchUpdateNotifier( |
911 CookiesTreeModel* model, CookieTreeNode* node) | 911 CookiesTreeModel* model, CookieTreeNode* node) |
912 : model_(model), node_(node), batch_in_progress_(false) { | 912 : model_(model), node_(node), batch_in_progress_(false) { |
| 913 model_->RecordBatchSeen(); |
913 } | 914 } |
914 | 915 |
915 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() { | 916 CookiesTreeModel::ScopedBatchUpdateNotifier::~ScopedBatchUpdateNotifier() { |
916 if (batch_in_progress_) { | 917 if (batch_in_progress_) { |
917 model_->NotifyObserverTreeNodeChanged(node_); | 918 model_->NotifyObserverTreeNodeChanged(node_); |
918 model_->NotifyObserverEndBatch(); | 919 model_->NotifyObserverEndBatch(); |
| 920 } else { |
| 921 // If no batch started, and this is the last batch, give the model a chance |
| 922 // to send out a final notification. |
| 923 model_->MaybeNotifyBatchesEnded(); |
919 } | 924 } |
920 } | 925 } |
921 | 926 |
922 void CookiesTreeModel::ScopedBatchUpdateNotifier::StartBatchUpdate() { | 927 void CookiesTreeModel::ScopedBatchUpdateNotifier::StartBatchUpdate() { |
923 if (!batch_in_progress_) { | 928 if (!batch_in_progress_) { |
924 model_->NotifyObserverBeginBatch(); | 929 model_->NotifyObserverBeginBatch(); |
925 batch_in_progress_ = true; | 930 batch_in_progress_ = true; |
926 } | 931 } |
927 } | 932 } |
928 | 933 |
929 /////////////////////////////////////////////////////////////////////////////// | 934 /////////////////////////////////////////////////////////////////////////////// |
930 // CookiesTreeModel, public: | 935 // CookiesTreeModel, public: |
931 CookiesTreeModel::CookiesTreeModel( | 936 CookiesTreeModel::CookiesTreeModel( |
932 LocalDataContainer* data_container, | 937 LocalDataContainer* data_container, |
933 ExtensionSpecialStoragePolicy* special_storage_policy, | 938 ExtensionSpecialStoragePolicy* special_storage_policy, |
934 bool group_by_cookie_source) | 939 bool group_by_cookie_source) |
935 : ui::TreeNodeModel<CookieTreeNode>(new CookieTreeRootNode(this)), | 940 : ui::TreeNodeModel<CookieTreeNode>(new CookieTreeRootNode(this)), |
936 data_container_(data_container), | 941 data_container_(data_container), |
937 #if defined(ENABLE_EXTENSIONS) | 942 #if defined(ENABLE_EXTENSIONS) |
938 special_storage_policy_(special_storage_policy), | 943 special_storage_policy_(special_storage_policy), |
939 #endif | 944 #endif |
940 group_by_cookie_source_(group_by_cookie_source), | 945 group_by_cookie_source_(group_by_cookie_source), |
941 batch_update_(0) { | 946 batches_expected_(0), |
| 947 batches_seen_(0), |
| 948 batches_started_(0), |
| 949 batches_ended_(0) { |
942 data_container_->Init(this); | 950 data_container_->Init(this); |
943 } | 951 } |
944 | 952 |
945 CookiesTreeModel::~CookiesTreeModel() { | 953 CookiesTreeModel::~CookiesTreeModel() { |
946 } | 954 } |
947 | 955 |
948 /////////////////////////////////////////////////////////////////////////////// | 956 /////////////////////////////////////////////////////////////////////////////// |
949 // CookiesTreeModel, TreeModel methods (public): | 957 // CookiesTreeModel, TreeModel methods (public): |
950 | 958 |
951 // TreeModel methods: | 959 // TreeModel methods: |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 return; | 1018 return; |
1011 cookie_node->DeleteStoredObjects(); | 1019 cookie_node->DeleteStoredObjects(); |
1012 CookieTreeNode* parent_node = cookie_node->parent(); | 1020 CookieTreeNode* parent_node = cookie_node->parent(); |
1013 delete Remove(parent_node, cookie_node); | 1021 delete Remove(parent_node, cookie_node); |
1014 if (parent_node->empty()) | 1022 if (parent_node->empty()) |
1015 DeleteCookieNode(parent_node); | 1023 DeleteCookieNode(parent_node); |
1016 } | 1024 } |
1017 | 1025 |
1018 void CookiesTreeModel::UpdateSearchResults(const base::string16& filter) { | 1026 void CookiesTreeModel::UpdateSearchResults(const base::string16& filter) { |
1019 CookieTreeNode* root = GetRoot(); | 1027 CookieTreeNode* root = GetRoot(); |
| 1028 SetBatchExpectation(1, true); |
1020 ScopedBatchUpdateNotifier notifier(this, root); | 1029 ScopedBatchUpdateNotifier notifier(this, root); |
1021 int num_children = root->child_count(); | 1030 int num_children = root->child_count(); |
1022 notifier.StartBatchUpdate(); | 1031 notifier.StartBatchUpdate(); |
1023 for (int i = num_children - 1; i >= 0; --i) | 1032 for (int i = num_children - 1; i >= 0; --i) |
1024 delete Remove(root, root->GetChild(i)); | 1033 delete Remove(root, root->GetChild(i)); |
1025 | 1034 |
1026 PopulateCookieInfoWithFilter(data_container(), ¬ifier, filter); | 1035 PopulateCookieInfoWithFilter(data_container(), ¬ifier, filter); |
1027 PopulateDatabaseInfoWithFilter(data_container(), ¬ifier, filter); | 1036 PopulateDatabaseInfoWithFilter(data_container(), ¬ifier, filter); |
1028 PopulateLocalStorageInfoWithFilter(data_container(), ¬ifier, filter); | 1037 PopulateLocalStorageInfoWithFilter(data_container(), ¬ifier, filter); |
1029 PopulateSessionStorageInfoWithFilter(data_container(), ¬ifier, filter); | 1038 PopulateSessionStorageInfoWithFilter(data_container(), ¬ifier, filter); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 it != container->flash_lso_domain_list_.end(); ++it) { | 1427 it != container->flash_lso_domain_list_.end(); ++it) { |
1419 if (filter_utf8.empty() || it->find(filter_utf8) != std::string::npos) { | 1428 if (filter_utf8.empty() || it->find(filter_utf8) != std::string::npos) { |
1420 // Create a fake origin for GetOrCreateHostNode(). | 1429 // Create a fake origin for GetOrCreateHostNode(). |
1421 GURL origin("http://" + *it); | 1430 GURL origin("http://" + *it); |
1422 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); | 1431 CookieTreeHostNode* host_node = root->GetOrCreateHostNode(origin); |
1423 host_node->GetOrCreateFlashLSONode(*it); | 1432 host_node->GetOrCreateFlashLSONode(*it); |
1424 } | 1433 } |
1425 } | 1434 } |
1426 } | 1435 } |
1427 | 1436 |
| 1437 void CookiesTreeModel::SetBatchExpectation(int batches_expected, bool reset) { |
| 1438 batches_expected_ = batches_expected; |
| 1439 if (reset) { |
| 1440 batches_seen_ = 0; |
| 1441 batches_started_ = 0; |
| 1442 batches_ended_ = 0; |
| 1443 } else { |
| 1444 MaybeNotifyBatchesEnded(); |
| 1445 } |
| 1446 } |
| 1447 |
| 1448 void CookiesTreeModel::RecordBatchSeen() { |
| 1449 batches_seen_++; |
| 1450 } |
| 1451 |
1428 void CookiesTreeModel::NotifyObserverBeginBatch() { | 1452 void CookiesTreeModel::NotifyObserverBeginBatch() { |
1429 // Only notify the model once if we're batching in a nested manner. | 1453 // Only notify the model once if we're batching in a nested manner. |
1430 if (batch_update_++ == 0) { | 1454 if (batches_started_++ == 0) { |
1431 FOR_EACH_OBSERVER(Observer, | 1455 FOR_EACH_OBSERVER(Observer, |
1432 cookies_observer_list_, | 1456 cookies_observer_list_, |
1433 TreeModelBeginBatch(this)); | 1457 TreeModelBeginBatch(this)); |
1434 } | 1458 } |
1435 } | 1459 } |
1436 | 1460 |
1437 void CookiesTreeModel::NotifyObserverEndBatch() { | 1461 void CookiesTreeModel::NotifyObserverEndBatch() { |
| 1462 batches_ended_++; |
| 1463 MaybeNotifyBatchesEnded(); |
| 1464 } |
| 1465 |
| 1466 void CookiesTreeModel::MaybeNotifyBatchesEnded() { |
1438 // Only notify the observers if this is the outermost call to EndBatch() if | 1467 // Only notify the observers if this is the outermost call to EndBatch() if |
1439 // called in a nested manner. | 1468 // called in a nested manner. |
1440 if (--batch_update_ == 0) { | 1469 if (batches_ended_ == batches_started_ && |
| 1470 batches_seen_ == batches_expected_) { |
1441 FOR_EACH_OBSERVER(Observer, | 1471 FOR_EACH_OBSERVER(Observer, |
1442 cookies_observer_list_, | 1472 cookies_observer_list_, |
1443 TreeModelEndBatch(this)); | 1473 TreeModelEndBatch(this)); |
1444 } | 1474 } |
1445 } | 1475 } |
OLD | NEW |