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 dde69a7f123fee47cc383fafd3339377482c315e..bdd0b1a8a5259f46d61e97afccdf7434f07ef0e7 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,40 +320,60 @@ 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(kRegisterableDomainField, info.registerable_domain); |
- 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)); |
- } |
+ if (!flag_enabled || dialog_disabled) { |
+ auto result = base::MakeUnique<base::DictionaryValue>(); |
+ result->SetBoolean(kFlagEnabledField, flag_enabled); |
+ result->Set(kImportantSitesField, base::MakeUnique<base::ListValue>()); |
+ ResolveJavascriptCallback(base::Value(callback_id), *result); |
+ return; |
} |
- std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
- result->SetBoolean(kFlagEnabledField, flag_enabled); |
- result->Set(kImportantSitesField, std::move(important_sites_list)); |
+ 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(); |
+ |
+ (new ImportantSitesUsageCounter( |
dominickn
2017/04/11 00:18:20
I just saw how this is used. It might be cleaner t
dullweber
2017/04/11 09:01:34
Yes that sounds better. The class can't be misused
|
+ std::move(important_sites), quota_manager, dom_storage, |
+ base::Bind(&ClearBrowsingDataHandler::OnFetchImportantSitesFinished, |
+ base::Unretained(this), callback_id))) |
+ ->RunAndDestroySelf(); |
+} |
+ |
+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(kRegisterableDomainField, info.registerable_domain); |
+ 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 << ImportantSitesUtil::ImportantReason::NOTIFICATIONS)) != 0; |
+ entry->SetBoolean(kHasNotificationsField, has_notifications); |
+ important_sites_list->Append(std::move(entry)); |
+ } |
- ResolveJavascriptCallback(*callback_id, *result); |
+ auto result = base::MakeUnique<base::DictionaryValue>(); |
+ result->SetBoolean(kFlagEnabledField, true); |
+ result->Set(kImportantSitesField, std::move(important_sites_list)); |
+ ResolveJavascriptCallback(base::Value(callback_id), *result); |
} |
void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |