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

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: rebase Created 3 years, 8 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 f4752a4671156dd5ec56b690e9f107dbc4d96acd..57b42dc067f53d8316581c24f2949a1c62f2ddde 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
@@ -19,6 +19,7 @@
#include "chrome/browser/browsing_data/browsing_data_important_sites_util.h"
#include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
+#include "chrome/browser/engagement/important_sites_usage_counter.h"
#include "chrome/browser/engagement/important_sites_util.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
@@ -29,6 +30,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"
@@ -38,8 +40,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,
@@ -320,43 +320,62 @@ 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));
bool important_sites_flag_enabled =
base::FeatureList::IsEnabled(features::kImportantSitesInCbd);
Profile* profile = profile_->GetOriginalProfile();
bool important_sites_dialog_disabled =
ImportantSitesUtil::IsDialogDisabled(profile);
+
+ if (!important_sites_flag_enabled || important_sites_dialog_disabled) {
+ auto result = base::MakeUnique<base::DictionaryValue>();
+ result->SetBoolean(kFlagEnabledField, important_sites_flag_enabled);
+ result->Set(kImportantSitesField, 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();
+
+ ImportantSitesUsageCounter::GetUsage(
+ std::move(important_sites), quota_manager, dom_storage,
+ base::Bind(&ClearBrowsingDataHandler::OnFetchImportantSitesFinished,
+ base::Unretained(this), callback_id));
Bernhard Bauer 2017/05/04 14:16:45 What if this object is destroyed before the callba
dullweber 2017/05/05 08:35:28 I assumed that it worked because the BrowsingDataR
+}
+
+void ClearBrowsingDataHandler::OnFetchImportantSitesFinished(
+ const std::string& callback_id,
+ std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites) {
auto important_sites_list = base::MakeUnique<base::ListValue>();
- if (important_sites_flag_enabled && !important_sites_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(kRegisterableDomainField, info.registerable_domain);
- // The |reason_bitfield| is only passed to Javascript to be logged
- // from |HandleClearBrowsingData|.
- entry->SetInteger(kReasonBitField, info.reason_bitfield);
- entry->SetString(kExampleOriginField, info.example_origin.spec());
- // Initially all sites are selected for deletion.
- entry->SetBoolean(kIsCheckedField, true);
- // TODO(dullweber): Get size.
- entry->SetString(kStorageSizeField, ui::FormatBytes(0));
- bool has_notifications =
- (info.reason_bitfield & (1 << ImportantReason::NOTIFICATIONS)) != 0;
- entry->SetBoolean(kHasNotificationsField, has_notifications);
- important_sites_list->Append(std::move(entry));
- }
+ for (const auto& info : important_sites) {
+ auto entry = base::MakeUnique<base::DictionaryValue>();
+ entry->SetString(kRegisterableDomainField, info.registerable_domain);
+ // The |reason_bitfield| is only passed to Javascript to be logged
+ // from |HandleClearBrowsingData|.
+ entry->SetInteger(kReasonBitField, info.reason_bitfield);
+ entry->SetString(kExampleOriginField, info.example_origin.spec());
+ // Initially all sites are selected for deletion.
+ entry->SetBoolean(kIsCheckedField, true);
+ entry->SetString(kStorageSizeField, ui::FormatBytes(info.usage));
+ bool has_notifications =
+ (info.reason_bitfield & (1 << ImportantReason::NOTIFICATIONS)) != 0;
+ entry->SetBoolean(kHasNotificationsField, has_notifications);
+ important_sites_list->Append(std::move(entry));
}
- std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
- result->SetBoolean(kFlagEnabledField, important_sites_flag_enabled);
+ auto result = base::MakeUnique<base::DictionaryValue>();
Bernhard Bauer 2017/05/04 14:16:45 You could even stack-allocate the DictionaryValue.
dullweber 2017/05/05 08:35:28 Done.
+ result->SetBoolean(kFlagEnabledField, true);
result->Set(kImportantSitesField, 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