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

Side by Side 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, 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler. h" 5 #include "chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler. h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/engagement/important_sites_util.h" 22 #include "chrome/browser/engagement/important_sites_util.h"
23 #include "chrome/browser/history/web_history_service_factory.h" 23 #include "chrome/browser/history/web_history_service_factory.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/common/channel_info.h" 25 #include "chrome/common/channel_info.h"
26 #include "chrome/common/chrome_features.h" 26 #include "chrome/common/chrome_features.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "components/browsing_data/core/history_notice_utils.h" 28 #include "components/browsing_data/core/history_notice_utils.h"
29 #include "components/browsing_data/core/pref_names.h" 29 #include "components/browsing_data/core/pref_names.h"
30 #include "components/prefs/pref_service.h" 30 #include "components/prefs/pref_service.h"
31 #include "content/public/browser/browsing_data_filter_builder.h" 31 #include "content/public/browser/browsing_data_filter_builder.h"
32 #include "content/public/browser/storage_partition.h"
32 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
33 #include "ui/base/text/bytes_formatting.h" 34 #include "ui/base/text/bytes_formatting.h"
34 35
35 namespace { 36 namespace {
36 37
37 const int kMaxTimesHistoryNoticeShown = 1; 38 const int kMaxTimesHistoryNoticeShown = 1;
38 39
39 const int kMaxImportantSites = 10;
40
41 // TODO(msramek): Get the list of deletion preferences from the JS side. 40 // TODO(msramek): Get the list of deletion preferences from the JS side.
42 const char* kCounterPrefs[] = { 41 const char* kCounterPrefs[] = {
43 browsing_data::prefs::kDeleteBrowsingHistory, 42 browsing_data::prefs::kDeleteBrowsingHistory,
44 browsing_data::prefs::kDeleteCache, 43 browsing_data::prefs::kDeleteCache,
45 browsing_data::prefs::kDeleteDownloadHistory, 44 browsing_data::prefs::kDeleteDownloadHistory,
46 browsing_data::prefs::kDeleteFormData, 45 browsing_data::prefs::kDeleteFormData,
47 browsing_data::prefs::kDeleteHostedAppsData, 46 browsing_data::prefs::kDeleteHostedAppsData,
48 browsing_data::prefs::kDeleteMediaLicenses, 47 browsing_data::prefs::kDeleteMediaLicenses,
49 browsing_data::prefs::kDeletePasswords, 48 browsing_data::prefs::kDeletePasswords,
50 }; 49 };
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); 310 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice);
312 311
313 ResolveJavascriptCallback(base::Value(webui_callback_id), 312 ResolveJavascriptCallback(base::Value(webui_callback_id),
314 base::Value(show_notice)); 313 base::Value(show_notice));
315 task_observer_.reset(); 314 task_observer_.reset();
316 } 315 }
317 316
318 void ClearBrowsingDataHandler::HandleFetchImportantSites( 317 void ClearBrowsingDataHandler::HandleFetchImportantSites(
319 const base::ListValue* args) { 318 const base::ListValue* args) {
320 AllowJavascript(); 319 AllowJavascript();
321 const base::Value* callback_id; 320 std::string callback_id;
322 CHECK(args->Get(0, &callback_id)); 321 CHECK(args->GetString(0, &callback_id));
323 322
324 Profile* profile = profile_->GetOriginalProfile(); 323 Profile* profile = profile_->GetOriginalProfile();
325 bool flag_enabled = 324 bool flag_enabled =
326 base::FeatureList::IsEnabled(features::kImportantSitesInCBD); 325 base::FeatureList::IsEnabled(features::kImportantSitesInCBD);
327 bool dialog_disabled = ImportantSitesUtil::IsDialogDisabled(profile); 326 bool dialog_disabled = ImportantSitesUtil::IsDialogDisabled(profile);
327
328 if (!flag_enabled || dialog_disabled) {
329 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.
330 result->SetBoolean(FLAG_ENABLED_FIELD, flag_enabled);
331 result->Set(IMPORTANT_SITES_FIELD, base::MakeUnique<base::ListValue>());
332 ResolveJavascriptCallback(base::Value(callback_id), *result);
333 return;
334 }
335
336 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites =
337 ImportantSitesUtil::GetImportantRegisterableDomains(
338 profile, ImportantSitesUtil::kMaxImportantSites);
339 content::StoragePartition* partition =
340 content::BrowserContext::GetDefaultStoragePartition(profile);
341 storage::QuotaManager* quota_manager = partition->GetQuotaManager();
342 content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext();
343
344 ImportantSitesUtil::PopulateUsage(
345 quota_manager, dom_storage, std::move(important_sites),
346 base::Bind(&ClearBrowsingDataHandler::OnFetchImportantSitesFinished,
347 base::Unretained(this), callback_id));
348 }
349
350 void ClearBrowsingDataHandler::OnFetchImportantSitesFinished(
351 const std::string& callback_id,
352 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites) {
328 auto important_sites_list = base::MakeUnique<base::ListValue>(); 353 auto important_sites_list = base::MakeUnique<base::ListValue>();
329 354 for (const auto& info : sites) {
330 if (flag_enabled && !dialog_disabled) { 355 auto entry = base::MakeUnique<base::DictionaryValue>();
331 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites = 356 entry->SetString(REGISTERABLE_DOMAIN_FIELD, info.registerable_domain);
332 ImportantSitesUtil::GetImportantRegisterableDomains(profile, 357 entry->SetInteger(REASON_BITFIELD_FIELD, info.reason_bitfield);
333 kMaxImportantSites); 358 entry->SetString(EXAMPLE_ORIGIN_FIELD, info.example_origin.spec());
334 for (const auto& info : important_sites) { 359 // Initially all sites are selected for deletion.
335 auto entry = base::MakeUnique<base::DictionaryValue>(); 360 entry->SetBoolean(IS_CHECKED_FIELD, true);
336 entry->SetString(REGISTERABLE_DOMAIN_FIELD, info.registerable_domain); 361 entry->SetString(STORAGE_SIZE_FIELD, ui::FormatBytes(info.usage));
337 entry->SetInteger(REASON_BITFIELD_FIELD, info.reason_bitfield); 362 bool has_notifications =
338 entry->SetString(EXAMPLE_ORIGIN_FIELD, info.example_origin.spec()); 363 (info.reason_bitfield &
339 // Initially all sites are selected for deletion. 364 (1 << ImportantSitesUtil::ImportantReason::NOTIFICATIONS)) != 0;
340 entry->SetBoolean(IS_CHECKED_FIELD, true); 365 entry->SetBoolean(HAS_NOTIFICATIONS_FIELD, has_notifications);
341 // TODO(dullweber): Get size. 366 important_sites_list->Append(std::move(entry));
342 entry->SetString(STORAGE_SIZE_FIELD, ui::FormatBytes(0));
343 bool has_notifications =
344 (info.reason_bitfield &
345 (1 << ImportantSitesUtil::ImportantReason::NOTIFICATIONS)) != 0;
346 entry->SetBoolean(HAS_NOTIFICATIONS_FIELD, has_notifications);
347 important_sites_list->Append(std::move(entry));
348 }
349 } 367 }
350 368
351 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 369 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
352 result->SetBoolean(FLAG_ENABLED_FIELD, flag_enabled); 370 result->SetBoolean(FLAG_ENABLED_FIELD, true);
353 result->Set(IMPORTANT_SITES_FIELD, std::move(important_sites_list)); 371 result->Set(IMPORTANT_SITES_FIELD, std::move(important_sites_list));
354 372 ResolveJavascriptCallback(base::Value(callback_id), *result);
355 ResolveJavascriptCallback(*callback_id, *result);
356 } 373 }
357 374
358 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { 375 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) {
359 AllowJavascript(); 376 AllowJavascript();
360 const base::Value* callback_id; 377 const base::Value* callback_id;
361 CHECK(args->Get(0, &callback_id)); 378 CHECK(args->Get(0, &callback_id));
362 379
363 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. 380 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450.
364 task_observer_.reset(); 381 task_observer_.reset();
365 382
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 451
435 void ClearBrowsingDataHandler::UpdateCounterText( 452 void ClearBrowsingDataHandler::UpdateCounterText(
436 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 453 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
437 CallJavascriptFunction( 454 CallJavascriptFunction(
438 "cr.webUIListenerCallback", base::Value("update-counter-text"), 455 "cr.webUIListenerCallback", base::Value("update-counter-text"),
439 base::Value(result->source()->GetPrefName()), 456 base::Value(result->source()->GetPrefName()),
440 base::Value(GetChromeCounterTextFromResult(result.get()))); 457 base::Value(GetChromeCounterTextFromResult(result.get())));
441 } 458 }
442 459
443 } // namespace settings 460 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698