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

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
« no previous file with comments | « chrome/browser/cookies_tree_model.h ('k') | chrome/browser/cookies_tree_model_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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); 73 cookie_, 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 children().end(), 546 children().end(),
545 new_child, 547 new_child,
546 NodeTitleComparator()); 548 NodeTitleComparator());
547 GetModel()->Add(this, new_child, iter - children().begin()); 549 GetModel()->Add(this, new_child, iter - children().begin());
548 } 550 }
549 551
550 /////////////////////////////////////////////////////////////////////////////// 552 ///////////////////////////////////////////////////////////////////////////////
551 // CookiesTreeModel, public: 553 // CookiesTreeModel, public:
552 554
553 CookiesTreeModel::CookiesTreeModel( 555 CookiesTreeModel::CookiesTreeModel(
554 net::CookieMonster* cookie_monster, 556 BrowsingDataCookieHelper* cookie_helper,
555 BrowsingDataDatabaseHelper* database_helper, 557 BrowsingDataDatabaseHelper* database_helper,
556 BrowsingDataLocalStorageHelper* local_storage_helper, 558 BrowsingDataLocalStorageHelper* local_storage_helper,
557 BrowsingDataLocalStorageHelper* session_storage_helper, 559 BrowsingDataLocalStorageHelper* session_storage_helper,
558 BrowsingDataAppCacheHelper* appcache_helper, 560 BrowsingDataAppCacheHelper* appcache_helper,
559 BrowsingDataIndexedDBHelper* indexed_db_helper, 561 BrowsingDataIndexedDBHelper* indexed_db_helper,
560 BrowsingDataFileSystemHelper* file_system_helper, 562 BrowsingDataFileSystemHelper* file_system_helper,
561 bool use_cookie_source) 563 bool use_cookie_source)
562 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>( 564 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>(
563 new CookieTreeRootNode(this))), 565 new CookieTreeRootNode(this))),
564 cookie_monster_(cookie_monster),
565 appcache_helper_(appcache_helper), 566 appcache_helper_(appcache_helper),
567 cookie_helper_(cookie_helper),
566 database_helper_(database_helper), 568 database_helper_(database_helper),
567 local_storage_helper_(local_storage_helper), 569 local_storage_helper_(local_storage_helper),
568 session_storage_helper_(session_storage_helper), 570 session_storage_helper_(session_storage_helper),
569 indexed_db_helper_(indexed_db_helper), 571 indexed_db_helper_(indexed_db_helper),
570 file_system_helper_(file_system_helper), 572 file_system_helper_(file_system_helper),
571 batch_update_(0), 573 batch_update_(0),
572 use_cookie_source_(use_cookie_source) { 574 use_cookie_source_(use_cookie_source) {
573 LoadCookies(); 575 DCHECK(cookie_helper_);
576 cookie_helper_->StartFetching(
577 base::Bind(&CookiesTreeModel::OnCookiesModelInfoLoaded,
578 base::Unretained(this)));
574 DCHECK(database_helper_); 579 DCHECK(database_helper_);
575 database_helper_->StartFetching(NewCallback( 580 database_helper_->StartFetching(NewCallback(
576 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded)); 581 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded));
577 DCHECK(local_storage_helper_); 582 DCHECK(local_storage_helper_);
578 local_storage_helper_->StartFetching(NewCallback( 583 local_storage_helper_->StartFetching(NewCallback(
579 this, &CookiesTreeModel::OnLocalStorageModelInfoLoaded)); 584 this, &CookiesTreeModel::OnLocalStorageModelInfoLoaded));
580 if (session_storage_helper_) { 585 if (session_storage_helper_) {
581 session_storage_helper_->StartFetching(NewCallback( 586 session_storage_helper_->StartFetching(NewCallback(
582 this, &CookiesTreeModel::OnSessionStorageModelInfoLoaded)); 587 this, &CookiesTreeModel::OnSessionStorageModelInfoLoaded));
583 } 588 }
(...skipping 10 matching lines...) Expand all
594 this, &CookiesTreeModel::OnIndexedDBModelInfoLoaded)); 599 this, &CookiesTreeModel::OnIndexedDBModelInfoLoaded));
595 } 600 }
596 601
597 if (file_system_helper_) { 602 if (file_system_helper_) {
598 file_system_helper_->StartFetching(NewCallback( 603 file_system_helper_->StartFetching(NewCallback(
599 this, &CookiesTreeModel::OnFileSystemModelInfoLoaded)); 604 this, &CookiesTreeModel::OnFileSystemModelInfoLoaded));
600 } 605 }
601 } 606 }
602 607
603 CookiesTreeModel::~CookiesTreeModel() { 608 CookiesTreeModel::~CookiesTreeModel() {
609 cookie_helper_->CancelNotification();
604 database_helper_->CancelNotification(); 610 database_helper_->CancelNotification();
605 local_storage_helper_->CancelNotification(); 611 local_storage_helper_->CancelNotification();
606 if (session_storage_helper_) 612 if (session_storage_helper_)
607 session_storage_helper_->CancelNotification(); 613 session_storage_helper_->CancelNotification();
608 if (appcache_helper_) 614 if (appcache_helper_)
609 appcache_helper_->CancelNotification(); 615 appcache_helper_->CancelNotification();
610 if (indexed_db_helper_) 616 if (indexed_db_helper_)
611 indexed_db_helper_->CancelNotification(); 617 indexed_db_helper_->CancelNotification();
612 if (file_system_helper_) 618 if (file_system_helper_)
613 file_system_helper_->CancelNotification(); 619 file_system_helper_->CancelNotification();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: 655 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB:
650 return DATABASE; // ditto 656 return DATABASE; // ditto
651 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: 657 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM:
652 return DATABASE; // ditto 658 return DATABASE; // ditto
653 default: 659 default:
654 break; 660 break;
655 } 661 }
656 return -1; 662 return -1;
657 } 663 }
658 664
659 void CookiesTreeModel::LoadCookies() {
660 LoadCookiesWithFilter(std::wstring());
661 }
662
663 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) {
664 // mmargh mmargh mmargh! delicious!
665
666 all_cookies_ = cookie_monster_->GetAllCookies();
667 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
668 for (CookieList::iterator it = all_cookies_.begin();
669 it != all_cookies_.end(); ++it) {
670 std::string source_string = it->Source();
671 if (source_string.empty() || !use_cookie_source_) {
672 std::string domain = it->Domain();
673 if (domain.length() > 1 && domain[0] == '.')
674 domain = domain.substr(1);
675
676 // We treat secure cookies just the same as normal ones.
677 source_string = std::string(chrome::kHttpScheme) +
678 chrome::kStandardSchemeSeparator + domain + "/";
679 }
680
681 GURL source(source_string);
682 if (!filter.size() ||
683 (CookieTreeOriginNode::TitleForUrl(source).find(filter) !=
684 std::string::npos)) {
685 CookieTreeOriginNode* origin_node =
686 root->GetOrCreateOriginNode(source);
687 CookieTreeCookiesNode* cookies_node =
688 origin_node->GetOrCreateCookiesNode();
689 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it);
690 cookies_node->AddCookieNode(new_cookie);
691 }
692 }
693 }
694
695 void CookiesTreeModel::DeleteAllStoredObjects() { 665 void CookiesTreeModel::DeleteAllStoredObjects() {
696 NotifyObserverBeginBatch(); 666 NotifyObserverBeginBatch();
697 CookieTreeNode* root = GetRoot(); 667 CookieTreeNode* root = GetRoot();
698 root->DeleteStoredObjects(); 668 root->DeleteStoredObjects();
699 int num_children = root->child_count(); 669 int num_children = root->child_count();
700 for (int i = num_children - 1; i >= 0; --i) 670 for (int i = num_children - 1; i >= 0; --i)
701 delete Remove(root, root->GetChild(i)); 671 delete Remove(root, root->GetChild(i));
702 NotifyObserverTreeNodeChanged(root); 672 NotifyObserverTreeNodeChanged(root);
703 NotifyObserverEndBatch(); 673 NotifyObserverEndBatch();
704 } 674 }
705 675
706 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) { 676 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) {
707 if (cookie_node == GetRoot()) 677 if (cookie_node == GetRoot())
708 return; 678 return;
709 cookie_node->DeleteStoredObjects(); 679 cookie_node->DeleteStoredObjects();
710 CookieTreeNode* parent_node = cookie_node->parent(); 680 CookieTreeNode* parent_node = cookie_node->parent();
711 delete Remove(parent_node, cookie_node); 681 delete Remove(parent_node, cookie_node);
712 if (parent_node->empty()) 682 if (parent_node->empty())
713 DeleteCookieNode(parent_node); 683 DeleteCookieNode(parent_node);
714 } 684 }
715 685
716 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) { 686 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) {
717 CookieTreeNode* root = GetRoot(); 687 CookieTreeNode* root = GetRoot();
718 int num_children = root->child_count(); 688 int num_children = root->child_count();
719 NotifyObserverBeginBatch(); 689 NotifyObserverBeginBatch();
720 for (int i = num_children - 1; i >= 0; --i) 690 for (int i = num_children - 1; i >= 0; --i)
721 delete Remove(root, root->GetChild(i)); 691 delete Remove(root, root->GetChild(i));
722 LoadCookiesWithFilter(filter); 692 PopulateCookieInfoWithFilter(filter);
723 PopulateDatabaseInfoWithFilter(filter); 693 PopulateDatabaseInfoWithFilter(filter);
724 PopulateLocalStorageInfoWithFilter(filter); 694 PopulateLocalStorageInfoWithFilter(filter);
725 PopulateSessionStorageInfoWithFilter(filter); 695 PopulateSessionStorageInfoWithFilter(filter);
726 PopulateAppCacheInfoWithFilter(filter); 696 PopulateAppCacheInfoWithFilter(filter);
727 PopulateIndexedDBInfoWithFilter(filter); 697 PopulateIndexedDBInfoWithFilter(filter);
728 PopulateFileSystemInfoWithFilter(filter); 698 PopulateFileSystemInfoWithFilter(filter);
729 NotifyObserverTreeNodeChanged(root); 699 NotifyObserverTreeNodeChanged(root);
730 NotifyObserverEndBatch(); 700 NotifyObserverEndBatch();
731 } 701 }
732 702
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 info != origin->second.end(); ++info) { 743 info != origin->second.end(); ++info) {
774 appcaches_node->AddAppCacheNode( 744 appcaches_node->AddAppCacheNode(
775 new CookieTreeAppCacheNode(&(*info))); 745 new CookieTreeAppCacheNode(&(*info)));
776 } 746 }
777 } 747 }
778 } 748 }
779 NotifyObserverTreeNodeChanged(root); 749 NotifyObserverTreeNodeChanged(root);
780 NotifyObserverEndBatch(); 750 NotifyObserverEndBatch();
781 } 751 }
782 752
753 void CookiesTreeModel::OnCookiesModelInfoLoaded(
754 const CookieList& cookie_list) {
755 cookie_list_ = cookie_list;
756 PopulateCookieInfoWithFilter(std::wstring());
757 }
758
759 void CookiesTreeModel::PopulateCookieInfoWithFilter(
760 const std::wstring& filter) {
761 // mmargh mmargh mmargh! delicious!
762
763 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
764 for (CookieList::iterator it = cookie_list_.begin();
765 it != cookie_list_.end(); ++it) {
766 std::string source_string = it->Source();
767 if (source_string.empty() || !use_cookie_source_) {
768 std::string domain = it->Domain();
769 if (domain.length() > 1 && domain[0] == '.')
770 domain = domain.substr(1);
771
772 // We treat secure cookies just the same as normal ones.
773 source_string = std::string(chrome::kHttpScheme) +
774 chrome::kStandardSchemeSeparator + domain + "/";
775 }
776
777 GURL source(source_string);
778 if (!filter.size() ||
779 (CookieTreeOriginNode::TitleForUrl(source).find(filter) !=
780 std::string::npos)) {
781 CookieTreeOriginNode* origin_node =
782 root->GetOrCreateOriginNode(source);
783 CookieTreeCookiesNode* cookies_node =
784 origin_node->GetOrCreateCookiesNode();
785 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it);
786 cookies_node->AddCookieNode(new_cookie);
787 }
788 }
789 }
790
783 void CookiesTreeModel::OnDatabaseModelInfoLoaded( 791 void CookiesTreeModel::OnDatabaseModelInfoLoaded(
784 const DatabaseInfoList& database_info) { 792 const DatabaseInfoList& database_info) {
785 database_info_list_ = database_info; 793 database_info_list_ = database_info;
786 PopulateDatabaseInfoWithFilter(std::wstring()); 794 PopulateDatabaseInfoWithFilter(std::wstring());
787 } 795 }
788 796
789 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( 797 void CookiesTreeModel::PopulateDatabaseInfoWithFilter(
790 const std::wstring& filter) { 798 const std::wstring& filter) {
791 if (database_info_list_.empty()) 799 if (database_info_list_.empty())
792 return; 800 return;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 963
956 void CookiesTreeModel::NotifyObserverEndBatch() { 964 void CookiesTreeModel::NotifyObserverEndBatch() {
957 // Only notify the observers if this is the outermost call to EndBatch() if 965 // Only notify the observers if this is the outermost call to EndBatch() if
958 // called in a nested manner. 966 // called in a nested manner.
959 if (--batch_update_ == 0) { 967 if (--batch_update_ == 0) {
960 FOR_EACH_OBSERVER(Observer, 968 FOR_EACH_OBSERVER(Observer,
961 cookies_observer_list_, 969 cookies_observer_list_,
962 TreeModelEndBatch(this)); 970 TreeModelEndBatch(this));
963 } 971 }
964 } 972 }
OLDNEW
« no previous file with comments | « chrome/browser/cookies_tree_model.h ('k') | chrome/browser/cookies_tree_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698