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

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

Issue 2827523003: Move BrowsingDataRemover to content/ (Closed)
Patch Set: Rebase over codereview.chromium.org/2815913005 Created 3 years, 7 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
OLDNEW
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/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 17 matching lines...) Expand all
28 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
29 #include "base/threading/sequenced_worker_pool.h" 29 #include "base/threading/sequenced_worker_pool.h"
30 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
31 #include "build/build_config.h" 31 #include "build/build_config.h"
32 #include "chrome/browser/after_startup_task_utils.h" 32 #include "chrome/browser/after_startup_task_utils.h"
33 #include "chrome/browser/apps/app_url_redirector.h" 33 #include "chrome/browser/apps/app_url_redirector.h"
34 #include "chrome/browser/browser_about_handler.h" 34 #include "chrome/browser/browser_about_handler.h"
35 #include "chrome/browser/browser_process.h" 35 #include "chrome/browser/browser_process.h"
36 #include "chrome/browser/browser_shutdown.h" 36 #include "chrome/browser/browser_shutdown.h"
37 #include "chrome/browser/browsing_data/browsing_data_helper.h" 37 #include "chrome/browser/browsing_data/browsing_data_helper.h"
38 #include "chrome/browser/browsing_data/browsing_data_remover.h"
39 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
40 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" 38 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
41 #include "chrome/browser/budget_service/budget_service_impl.h" 39 #include "chrome/browser/budget_service/budget_service_impl.h"
42 #include "chrome/browser/chrome_content_browser_client_parts.h" 40 #include "chrome/browser/chrome_content_browser_client_parts.h"
43 #include "chrome/browser/chrome_quota_permission_context.h" 41 #include "chrome/browser/chrome_quota_permission_context.h"
44 #include "chrome/browser/content_settings/cookie_settings_factory.h" 42 #include "chrome/browser/content_settings/cookie_settings_factory.h"
45 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 43 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
46 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 44 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
47 #include "chrome/browser/defaults.h" 45 #include "chrome/browser/defaults.h"
48 #include "chrome/browser/download/download_prefs.h" 46 #include "chrome/browser/download/download_prefs.h"
49 #include "chrome/browser/font_family_cache.h" 47 #include "chrome/browser/font_family_cache.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 #include "components/translate/core/common/translate_switches.h" 155 #include "components/translate/core/common/translate_switches.h"
158 #include "components/url_formatter/url_fixer.h" 156 #include "components/url_formatter/url_fixer.h"
159 #include "components/variations/variations_associated_data.h" 157 #include "components/variations/variations_associated_data.h"
160 #include "components/version_info/version_info.h" 158 #include "components/version_info/version_info.h"
161 #include "content/public/browser/browser_child_process_host.h" 159 #include "content/public/browser/browser_child_process_host.h"
162 #include "content/public/browser/browser_main_parts.h" 160 #include "content/public/browser/browser_main_parts.h"
163 #include "content/public/browser/browser_ppapi_host.h" 161 #include "content/public/browser/browser_ppapi_host.h"
164 #include "content/public/browser/browser_thread.h" 162 #include "content/public/browser/browser_thread.h"
165 #include "content/public/browser/browser_url_handler.h" 163 #include "content/public/browser/browser_url_handler.h"
166 #include "content/public/browser/browsing_data_filter_builder.h" 164 #include "content/public/browser/browsing_data_filter_builder.h"
165 #include "content/public/browser/browsing_data_remover.h"
167 #include "content/public/browser/child_process_data.h" 166 #include "content/public/browser/child_process_data.h"
168 #include "content/public/browser/child_process_security_policy.h" 167 #include "content/public/browser/child_process_security_policy.h"
169 #include "content/public/browser/client_certificate_delegate.h" 168 #include "content/public/browser/client_certificate_delegate.h"
170 #include "content/public/browser/navigation_handle.h" 169 #include "content/public/browser/navigation_handle.h"
171 #include "content/public/browser/navigation_throttle.h" 170 #include "content/public/browser/navigation_throttle.h"
172 #include "content/public/browser/render_frame_host.h" 171 #include "content/public/browser/render_frame_host.h"
173 #include "content/public/browser/render_process_host.h" 172 #include "content/public/browser/render_process_host.h"
174 #include "content/public/browser/render_view_host.h" 173 #include "content/public/browser/render_view_host.h"
175 #include "content/public/browser/resource_context.h" 174 #include "content/public/browser/resource_context.h"
176 #include "content/public/browser/site_instance.h" 175 #include "content/public/browser/site_instance.h"
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 // Enable data saver only when data saver pref is enabled and not part of 922 // Enable data saver only when data saver pref is enabled and not part of
924 // "Disabled" group of "SaveDataHeader" experiment. 923 // "Disabled" group of "SaveDataHeader" experiment.
925 return prefs->GetBoolean(prefs::kDataSaverEnabled) && 924 return prefs->GetBoolean(prefs::kDataSaverEnabled) &&
926 base::FieldTrialList::FindFullName("SaveDataHeader") 925 base::FieldTrialList::FindFullName("SaveDataHeader")
927 .compare("Disabled"); 926 .compare("Disabled");
928 } 927 }
929 928
930 // A BrowsingDataRemover::Observer that waits for |count| 929 // A BrowsingDataRemover::Observer that waits for |count|
931 // OnBrowsingDataRemoverDone() callbacks, translates them into 930 // OnBrowsingDataRemoverDone() callbacks, translates them into
932 // one base::Closure, and then destroys itself. 931 // one base::Closure, and then destroys itself.
933 class ClearSiteDataObserver : public BrowsingDataRemover::Observer { 932 class ClearSiteDataObserver : public content::BrowsingDataRemover::Observer {
934 public: 933 public:
935 explicit ClearSiteDataObserver(BrowsingDataRemover* remover, 934 explicit ClearSiteDataObserver(content::BrowsingDataRemover* remover,
936 const base::Closure& callback, 935 const base::Closure& callback,
937 int count) 936 int count)
938 : remover_(remover), callback_(callback), count_(count) { 937 : remover_(remover), callback_(callback), count_(count) {
939 remover_->AddObserver(this); 938 remover_->AddObserver(this);
940 } 939 }
941 940
942 ~ClearSiteDataObserver() override { remover_->RemoveObserver(this); } 941 ~ClearSiteDataObserver() override { remover_->RemoveObserver(this); }
943 942
944 // BrowsingDataRemover::Observer. 943 // BrowsingDataRemover::Observer.
945 void OnBrowsingDataRemoverDone() override { 944 void OnBrowsingDataRemoverDone() override {
946 DCHECK(count_); 945 DCHECK(count_);
947 if (--count_) 946 if (--count_)
948 return; 947 return;
949 948
950 callback_.Run(); 949 callback_.Run();
951 delete this; 950 delete this;
952 } 951 }
953 952
954 private: 953 private:
955 BrowsingDataRemover* remover_; 954 content::BrowsingDataRemover* remover_;
956 base::Closure callback_; 955 base::Closure callback_;
957 int count_; 956 int count_;
958 }; 957 };
959 958
960 WebContents* GetWebContents(int render_process_id, int render_frame_id) { 959 WebContents* GetWebContents(int render_process_id, int render_frame_id) {
961 RenderFrameHost* rfh = 960 RenderFrameHost* rfh =
962 RenderFrameHost::FromID(render_process_id, render_frame_id); 961 RenderFrameHost::FromID(render_process_id, render_frame_id);
963 return WebContents::FromRenderFrameHost(rfh); 962 return WebContents::FromRenderFrameHost(rfh);
964 } 963 }
965 964
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 // Handler to rewrite chrome://newtab for InstantExtended. 2762 // Handler to rewrite chrome://newtab for InstantExtended.
2764 handler->AddHandlerPair(&search::HandleNewTabURLRewrite, 2763 handler->AddHandlerPair(&search::HandleNewTabURLRewrite,
2765 &search::HandleNewTabURLReverseRewrite); 2764 &search::HandleNewTabURLReverseRewrite);
2766 #endif 2765 #endif
2767 2766
2768 // chrome: & friends. 2767 // chrome: & friends.
2769 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse); 2768 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
2770 } 2769 }
2771 2770
2772 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) { 2771 void ChromeContentBrowserClient::ClearCache(RenderFrameHost* rfh) {
2773 Profile* profile = Profile::FromBrowserContext( 2772 content::BrowsingDataRemover* remover =
2774 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext()); 2773 content::BrowserContext::GetBrowsingDataRemover(
2775 BrowsingDataRemover* remover = 2774 rfh->GetSiteInstance()->GetProcess()->GetBrowserContext());
2776 BrowsingDataRemoverFactory::GetForBrowserContext(profile);
2777 remover->Remove(base::Time(), base::Time::Max(), 2775 remover->Remove(base::Time(), base::Time::Max(),
2778 BrowsingDataRemover::DATA_TYPE_CACHE, 2776 content::BrowsingDataRemover::DATA_TYPE_CACHE,
2779 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); 2777 content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB);
2780 } 2778 }
2781 2779
2782 void ChromeContentBrowserClient::ClearSiteData( 2780 void ChromeContentBrowserClient::ClearSiteData(
2783 content::BrowserContext* browser_context, 2781 content::BrowserContext* browser_context,
2784 const url::Origin& origin, 2782 const url::Origin& origin,
2785 bool remove_cookies, 2783 bool remove_cookies,
2786 bool remove_storage, 2784 bool remove_storage,
2787 bool remove_cache, 2785 bool remove_cache,
2788 const base::Closure& callback) { 2786 const base::Closure& callback) {
2789 BrowsingDataRemover* remover = 2787 content::BrowsingDataRemover* remover =
2790 BrowsingDataRemoverFactory::GetForBrowserContext(browser_context); 2788 content::BrowserContext::GetBrowsingDataRemover(browser_context);
2791 2789
2792 // ClearSiteDataObserver deletes itself when callbacks from both removal 2790 // ClearSiteDataObserver deletes itself when callbacks from both removal
2793 // tasks are received. 2791 // tasks are received.
2794 ClearSiteDataObserver* observer = 2792 ClearSiteDataObserver* observer =
2795 new ClearSiteDataObserver(remover, callback, 2 /* number of tasks */); 2793 new ClearSiteDataObserver(remover, callback, 2 /* number of tasks */);
2796 2794
2797 // Cookies and channel IDs are scoped to 2795 // Cookies and channel IDs are scoped to
2798 // a) eTLD+1 of |origin|'s host if |origin|'s host is a registrable domain 2796 // a) eTLD+1 of |origin|'s host if |origin|'s host is a registrable domain
2799 // or a subdomain thereof 2797 // or a subdomain thereof
2800 // b) |origin|'s host exactly if it is an IP address or an internal hostname 2798 // b) |origin|'s host exactly if it is an IP address or an internal hostname
2801 // (e.g. "localhost" or "fileserver"). 2799 // (e.g. "localhost" or "fileserver").
2802 if (remove_cookies) { 2800 if (remove_cookies) {
2803 std::string domain = GetDomainAndRegistry( 2801 std::string domain = GetDomainAndRegistry(
2804 origin.host(), 2802 origin.host(),
2805 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 2803 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
2806 2804
2807 if (domain.empty()) 2805 if (domain.empty())
2808 domain = origin.host(); // IP address or internal hostname. 2806 domain = origin.host(); // IP address or internal hostname.
2809 2807
2810 std::unique_ptr<BrowsingDataFilterBuilder> domain_filter_builder( 2808 std::unique_ptr<BrowsingDataFilterBuilder> domain_filter_builder(
2811 BrowsingDataFilterBuilder::Create( 2809 BrowsingDataFilterBuilder::Create(
2812 BrowsingDataFilterBuilder::WHITELIST)); 2810 BrowsingDataFilterBuilder::WHITELIST));
2813 domain_filter_builder->AddRegisterableDomain(domain); 2811 domain_filter_builder->AddRegisterableDomain(domain);
2814 2812
2815 remover->RemoveWithFilterAndReply( 2813 remover->RemoveWithFilterAndReply(
2816 base::Time(), base::Time::Max(), 2814 base::Time(), base::Time::Max(),
2817 BrowsingDataRemover::DATA_TYPE_COOKIES | 2815 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
2818 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS | 2816 content::BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS |
2819 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA, 2817 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA,
2820 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, 2818 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
2821 std::move(domain_filter_builder), observer); 2819 std::move(domain_filter_builder), observer);
2822 } else { 2820 } else {
2823 // The first removal task is a no-op. 2821 // The first removal task is a no-op.
2824 observer->OnBrowsingDataRemoverDone(); 2822 observer->OnBrowsingDataRemoverDone();
2825 } 2823 }
2826 2824
2827 // Delete origin-scoped data. 2825 // Delete origin-scoped data.
2828 int remove_mask = 0; 2826 int remove_mask = 0;
2829 if (remove_storage) 2827 if (remove_storage)
2830 remove_mask |= BrowsingDataRemover::DATA_TYPE_DOM_STORAGE; 2828 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_DOM_STORAGE;
2831 if (remove_cache) 2829 if (remove_cache)
2832 remove_mask |= BrowsingDataRemover::DATA_TYPE_CACHE; 2830 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE;
2833 2831
2834 if (remove_mask) { 2832 if (remove_mask) {
2835 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder( 2833 std::unique_ptr<BrowsingDataFilterBuilder> origin_filter_builder(
2836 BrowsingDataFilterBuilder::Create( 2834 BrowsingDataFilterBuilder::Create(
2837 BrowsingDataFilterBuilder::WHITELIST)); 2835 BrowsingDataFilterBuilder::WHITELIST));
2838 origin_filter_builder->AddOrigin(origin); 2836 origin_filter_builder->AddOrigin(origin);
2839 2837
2840 remover->RemoveWithFilterAndReply( 2838 remover->RemoveWithFilterAndReply(
2841 base::Time(), base::Time::Max(), remove_mask, 2839 base::Time(), base::Time::Max(), remove_mask,
2842 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES, 2840 ChromeBrowsingDataRemoverDelegate::ALL_ORIGIN_TYPES,
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
3617 RedirectNonUINonIOBrowserThreadsToTaskScheduler() { 3615 RedirectNonUINonIOBrowserThreadsToTaskScheduler() {
3618 return variations::GetVariationParamValue( 3616 return variations::GetVariationParamValue(
3619 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true"; 3617 "BrowserScheduler", "RedirectNonUINonIOBrowserThreads") == "true";
3620 } 3618 }
3621 3619
3622 // static 3620 // static
3623 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( 3621 void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting(
3624 const storage::QuotaSettings* settings) { 3622 const storage::QuotaSettings* settings) {
3625 g_default_quota_settings = settings; 3623 g_default_quota_settings = settings;
3626 } 3624 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698