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

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: rebase and remove deb file Created 3 years, 7 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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/metrics/sparse_histogram.h" 14 #include "base/metrics/sparse_histogram.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/browsing_data/browsing_data_counter_factory.h" 16 #include "chrome/browser/browsing_data/browsing_data_counter_factory.h"
17 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" 17 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h"
18 #include "chrome/browser/browsing_data/browsing_data_helper.h" 18 #include "chrome/browser/browsing_data/browsing_data_helper.h"
19 #include "chrome/browser/browsing_data/browsing_data_important_sites_util.h" 19 #include "chrome/browser/browsing_data/browsing_data_important_sites_util.h"
20 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" 20 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
21 #include "chrome/browser/engagement/important_sites_usage_counter.h"
21 #include "chrome/browser/engagement/important_sites_util.h" 22 #include "chrome/browser/engagement/important_sites_util.h"
22 #include "chrome/browser/history/web_history_service_factory.h" 23 #include "chrome/browser/history/web_history_service_factory.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h" 24 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/common/channel_info.h" 25 #include "chrome/common/channel_info.h"
25 #include "chrome/common/chrome_features.h" 26 #include "chrome/common/chrome_features.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "components/browsing_data/core/history_notice_utils.h" 28 #include "components/browsing_data/core/history_notice_utils.h"
28 #include "components/browsing_data/core/pref_names.h" 29 #include "components/browsing_data/core/pref_names.h"
29 #include "components/prefs/pref_service.h" 30 #include "components/prefs/pref_service.h"
30 #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"
31 #include "content/public/browser/web_ui.h" 33 #include "content/public/browser/web_ui.h"
32 #include "ui/base/text/bytes_formatting.h" 34 #include "ui/base/text/bytes_formatting.h"
33 35
34 using ImportantReason = ImportantSitesUtil::ImportantReason; 36 using ImportantReason = ImportantSitesUtil::ImportantReason;
35 37
36 namespace { 38 namespace {
37 39
38 const int kMaxTimesHistoryNoticeShown = 1; 40 const int kMaxTimesHistoryNoticeShown = 1;
39 41
40 const int kMaxImportantSites = 10;
41
42 // TODO(msramek): Get the list of deletion preferences from the JS side. 42 // TODO(msramek): Get the list of deletion preferences from the JS side.
43 const char* kCounterPrefs[] = { 43 const char* kCounterPrefs[] = {
44 browsing_data::prefs::kDeleteBrowsingHistory, 44 browsing_data::prefs::kDeleteBrowsingHistory,
45 browsing_data::prefs::kDeleteCache, 45 browsing_data::prefs::kDeleteCache,
46 browsing_data::prefs::kDeleteDownloadHistory, 46 browsing_data::prefs::kDeleteDownloadHistory,
47 browsing_data::prefs::kDeleteFormData, 47 browsing_data::prefs::kDeleteFormData,
48 browsing_data::prefs::kDeleteHostedAppsData, 48 browsing_data::prefs::kDeleteHostedAppsData,
49 browsing_data::prefs::kDeleteMediaLicenses, 49 browsing_data::prefs::kDeleteMediaLicenses,
50 browsing_data::prefs::kDeletePasswords, 50 browsing_data::prefs::kDeletePasswords,
51 }; 51 };
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); 321 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice);
322 322
323 ResolveJavascriptCallback(base::Value(webui_callback_id), 323 ResolveJavascriptCallback(base::Value(webui_callback_id),
324 base::Value(show_notice)); 324 base::Value(show_notice));
325 task_observer_.reset(); 325 task_observer_.reset();
326 } 326 }
327 327
328 void ClearBrowsingDataHandler::HandleFetchImportantSites( 328 void ClearBrowsingDataHandler::HandleFetchImportantSites(
329 const base::ListValue* args) { 329 const base::ListValue* args) {
330 AllowJavascript(); 330 AllowJavascript();
331 const base::Value* callback_id; 331 std::string callback_id;
332 CHECK(args->Get(0, &callback_id)); 332 CHECK(args->GetString(0, &callback_id));
333 333
334 bool important_sites_flag_enabled = 334 bool important_sites_flag_enabled =
335 base::FeatureList::IsEnabled(features::kImportantSitesInCbd); 335 base::FeatureList::IsEnabled(features::kImportantSitesInCbd);
336 Profile* profile = profile_->GetOriginalProfile(); 336 Profile* profile = profile_->GetOriginalProfile();
337 bool important_sites_dialog_disabled = 337 bool important_sites_dialog_disabled =
338 ImportantSitesUtil::IsDialogDisabled(profile); 338 ImportantSitesUtil::IsDialogDisabled(profile);
339
340 if (!important_sites_flag_enabled || important_sites_dialog_disabled) {
341 base::DictionaryValue result;
342 result.SetBoolean(kFlagEnabledField, important_sites_flag_enabled);
343 result.Set(kImportantSitesField, base::MakeUnique<base::ListValue>());
344 ResolveJavascriptCallback(base::Value(callback_id), result);
345 return;
346 }
347
348 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites =
349 ImportantSitesUtil::GetImportantRegisterableDomains(
350 profile, ImportantSitesUtil::kMaxImportantSites);
351 content::StoragePartition* partition =
352 content::BrowserContext::GetDefaultStoragePartition(profile);
353 storage::QuotaManager* quota_manager = partition->GetQuotaManager();
354 content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext();
355
356 ImportantSitesUsageCounter::GetUsage(
357 std::move(important_sites), quota_manager, dom_storage,
358 base::BindOnce(&ClearBrowsingDataHandler::OnFetchImportantSitesFinished,
359 weak_ptr_factory_.GetWeakPtr(), callback_id));
360 }
361
362 void ClearBrowsingDataHandler::OnFetchImportantSitesFinished(
363 const std::string& callback_id,
364 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites) {
339 auto important_sites_list = base::MakeUnique<base::ListValue>(); 365 auto important_sites_list = base::MakeUnique<base::ListValue>();
340 366
341 if (important_sites_flag_enabled && !important_sites_dialog_disabled) { 367 for (const auto& info : important_sites) {
342 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites = 368 auto entry = base::MakeUnique<base::DictionaryValue>();
343 ImportantSitesUtil::GetImportantRegisterableDomains(profile, 369 entry->SetString(kRegisterableDomainField, info.registerable_domain);
344 kMaxImportantSites); 370 // The |reason_bitfield| is only passed to Javascript to be logged
345 for (const auto& info : important_sites) { 371 // from |HandleClearBrowsingData|.
346 auto entry = base::MakeUnique<base::DictionaryValue>(); 372 entry->SetInteger(kReasonBitField, info.reason_bitfield);
347 entry->SetString(kRegisterableDomainField, info.registerable_domain); 373 entry->SetString(kExampleOriginField, info.example_origin.spec());
348 // The |reason_bitfield| is only passed to Javascript to be logged 374 // Initially all sites are selected for deletion.
349 // from |HandleClearBrowsingData|. 375 entry->SetBoolean(kIsCheckedField, true);
350 entry->SetInteger(kReasonBitField, info.reason_bitfield); 376 entry->SetString(kStorageSizeField, ui::FormatBytes(info.usage));
351 entry->SetString(kExampleOriginField, info.example_origin.spec()); 377 bool has_notifications =
352 // Initially all sites are selected for deletion. 378 (info.reason_bitfield & (1 << ImportantReason::NOTIFICATIONS)) != 0;
353 entry->SetBoolean(kIsCheckedField, true); 379 entry->SetBoolean(kHasNotificationsField, has_notifications);
354 // TODO(dullweber): Get size. 380 important_sites_list->Append(std::move(entry));
355 entry->SetString(kStorageSizeField, ui::FormatBytes(0));
356 bool has_notifications =
357 (info.reason_bitfield & (1 << ImportantReason::NOTIFICATIONS)) != 0;
358 entry->SetBoolean(kHasNotificationsField, has_notifications);
359 important_sites_list->Append(std::move(entry));
360 }
361 } 381 }
362 382
363 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 383 base::DictionaryValue result;
364 result->SetBoolean(kFlagEnabledField, important_sites_flag_enabled); 384 result.SetBoolean(kFlagEnabledField, true);
365 result->Set(kImportantSitesField, std::move(important_sites_list)); 385 result.Set(kImportantSitesField, std::move(important_sites_list));
366 386 ResolveJavascriptCallback(base::Value(callback_id), result);
367 ResolveJavascriptCallback(*callback_id, *result);
368 } 387 }
369 388
370 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { 389 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) {
371 AllowJavascript(); 390 AllowJavascript();
372 const base::Value* callback_id; 391 const base::Value* callback_id;
373 CHECK(args->Get(0, &callback_id)); 392 CHECK(args->Get(0, &callback_id));
374 393
375 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. 394 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450.
376 task_observer_.reset(); 395 task_observer_.reset();
377 396
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 463
445 void ClearBrowsingDataHandler::UpdateCounterText( 464 void ClearBrowsingDataHandler::UpdateCounterText(
446 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 465 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
447 CallJavascriptFunction( 466 CallJavascriptFunction(
448 "cr.webUIListenerCallback", base::Value("update-counter-text"), 467 "cr.webUIListenerCallback", base::Value("update-counter-text"),
449 base::Value(result->source()->GetPrefName()), 468 base::Value(result->source()->GetPrefName()),
450 base::Value(GetChromeCounterTextFromResult(result.get()))); 469 base::Value(GetChromeCounterTextFromResult(result.get())));
451 } 470 }
452 471
453 } // namespace settings 472 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698