OLD | NEW |
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 Loading... |
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 const int kMaxImportantSites = 10; |
40 | 41 |
41 // 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. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); | 312 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); |
312 | 313 |
313 ResolveJavascriptCallback(base::Value(webui_callback_id), | 314 ResolveJavascriptCallback(base::Value(webui_callback_id), |
314 base::Value(show_notice)); | 315 base::Value(show_notice)); |
315 task_observer_.reset(); | 316 task_observer_.reset(); |
316 } | 317 } |
317 | 318 |
318 void ClearBrowsingDataHandler::HandleFetchImportantSites( | 319 void ClearBrowsingDataHandler::HandleFetchImportantSites( |
319 const base::ListValue* args) { | 320 const base::ListValue* args) { |
320 AllowJavascript(); | 321 AllowJavascript(); |
321 const base::Value* callback_id; | 322 std::string callback_id; |
322 CHECK(args->Get(0, &callback_id)); | 323 CHECK(args->GetString(0, &callback_id)); |
323 | 324 |
324 Profile* profile = profile_->GetOriginalProfile(); | 325 Profile* profile = profile_->GetOriginalProfile(); |
325 bool dialog_disabled = | 326 bool dialog_disabled = |
326 ImportantSitesUtil::IsDialogDisabled(profile) || | 327 ImportantSitesUtil::IsDialogDisabled(profile) || |
327 !base::FeatureList::IsEnabled(features::kImportantSitesInCBD); | 328 !base::FeatureList::IsEnabled(features::kImportantSitesInCBD); |
| 329 |
| 330 if (dialog_disabled) { |
| 331 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 332 result->SetBoolean(DIALOG_DISABLED_FIELD, true); |
| 333 result->Set(IMPORTANT_SITES_FIELD, base::MakeUnique<base::ListValue>()); |
| 334 ResolveJavascriptCallback(base::Value(callback_id), *result); |
| 335 return; |
| 336 } |
| 337 |
| 338 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites = |
| 339 ImportantSitesUtil::GetImportantRegisterableDomains(profile, |
| 340 kMaxImportantSites); |
| 341 content::StoragePartition* partition = |
| 342 content::BrowserContext::GetDefaultStoragePartition(profile); |
| 343 storage::QuotaManager* quota_manager = partition->GetQuotaManager(); |
| 344 content::DOMStorageContext* dom_storage = partition->GetDOMStorageContext(); |
| 345 |
| 346 ImportantSitesUtil::PopulateUsage( |
| 347 quota_manager, dom_storage, std::move(important_sites), |
| 348 base::Bind(&ClearBrowsingDataHandler::OnFetchImportantSitesFinished, |
| 349 base::Unretained(this), callback_id)); |
| 350 } |
| 351 |
| 352 void ClearBrowsingDataHandler::OnFetchImportantSitesFinished( |
| 353 const std::string& callback_id, |
| 354 std::vector<ImportantSitesUtil::ImportantDomainInfo> sites) { |
328 auto important_sites_list = base::MakeUnique<base::ListValue>(); | 355 auto important_sites_list = base::MakeUnique<base::ListValue>(); |
329 | 356 for (const auto& info : sites) { |
330 if (!dialog_disabled) { | 357 auto entry = base::MakeUnique<base::DictionaryValue>(); |
331 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_sites = | 358 entry->SetString(REGISTERABLE_DOMAIN_FIELD, info.registerable_domain); |
332 ImportantSitesUtil::GetImportantRegisterableDomains(profile, | 359 entry->SetInteger(REASON_BITFIELD_FIELD, info.reason_bitfield); |
333 kMaxImportantSites); | 360 entry->SetString(EXAMPLE_ORIGIN_FIELD, info.example_origin.spec()); |
334 for (const auto& info : important_sites) { | 361 // Initially all sites are selected for deletion. |
335 auto entry = base::MakeUnique<base::DictionaryValue>(); | 362 entry->SetBoolean(IS_CHECKED_FIELD, true); |
336 entry->SetString(REGISTERABLE_DOMAIN_FIELD, info.registerable_domain); | 363 entry->SetString(STORAGE_SIZE_FIELD, ui::FormatBytes(info.usage)); |
337 entry->SetInteger(REASON_BITFIELD_FIELD, info.reason_bitfield); | 364 bool has_notifications = |
338 entry->SetString(EXAMPLE_ORIGIN_FIELD, info.example_origin.spec()); | 365 (info.reason_bitfield & |
339 // Initially all sites are selected for deletion. | 366 (1 << ImportantSitesUtil::ImportantReason::NOTIFICATIONS)) != 0; |
340 entry->SetBoolean(IS_CHECKED_FIELD, true); | 367 entry->SetBoolean(HAS_NOTIFICATIONS_FIELD, has_notifications); |
341 // TODO(dullweber): Get size. | 368 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 } | 369 } |
350 | 370 |
351 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 371 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
352 result->SetBoolean(DIALOG_DISABLED_FIELD, dialog_disabled); | 372 result->SetBoolean(DIALOG_DISABLED_FIELD, false); |
353 result->Set(IMPORTANT_SITES_FIELD, std::move(important_sites_list)); | 373 result->Set(IMPORTANT_SITES_FIELD, std::move(important_sites_list)); |
354 | 374 ResolveJavascriptCallback(base::Value(callback_id), *result); |
355 ResolveJavascriptCallback(*callback_id, *result); | |
356 } | 375 } |
357 | 376 |
358 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 377 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
359 AllowJavascript(); | 378 AllowJavascript(); |
360 const base::Value* callback_id; | 379 const base::Value* callback_id; |
361 CHECK(args->Get(0, &callback_id)); | 380 CHECK(args->Get(0, &callback_id)); |
362 | 381 |
363 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. | 382 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. |
364 task_observer_.reset(); | 383 task_observer_.reset(); |
365 | 384 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 453 |
435 void ClearBrowsingDataHandler::UpdateCounterText( | 454 void ClearBrowsingDataHandler::UpdateCounterText( |
436 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 455 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
437 CallJavascriptFunction( | 456 CallJavascriptFunction( |
438 "cr.webUIListenerCallback", base::Value("update-counter-text"), | 457 "cr.webUIListenerCallback", base::Value("update-counter-text"), |
439 base::Value(result->source()->GetPrefName()), | 458 base::Value(result->source()->GetPrefName()), |
440 base::Value(GetChromeCounterTextFromResult(result.get()))); | 459 base::Value(GetChromeCounterTextFromResult(result.get()))); |
441 } | 460 } |
442 | 461 |
443 } // namespace settings | 462 } // namespace settings |
OLD | NEW |