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

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 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/browsing_data_remover_factory.h" 20 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
21 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" 21 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
22 #include "chrome/browser/engagement/important_sites_usage_counter.h"
22 #include "chrome/browser/engagement/important_sites_util.h" 23 #include "chrome/browser/engagement/important_sites_util.h"
23 #include "chrome/browser/history/web_history_service_factory.h" 24 #include "chrome/browser/history/web_history_service_factory.h"
24 #include "chrome/browser/sync/profile_sync_service_factory.h" 25 #include "chrome/browser/sync/profile_sync_service_factory.h"
25 #include "chrome/common/channel_info.h" 26 #include "chrome/common/channel_info.h"
26 #include "chrome/common/chrome_features.h" 27 #include "chrome/common/chrome_features.h"
27 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
28 #include "components/browsing_data/core/history_notice_utils.h" 29 #include "components/browsing_data/core/history_notice_utils.h"
29 #include "components/browsing_data/core/pref_names.h" 30 #include "components/browsing_data/core/pref_names.h"
30 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
31 #include "content/public/browser/browsing_data_filter_builder.h" 32 #include "content/public/browser/browsing_data_filter_builder.h"
33 #include "content/public/browser/storage_partition.h"
32 #include "content/public/browser/web_ui.h" 34 #include "content/public/browser/web_ui.h"
33 #include "ui/base/text/bytes_formatting.h" 35 #include "ui/base/text/bytes_formatting.h"
34 36
35 using ImportantReason = ImportantSitesUtil::ImportantReason; 37 using ImportantReason = ImportantSitesUtil::ImportantReason;
36 38
37 namespace { 39 namespace {
38 40
39 const int kMaxTimesHistoryNoticeShown = 1; 41 const int kMaxTimesHistoryNoticeShown = 1;
40 42
41 const int kMaxImportantSites = 10;
42
43 // TODO(msramek): Get the list of deletion preferences from the JS side. 43 // TODO(msramek): Get the list of deletion preferences from the JS side.
44 const char* kCounterPrefs[] = { 44 const char* kCounterPrefs[] = {
45 browsing_data::prefs::kDeleteBrowsingHistory, 45 browsing_data::prefs::kDeleteBrowsingHistory,
46 browsing_data::prefs::kDeleteCache, 46 browsing_data::prefs::kDeleteCache,
47 browsing_data::prefs::kDeleteDownloadHistory, 47 browsing_data::prefs::kDeleteDownloadHistory,
48 browsing_data::prefs::kDeleteFormData, 48 browsing_data::prefs::kDeleteFormData,
49 browsing_data::prefs::kDeleteHostedAppsData, 49 browsing_data::prefs::kDeleteHostedAppsData,
50 browsing_data::prefs::kDeleteMediaLicenses, 50 browsing_data::prefs::kDeleteMediaLicenses,
51 browsing_data::prefs::kDeletePasswords, 51 browsing_data::prefs::kDeletePasswords,
52 }; 52 };
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); 313 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice);
314 314
315 ResolveJavascriptCallback(base::Value(webui_callback_id), 315 ResolveJavascriptCallback(base::Value(webui_callback_id),
316 base::Value(show_notice)); 316 base::Value(show_notice));
317 task_observer_.reset(); 317 task_observer_.reset();
318 } 318 }
319 319
320 void ClearBrowsingDataHandler::HandleFetchImportantSites( 320 void ClearBrowsingDataHandler::HandleFetchImportantSites(
321 const base::ListValue* args) { 321 const base::ListValue* args) {
322 AllowJavascript(); 322 AllowJavascript();
323 const base::Value* callback_id; 323 std::string callback_id;
324 CHECK(args->Get(0, &callback_id)); 324 CHECK(args->GetString(0, &callback_id));
325 325
326 bool important_sites_flag_enabled = 326 bool important_sites_flag_enabled =
327 base::FeatureList::IsEnabled(features::kImportantSitesInCbd); 327 base::FeatureList::IsEnabled(features::kImportantSitesInCbd);
328 Profile* profile = profile_->GetOriginalProfile(); 328 Profile* profile = profile_->GetOriginalProfile();
329 bool important_sites_dialog_disabled = 329 bool important_sites_dialog_disabled =
330 ImportantSitesUtil::IsDialogDisabled(profile); 330 ImportantSitesUtil::IsDialogDisabled(profile);
331
332 if (!important_sites_flag_enabled || important_sites_dialog_disabled) {
333 auto result = base::MakeUnique<base::DictionaryValue>();
334 result->SetBoolean(kFlagEnabledField, important_sites_flag_enabled);
335 result->Set(kImportantSitesField, base::MakeUnique<base::ListValue>());
336 ResolveJavascriptCallback(base::Value(callback_id), *result);
337 return;
338 }
339
340 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites =
341 ImportantSitesUtil::GetImportantRegisterableDomains(
342 profile, ImportantSitesUtil::kMaxImportantSites);
343 content::StoragePartition* partition =
344 content::BrowserContext::GetDefaultStoragePartition(profile);
345 storage::QuotaManager* quota_manager = partition->GetQuotaManager();
346 content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext();
347
348 ImportantSitesUsageCounter::GetUsage(
349 std::move(important_sites), quota_manager, dom_storage,
350 base::Bind(&ClearBrowsingDataHandler::OnFetchImportantSitesFinished,
351 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
352 }
353
354 void ClearBrowsingDataHandler::OnFetchImportantSitesFinished(
355 const std::string& callback_id,
356 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites) {
331 auto important_sites_list = base::MakeUnique<base::ListValue>(); 357 auto important_sites_list = base::MakeUnique<base::ListValue>();
332 358
333 if (important_sites_flag_enabled && !important_sites_dialog_disabled) { 359 for (const auto& info : important_sites) {
334 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites = 360 auto entry = base::MakeUnique<base::DictionaryValue>();
335 ImportantSitesUtil::GetImportantRegisterableDomains(profile, 361 entry->SetString(kRegisterableDomainField, info.registerable_domain);
336 kMaxImportantSites); 362 // The |reason_bitfield| is only passed to Javascript to be logged
337 for (const auto& info : important_sites) { 363 // from |HandleClearBrowsingData|.
338 auto entry = base::MakeUnique<base::DictionaryValue>(); 364 entry->SetInteger(kReasonBitField, info.reason_bitfield);
339 entry->SetString(kRegisterableDomainField, info.registerable_domain); 365 entry->SetString(kExampleOriginField, info.example_origin.spec());
340 // The |reason_bitfield| is only passed to Javascript to be logged 366 // Initially all sites are selected for deletion.
341 // from |HandleClearBrowsingData|. 367 entry->SetBoolean(kIsCheckedField, true);
342 entry->SetInteger(kReasonBitField, info.reason_bitfield); 368 entry->SetString(kStorageSizeField, ui::FormatBytes(info.usage));
343 entry->SetString(kExampleOriginField, info.example_origin.spec()); 369 bool has_notifications =
344 // Initially all sites are selected for deletion. 370 (info.reason_bitfield & (1 << ImportantReason::NOTIFICATIONS)) != 0;
345 entry->SetBoolean(kIsCheckedField, true); 371 entry->SetBoolean(kHasNotificationsField, has_notifications);
346 // TODO(dullweber): Get size. 372 important_sites_list->Append(std::move(entry));
347 entry->SetString(kStorageSizeField, ui::FormatBytes(0));
348 bool has_notifications =
349 (info.reason_bitfield & (1 << ImportantReason::NOTIFICATIONS)) != 0;
350 entry->SetBoolean(kHasNotificationsField, has_notifications);
351 important_sites_list->Append(std::move(entry));
352 }
353 } 373 }
354 374
355 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 375 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.
356 result->SetBoolean(kFlagEnabledField, important_sites_flag_enabled); 376 result->SetBoolean(kFlagEnabledField, true);
357 result->Set(kImportantSitesField, std::move(important_sites_list)); 377 result->Set(kImportantSitesField, std::move(important_sites_list));
358 378 ResolveJavascriptCallback(base::Value(callback_id), *result);
359 ResolveJavascriptCallback(*callback_id, *result);
360 } 379 }
361 380
362 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { 381 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) {
363 AllowJavascript(); 382 AllowJavascript();
364 const base::Value* callback_id; 383 const base::Value* callback_id;
365 CHECK(args->Get(0, &callback_id)); 384 CHECK(args->Get(0, &callback_id));
366 385
367 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. 386 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450.
368 task_observer_.reset(); 387 task_observer_.reset();
369 388
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 455
437 void ClearBrowsingDataHandler::UpdateCounterText( 456 void ClearBrowsingDataHandler::UpdateCounterText(
438 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 457 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
439 CallJavascriptFunction( 458 CallJavascriptFunction(
440 "cr.webUIListenerCallback", base::Value("update-counter-text"), 459 "cr.webUIListenerCallback", base::Value("update-counter-text"),
441 base::Value(result->source()->GetPrefName()), 460 base::Value(result->source()->GetPrefName()),
442 base::Value(GetChromeCounterTextFromResult(result.get()))); 461 base::Value(GetChromeCounterTextFromResult(result.get())));
443 } 462 }
444 463
445 } // namespace settings 464 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698