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

Unified Diff: chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc

Issue 2752263003: Count site data size for important sites (Closed)
Patch Set: add localstorage to test case Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc
diff --git a/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc b/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc
index b0ae49d825ceeb741445035448351b1d4736ad6f..5bac0d0e8a69b5c114d9acc5aa177a2985499dc7 100644
--- a/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc
+++ b/chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler.cc
@@ -29,6 +29,7 @@
#include "components/browsing_data/core/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browsing_data_filter_builder.h"
+#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_ui.h"
#include "ui/base/text/bytes_formatting.h"
@@ -318,41 +319,59 @@ void ClearBrowsingDataHandler::OnClearingTaskFinished(
void ClearBrowsingDataHandler::HandleFetchImportantSites(
const base::ListValue* args) {
AllowJavascript();
- const base::Value* callback_id;
- CHECK(args->Get(0, &callback_id));
+ std::string callback_id;
+ CHECK(args->GetString(0, &callback_id));
Profile* profile = profile_->GetOriginalProfile();
bool dialog_disabled =
ImportantSitesUtil::IsDialogDisabled(profile) ||
!base::FeatureList::IsEnabled(features::kImportantSitesInCBD);
- auto important_sites_list = base::MakeUnique<base::ListValue>();
- if (!dialog_disabled) {
- std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites =
- ImportantSitesUtil::GetImportantRegisterableDomains(profile,
- kMaxImportantSites);
- for (const auto& info : important_sites) {
- auto entry = base::MakeUnique<base::DictionaryValue>();
- entry->SetString(REGISTERABLE_DOMAIN_FIELD, info.registerable_domain);
- entry->SetInteger(REASON_BITFIELD_FIELD, info.reason_bitfield);
- entry->SetString(EXAMPLE_ORIGIN_FIELD, info.example_origin.spec());
- // Initially all sites are selected for deletion.
- entry->SetBoolean(IS_CHECKED_FIELD, true);
- // TODO(dullweber): Get size.
- entry->SetString(STORAGE_SIZE_FIELD, ui::FormatBytes(0));
- bool has_notifications =
- (info.reason_bitfield &
- (1 << ImportantSitesUtil::ImportantReason::NOTIFICATIONS)) != 0;
- entry->SetBoolean(HAS_NOTIFICATIONS_FIELD, has_notifications);
- important_sites_list->Append(std::move(entry));
- }
+ if (dialog_disabled) {
+ std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
+ result->SetBoolean(DIALOG_DISABLED_FIELD, true);
+ result->Set(IMPORTANT_SITES_FIELD, base::MakeUnique<base::ListValue>());
+ ResolveJavascriptCallback(base::Value(callback_id), *result);
+ return;
+ }
+
+ std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites =
+ ImportantSitesUtil::GetImportantRegisterableDomains(profile,
+ kMaxImportantSites);
+ content::StoragePartition* partition =
+ content::BrowserContext::GetDefaultStoragePartition(profile);
+ storage::QuotaManager* quota_manager = partition->GetQuotaManager();
+ content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext();
+
+ ImportantSitesUtil::PopulateUsage(
+ quota_manager, dom_storage, std::move(important_sites),
+ base::Bind(&ClearBrowsingDataHandler::OnFetchImportantSitesFinished,
+ base::Unretained(this), callback_id));
+}
+
+void ClearBrowsingDataHandler::OnFetchImportantSitesFinished(
+ const std::string& callback_id,
+ std::vector<ImportantSitesUtil::ImportantDomainInfo> sites) {
+ auto important_sites_list = base::MakeUnique<base::ListValue>();
+ for (const auto& info : sites) {
+ auto entry = base::MakeUnique<base::DictionaryValue>();
+ entry->SetString(REGISTERABLE_DOMAIN_FIELD, info.registerable_domain);
+ entry->SetInteger(REASON_BITFIELD_FIELD, info.reason_bitfield);
+ entry->SetString(EXAMPLE_ORIGIN_FIELD, info.example_origin.spec());
+ // Initially all sites are selected for deletion.
+ entry->SetBoolean(IS_CHECKED_FIELD, true);
+ entry->SetString(STORAGE_SIZE_FIELD, ui::FormatBytes(info.usage));
+ bool has_notifications =
+ (info.reason_bitfield &
+ (1 << ImportantSitesUtil::ImportantReason::NOTIFICATIONS)) != 0;
+ entry->SetBoolean(HAS_NOTIFICATIONS_FIELD, has_notifications);
+ important_sites_list->Append(std::move(entry));
}
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
- result->SetBoolean(DIALOG_DISABLED_FIELD, dialog_disabled);
+ result->SetBoolean(DIALOG_DISABLED_FIELD, false);
result->Set(IMPORTANT_SITES_FIELD, std::move(important_sites_list));
-
- ResolveJavascriptCallback(*callback_id, *result);
+ ResolveJavascriptCallback(base::Value(callback_id), *result);
}
void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) {

Powered by Google App Engine
This is Rietveld 408576698