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

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: switch to SmallMap 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 323b17e65d73d79b5a6a669837238e8d2aa48ba3..abb9f25fffcec66a66d5581970a03ad2fc33d367 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"
@@ -36,8 +37,6 @@ namespace {
const int kMaxTimesHistoryNoticeShown = 1;
-const int kMaxImportantSites = 10;
-
// TODO(msramek): Get the list of deletion preferences from the JS side.
const char* kCounterPrefs[] = {
browsing_data::prefs::kDeleteBrowsingHistory,
@@ -318,41 +317,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 flag_enabled =
base::FeatureList::IsEnabled(features::kImportantSitesInCBD);
bool dialog_disabled = ImportantSitesUtil::IsDialogDisabled(profile);
- auto important_sites_list = base::MakeUnique<base::ListValue>();
- if (flag_enabled && !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 (!flag_enabled || dialog_disabled) {
+ std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
dominickn 2017/04/10 05:06:12 auto result = base::MakeUnique<base::DictionaryVal
dullweber 2017/04/10 13:29:39 Done.
+ result->SetBoolean(FLAG_ENABLED_FIELD, flag_enabled);
+ 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, ImportantSitesUtil::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(FLAG_ENABLED_FIELD, flag_enabled);
+ result->SetBoolean(FLAG_ENABLED_FIELD, true);
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