Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: chrome/browser/cookies_tree_model.cc

Issue 7355025: Creat BrowsingDataCookieHelper and CannedBrowsingDataCookieHelper for logging cookies at UI thread. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/cookies_tree_model.h" 5 #include "chrome/browser/cookies_tree_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browsing_data_cookie_helper.h"
15 #include "chrome/browser/content_settings/host_content_settings_map.h" 17 #include "chrome/browser/content_settings/host_content_settings_map.h"
16 #include "chrome/browser/extensions/extension_service.h" 18 #include "chrome/browser/extensions/extension_service.h"
17 #include "content/browser/in_process_webkit/webkit_context.h" 19 #include "content/browser/in_process_webkit/webkit_context.h"
18 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
20 #include "grit/ui_resources.h" 22 #include "grit/ui_resources.h"
21 #include "net/base/cookie_monster.h" 23 #include "net/base/cookie_monster.h"
22 #include "net/base/registry_controlled_domain.h" 24 #include "net/base/registry_controlled_domain.h"
23 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 30 matching lines...) Expand all
55 CookieTreeCookieNode::~CookieTreeCookieNode() {} 57 CookieTreeCookieNode::~CookieTreeCookieNode() {}
56 58
57 void CookieTreeCookieNode::DeleteStoredObjects() { 59 void CookieTreeCookieNode::DeleteStoredObjects() {
58 // notify CookieMonster that we should delete this cookie 60 // notify CookieMonster that we should delete this cookie
59 // We have stored a copy of all the cookies in the model, and our model is 61 // We have stored a copy of all the cookies in the model, and our model is
60 // never re-calculated. Thus, we just need to delete the nodes from our 62 // never re-calculated. Thus, we just need to delete the nodes from our
61 // model, and tell CookieMonster to delete the cookies. We can keep the 63 // model, and tell CookieMonster to delete the cookies. We can keep the
62 // vector storing the cookies in-tact and not delete from there (that would 64 // vector storing the cookies in-tact and not delete from there (that would
63 // invalidate our pointers), and the fact that it contains semi out-of-date 65 // invalidate our pointers), and the fact that it contains semi out-of-date
64 // data is not problematic as we don't re-build the model based on that. 66 // data is not problematic as we don't re-build the model based on that.
65 GetModel()->cookie_monster_->DeleteCanonicalCookie(*cookie_); 67 GetModel()->cookie_helper_->DeleteCookie(*cookie_);
66 } 68 }
67 69
68 CookieTreeNode::DetailedInfo CookieTreeCookieNode::GetDetailedInfo() const { 70 CookieTreeNode::DetailedInfo CookieTreeCookieNode::GetDetailedInfo() const {
69 return DetailedInfo(parent()->parent()->GetTitle(), 71 return DetailedInfo(parent()->parent()->GetTitle(),
70 DetailedInfo::TYPE_COOKIE, 72 DetailedInfo::TYPE_COOKIE,
71 cookie_, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 73 cookie_, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
72 } 74 }
73 75
74 namespace { 76 namespace {
75 // comparison functor, for use in CookieTreeRootNode 77 // comparison functor, for use in CookieTreeRootNode
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 children().end(), 580 children().end(),
579 new_child, 581 new_child,
580 NodeTitleComparator()); 582 NodeTitleComparator());
581 GetModel()->Add(this, new_child, iter - children().begin()); 583 GetModel()->Add(this, new_child, iter - children().begin());
582 } 584 }
583 585
584 /////////////////////////////////////////////////////////////////////////////// 586 ///////////////////////////////////////////////////////////////////////////////
585 // CookiesTreeModel, public: 587 // CookiesTreeModel, public:
586 588
587 CookiesTreeModel::CookiesTreeModel( 589 CookiesTreeModel::CookiesTreeModel(
588 net::CookieMonster* cookie_monster, 590 BrowsingDataCookieHelper* cookie_helper,
589 BrowsingDataDatabaseHelper* database_helper, 591 BrowsingDataDatabaseHelper* database_helper,
590 BrowsingDataLocalStorageHelper* local_storage_helper, 592 BrowsingDataLocalStorageHelper* local_storage_helper,
591 BrowsingDataLocalStorageHelper* session_storage_helper, 593 BrowsingDataLocalStorageHelper* session_storage_helper,
592 BrowsingDataAppCacheHelper* appcache_helper, 594 BrowsingDataAppCacheHelper* appcache_helper,
593 BrowsingDataIndexedDBHelper* indexed_db_helper, 595 BrowsingDataIndexedDBHelper* indexed_db_helper,
594 BrowsingDataFileSystemHelper* file_system_helper, 596 BrowsingDataFileSystemHelper* file_system_helper,
595 BrowsingDataQuotaHelper* quota_helper, 597 BrowsingDataQuotaHelper* quota_helper,
596 bool use_cookie_source) 598 bool use_cookie_source)
597 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>( 599 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>(
598 new CookieTreeRootNode(this))), 600 new CookieTreeRootNode(this))),
599 cookie_monster_(cookie_monster),
600 appcache_helper_(appcache_helper), 601 appcache_helper_(appcache_helper),
602 cookie_helper_(cookie_helper),
601 database_helper_(database_helper), 603 database_helper_(database_helper),
602 local_storage_helper_(local_storage_helper), 604 local_storage_helper_(local_storage_helper),
603 session_storage_helper_(session_storage_helper), 605 session_storage_helper_(session_storage_helper),
604 indexed_db_helper_(indexed_db_helper), 606 indexed_db_helper_(indexed_db_helper),
605 file_system_helper_(file_system_helper), 607 file_system_helper_(file_system_helper),
606 quota_helper_(quota_helper), 608 quota_helper_(quota_helper),
607 batch_update_(0), 609 batch_update_(0),
608 use_cookie_source_(use_cookie_source) { 610 use_cookie_source_(use_cookie_source) {
609 LoadCookies(); 611 DCHECK(cookie_helper_);
612 cookie_helper_->StartFetching(
613 base::Bind(&CookiesTreeModel::OnCookiesModelInfoLoaded,
614 base::Unretained(this)));
610 DCHECK(database_helper_); 615 DCHECK(database_helper_);
611 database_helper_->StartFetching(NewCallback( 616 database_helper_->StartFetching(NewCallback(
612 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded)); 617 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded));
613 DCHECK(local_storage_helper_); 618 DCHECK(local_storage_helper_);
614 local_storage_helper_->StartFetching(NewCallback( 619 local_storage_helper_->StartFetching(NewCallback(
615 this, &CookiesTreeModel::OnLocalStorageModelInfoLoaded)); 620 this, &CookiesTreeModel::OnLocalStorageModelInfoLoaded));
616 if (session_storage_helper_) { 621 if (session_storage_helper_) {
617 session_storage_helper_->StartFetching(NewCallback( 622 session_storage_helper_->StartFetching(NewCallback(
618 this, &CookiesTreeModel::OnSessionStorageModelInfoLoaded)); 623 this, &CookiesTreeModel::OnSessionStorageModelInfoLoaded));
619 } 624 }
(...skipping 15 matching lines...) Expand all
635 this, &CookiesTreeModel::OnFileSystemModelInfoLoaded)); 640 this, &CookiesTreeModel::OnFileSystemModelInfoLoaded));
636 } 641 }
637 642
638 if (quota_helper_) { 643 if (quota_helper_) {
639 quota_helper_->StartFetching(NewCallback( 644 quota_helper_->StartFetching(NewCallback(
640 this, &CookiesTreeModel::OnQuotaModelInfoLoaded)); 645 this, &CookiesTreeModel::OnQuotaModelInfoLoaded));
641 } 646 }
642 } 647 }
643 648
644 CookiesTreeModel::~CookiesTreeModel() { 649 CookiesTreeModel::~CookiesTreeModel() {
650 cookie_helper_->CancelNotification();
645 database_helper_->CancelNotification(); 651 database_helper_->CancelNotification();
646 local_storage_helper_->CancelNotification(); 652 local_storage_helper_->CancelNotification();
647 if (session_storage_helper_) 653 if (session_storage_helper_)
648 session_storage_helper_->CancelNotification(); 654 session_storage_helper_->CancelNotification();
649 if (appcache_helper_) 655 if (appcache_helper_)
650 appcache_helper_->CancelNotification(); 656 appcache_helper_->CancelNotification();
651 if (indexed_db_helper_) 657 if (indexed_db_helper_)
652 indexed_db_helper_->CancelNotification(); 658 indexed_db_helper_->CancelNotification();
653 if (file_system_helper_) 659 if (file_system_helper_)
654 file_system_helper_->CancelNotification(); 660 file_system_helper_->CancelNotification();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: 700 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
695 return DATABASE; // ditto 701 return DATABASE; // ditto
696 case CookieTreeNode::DetailedInfo::TYPE_QUOTA: 702 case CookieTreeNode::DetailedInfo::TYPE_QUOTA:
697 return -1; 703 return -1;
698 default: 704 default:
699 break; 705 break;
700 } 706 }
701 return -1; 707 return -1;
702 } 708 }
703 709
704 void CookiesTreeModel::LoadCookies() {
705 LoadCookiesWithFilter(std::wstring());
706 }
707
708 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) {
709 // mmargh mmargh mmargh! delicious!
710
711 all_cookies_ = cookie_monster_->GetAllCookies();
712 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
713 for (CookieList::iterator it = all_cookies_.begin();
714 it != all_cookies_.end(); ++it) {
715 std::string source_string = it->Source();
716 if (source_string.empty() || !use_cookie_source_) {
717 std::string domain = it->Domain();
718 if (domain.length() > 1 && domain[0] == '.')
719 domain = domain.substr(1);
720
721 // We treat secure cookies just the same as normal ones.
722 source_string = std::string(chrome::kHttpScheme) +
723 chrome::kStandardSchemeSeparator + domain + "/";
724 }
725
726 GURL source(source_string);
727 if (!filter.size() ||
728 (CookieTreeOriginNode::TitleForUrl(source).find(filter) !=
729 std::string::npos)) {
730 CookieTreeOriginNode* origin_node =
731 root->GetOrCreateOriginNode(source);
732 CookieTreeCookiesNode* cookies_node =
733 origin_node->GetOrCreateCookiesNode();
734 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it);
735 cookies_node->AddCookieNode(new_cookie);
736 }
737 }
738 }
739
740 void CookiesTreeModel::DeleteAllStoredObjects() { 710 void CookiesTreeModel::DeleteAllStoredObjects() {
741 NotifyObserverBeginBatch(); 711 NotifyObserverBeginBatch();
742 CookieTreeNode* root = GetRoot(); 712 CookieTreeNode* root = GetRoot();
743 root->DeleteStoredObjects(); 713 root->DeleteStoredObjects();
744 int num_children = root->child_count(); 714 int num_children = root->child_count();
745 for (int i = num_children - 1; i >= 0; --i) 715 for (int i = num_children - 1; i >= 0; --i)
746 delete Remove(root, root->GetChild(i)); 716 delete Remove(root, root->GetChild(i));
747 NotifyObserverTreeNodeChanged(root); 717 NotifyObserverTreeNodeChanged(root);
748 NotifyObserverEndBatch(); 718 NotifyObserverEndBatch();
749 } 719 }
750 720
751 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) { 721 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) {
752 if (cookie_node == GetRoot()) 722 if (cookie_node == GetRoot())
753 return; 723 return;
754 cookie_node->DeleteStoredObjects(); 724 cookie_node->DeleteStoredObjects();
755 CookieTreeNode* parent_node = cookie_node->parent(); 725 CookieTreeNode* parent_node = cookie_node->parent();
756 delete Remove(parent_node, cookie_node); 726 delete Remove(parent_node, cookie_node);
757 if (parent_node->empty()) 727 if (parent_node->empty())
758 DeleteCookieNode(parent_node); 728 DeleteCookieNode(parent_node);
759 } 729 }
760 730
761 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) { 731 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) {
762 CookieTreeNode* root = GetRoot(); 732 CookieTreeNode* root = GetRoot();
763 int num_children = root->child_count(); 733 int num_children = root->child_count();
764 NotifyObserverBeginBatch(); 734 NotifyObserverBeginBatch();
765 for (int i = num_children - 1; i >= 0; --i) 735 for (int i = num_children - 1; i >= 0; --i)
766 delete Remove(root, root->GetChild(i)); 736 delete Remove(root, root->GetChild(i));
767 LoadCookiesWithFilter(filter); 737 PopulateCookieInfoWithFilter(filter);
768 PopulateDatabaseInfoWithFilter(filter); 738 PopulateDatabaseInfoWithFilter(filter);
769 PopulateLocalStorageInfoWithFilter(filter); 739 PopulateLocalStorageInfoWithFilter(filter);
770 PopulateSessionStorageInfoWithFilter(filter); 740 PopulateSessionStorageInfoWithFilter(filter);
771 PopulateAppCacheInfoWithFilter(filter); 741 PopulateAppCacheInfoWithFilter(filter);
772 PopulateIndexedDBInfoWithFilter(filter); 742 PopulateIndexedDBInfoWithFilter(filter);
773 PopulateFileSystemInfoWithFilter(filter); 743 PopulateFileSystemInfoWithFilter(filter);
774 PopulateQuotaInfoWithFilter(filter); 744 PopulateQuotaInfoWithFilter(filter);
775 NotifyObserverTreeNodeChanged(root); 745 NotifyObserverTreeNodeChanged(root);
776 NotifyObserverEndBatch(); 746 NotifyObserverEndBatch();
777 } 747 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 info != origin->second.end(); ++info) { 789 info != origin->second.end(); ++info) {
820 appcaches_node->AddAppCacheNode( 790 appcaches_node->AddAppCacheNode(
821 new CookieTreeAppCacheNode(&(*info))); 791 new CookieTreeAppCacheNode(&(*info)));
822 } 792 }
823 } 793 }
824 } 794 }
825 NotifyObserverTreeNodeChanged(root); 795 NotifyObserverTreeNodeChanged(root);
826 NotifyObserverEndBatch(); 796 NotifyObserverEndBatch();
827 } 797 }
828 798
799 void CookiesTreeModel::OnCookiesModelInfoLoaded(
800 const CookieList& cookie_list) {
801 cookie_list_ = cookie_list;
802 PopulateCookieInfoWithFilter(std::wstring());
803 }
804
805 void CookiesTreeModel::PopulateCookieInfoWithFilter(
806 const std::wstring& filter) {
807 // mmargh mmargh mmargh! delicious!
808
809 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
810 for (CookieList::iterator it = cookie_list_.begin();
811 it != cookie_list_.end(); ++it) {
812 std::string source_string = it->Source();
813 if (source_string.empty() || !use_cookie_source_) {
814 std::string domain = it->Domain();
815 if (domain.length() > 1 && domain[0] == '.')
816 domain = domain.substr(1);
817
818 // We treat secure cookies just the same as normal ones.
819 source_string = std::string(chrome::kHttpScheme) +
820 chrome::kStandardSchemeSeparator + domain + "/";
821 }
822
823 GURL source(source_string);
824 if (!filter.size() ||
825 (CookieTreeOriginNode::TitleForUrl(source).find(filter) !=
826 std::string::npos)) {
827 CookieTreeOriginNode* origin_node =
828 root->GetOrCreateOriginNode(source);
829 CookieTreeCookiesNode* cookies_node =
830 origin_node->GetOrCreateCookiesNode();
831 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it);
832 cookies_node->AddCookieNode(new_cookie);
833 }
834 }
835 }
836
829 void CookiesTreeModel::OnDatabaseModelInfoLoaded( 837 void CookiesTreeModel::OnDatabaseModelInfoLoaded(
830 const DatabaseInfoList& database_info) { 838 const DatabaseInfoList& database_info) {
831 database_info_list_ = database_info; 839 database_info_list_ = database_info;
832 PopulateDatabaseInfoWithFilter(std::wstring()); 840 PopulateDatabaseInfoWithFilter(std::wstring());
833 } 841 }
834 842
835 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( 843 void CookiesTreeModel::PopulateDatabaseInfoWithFilter(
836 const std::wstring& filter) { 844 const std::wstring& filter) {
837 if (database_info_list_.empty()) 845 if (database_info_list_.empty())
838 return; 846 return;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 1035
1028 void CookiesTreeModel::NotifyObserverEndBatch() { 1036 void CookiesTreeModel::NotifyObserverEndBatch() {
1029 // Only notify the observers if this is the outermost call to EndBatch() if 1037 // Only notify the observers if this is the outermost call to EndBatch() if
1030 // called in a nested manner. 1038 // called in a nested manner.
1031 if (--batch_update_ == 0) { 1039 if (--batch_update_ == 0) {
1032 FOR_EACH_OBSERVER(Observer, 1040 FOR_EACH_OBSERVER(Observer,
1033 cookies_observer_list_, 1041 cookies_observer_list_,
1034 TreeModelEndBatch(this)); 1042 TreeModelEndBatch(this));
1035 } 1043 }
1036 } 1044 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698