Chromium Code Reviews| Index: chrome/browser/ui/webui/settings/site_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/settings/site_settings_handler.cc b/chrome/browser/ui/webui/settings/site_settings_handler.cc |
| index 490b179cdd99f2faa87296836592619fefa73e0b..d939c2c08f192398c706dda2871080b0f80d7866 100644 |
| --- a/chrome/browser/ui/webui/settings/site_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/settings/site_settings_handler.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/values.h" |
| +#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "components/content_settings/core/common/content_settings_types.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -29,6 +30,10 @@ void SiteSettingsHandler::RegisterMessages() { |
| "fetchUsageTotal", |
| base::Bind(&SiteSettingsHandler::HandleFetchUsageTotal, |
| base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback( |
| + "clearUsage", |
| + base::Bind(&SiteSettingsHandler::HandleClearUsage, |
| + base::Unretained(this))); |
| } |
| void SiteSettingsHandler::OnGetUsageInfo( |
| @@ -41,23 +46,53 @@ void SiteSettingsHandler::OnGetUsageInfo( |
| web_ui()->CallJavascriptFunction( |
| "settings.WebsiteUsagePrivateApi.returnUsageTotal", |
| base::StringValue(entry.host), |
| - base::StringValue(ui::FormatBytes(entry.usage))); |
| - return; |
| + base::StringValue(ui::FormatBytes(entry.usage)), |
| + base::FundamentalValue(entry.type)); |
| } |
| } |
| } |
| +void SiteSettingsHandler::OnUsageInfoCleared() { |
| +} |
| + |
| void SiteSettingsHandler::HandleFetchUsageTotal( |
| const base::ListValue* args) { |
| CHECK_EQ(1U, args->GetSize()); |
| std::string host; |
| CHECK(args->GetString(0, &host)); |
| usage_host_ = host; |
| - storage_info_fetcher_ = new StorageInfoFetcher( |
| + storage::QuotaManager* quota_manager = |
| content::BrowserContext::GetDefaultStoragePartition( |
| - profile_)->GetQuotaManager()); |
| + profile_)->GetQuotaManager(); |
| + storage_info_fetcher_ = new StorageInfoFetcher(quota_manager); |
| storage_info_fetcher_->AddObserver(this); |
| - storage_info_fetcher_->Run(); |
| + storage_info_fetcher_->FetchStorageInfo(); |
| +} |
| + |
| +void SiteSettingsHandler::HandleClearUsage( |
| + const base::ListValue* args) { |
| + CHECK_EQ(2U, args->GetSize()); |
| + std::string origin; |
| + CHECK(args->GetString(0, &origin)); |
| + int type; |
| + CHECK(args->GetInteger(1, &type)); |
| + |
| + GURL url(origin); |
| + if (url.is_valid()) { |
| + // Start by clearing the storage data asynchronously. |
| + storage::QuotaManager* quota_manager = |
| + content::BrowserContext::GetDefaultStoragePartition( |
| + profile_)->GetQuotaManager(); |
| + storage_info_fetcher_ = new StorageInfoFetcher(quota_manager); |
|
michaelpg
2016/02/03 18:39:13
Why is it necessary to re-initialize this if it al
Finnur
2016/02/04 14:56:58
I suppose it isn't necessary. I do have an upcomin
|
| + storage_info_fetcher_->AddObserver(this); |
| + storage_info_fetcher_->ClearStorage( |
| + url.host(), static_cast<storage::StorageType>(type)); |
| + |
| + // Also clear the *local* storage data. |
| + scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper = |
| + new BrowsingDataLocalStorageHelper(profile_); |
| + local_storage_helper->DeleteOrigin(url); |
| + } |
| } |
| } // namespace settings |