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