OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/options/clear_browser_data_handler.h" | 5 #include "chrome/browser/ui/webui/options/clear_browser_data_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/values.h" | 21 #include "base/values.h" |
22 #include "chrome/app/chrome_command_ids.h" | 22 #include "chrome/app/chrome_command_ids.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/browsing_data/browsing_data_counter_factory.h" | 24 #include "chrome/browser/browsing_data/browsing_data_counter_factory.h" |
25 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | 25 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
26 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 26 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
27 #include "chrome/browser/browsing_data/browsing_data_remover.h" | |
28 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
29 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" | 27 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
30 #include "chrome/browser/history/web_history_service_factory.h" | 28 #include "chrome/browser/history/web_history_service_factory.h" |
31 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 29 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
32 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/sync/profile_sync_service_factory.h" | 31 #include "chrome/browser/sync/profile_sync_service_factory.h" |
34 #include "chrome/browser/ui/accelerator_utils.h" | 32 #include "chrome/browser/ui/accelerator_utils.h" |
35 #include "chrome/common/channel_info.h" | 33 #include "chrome/common/channel_info.h" |
36 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
37 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
38 #include "chrome/grit/locale_settings.h" | 36 #include "chrome/grit/locale_settings.h" |
39 #include "components/browsing_data/core/counters/browsing_data_counter.h" | 37 #include "components/browsing_data/core/counters/browsing_data_counter.h" |
40 #include "components/browsing_data/core/history_notice_utils.h" | 38 #include "components/browsing_data/core/history_notice_utils.h" |
41 #include "components/browsing_data/core/pref_names.h" | 39 #include "components/browsing_data/core/pref_names.h" |
42 #include "components/google/core/browser/google_util.h" | 40 #include "components/google/core/browser/google_util.h" |
43 #include "components/prefs/pref_service.h" | 41 #include "components/prefs/pref_service.h" |
| 42 #include "content/public/browser/browsing_data_remover.h" |
44 #include "content/public/browser/notification_details.h" | 43 #include "content/public/browser/notification_details.h" |
45 #include "content/public/browser/web_ui.h" | 44 #include "content/public/browser/web_ui.h" |
46 #include "ui/base/accelerators/accelerator.h" | 45 #include "ui/base/accelerators/accelerator.h" |
47 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
48 #include "ui/events/keycodes/keyboard_codes.h" | 47 #include "ui/events/keycodes/keyboard_codes.h" |
49 | 48 |
50 namespace { | 49 namespace { |
51 | 50 |
52 const char kClearBrowsingDataLearnMoreUrl[] = | 51 const char kClearBrowsingDataLearnMoreUrl[] = |
53 "https://support.google.com/chrome/?p=settings_clear_browsing_data"; | 52 "https://support.google.com/chrome/?p=settings_clear_browsing_data"; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 site_data_mask &= ~ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA; | 252 site_data_mask &= ~ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PLUGIN_DATA; |
254 | 253 |
255 int remove_mask = 0; | 254 int remove_mask = 0; |
256 int origin_mask = 0; | 255 int origin_mask = 0; |
257 if (prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory) && | 256 if (prefs->GetBoolean(browsing_data::prefs::kDeleteBrowsingHistory) && |
258 *allow_deleting_browser_history_) { | 257 *allow_deleting_browser_history_) { |
259 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY; | 258 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY; |
260 } | 259 } |
261 if (prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory) && | 260 if (prefs->GetBoolean(browsing_data::prefs::kDeleteDownloadHistory) && |
262 *allow_deleting_browser_history_) { | 261 *allow_deleting_browser_history_) { |
263 remove_mask |= BrowsingDataRemover::DATA_TYPE_DOWNLOADS; | 262 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_DOWNLOADS; |
264 } | 263 } |
265 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) | 264 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) |
266 remove_mask |= BrowsingDataRemover::DATA_TYPE_CACHE; | 265 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_CACHE; |
267 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { | 266 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { |
268 remove_mask |= site_data_mask; | 267 remove_mask |= site_data_mask; |
269 origin_mask |= BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; | 268 origin_mask |= content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; |
270 } | 269 } |
271 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) | 270 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) |
272 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PASSWORDS; | 271 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_PASSWORDS; |
273 if (prefs->GetBoolean(browsing_data::prefs::kDeleteFormData)) | 272 if (prefs->GetBoolean(browsing_data::prefs::kDeleteFormData)) |
274 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_FORM_DATA; | 273 remove_mask |= ChromeBrowsingDataRemoverDelegate::DATA_TYPE_FORM_DATA; |
275 if (prefs->GetBoolean(browsing_data::prefs::kDeleteMediaLicenses)) | 274 if (prefs->GetBoolean(browsing_data::prefs::kDeleteMediaLicenses)) |
276 remove_mask |= BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES; | 275 remove_mask |= content::BrowsingDataRemover::DATA_TYPE_MEDIA_LICENSES; |
277 if (prefs->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData)) { | 276 if (prefs->GetBoolean(browsing_data::prefs::kDeleteHostedAppsData)) { |
278 remove_mask |= site_data_mask; | 277 remove_mask |= site_data_mask; |
279 origin_mask |= BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; | 278 origin_mask |= content::BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; |
280 } | 279 } |
281 | 280 |
282 // Record the deletion of cookies and cache. | 281 // Record the deletion of cookies and cache. |
283 BrowsingDataRemover::CookieOrCacheDeletionChoice choice = | 282 content::BrowsingDataRemover::CookieOrCacheDeletionChoice choice = |
284 BrowsingDataRemover::NEITHER_COOKIES_NOR_CACHE; | 283 content::BrowsingDataRemover::NEITHER_COOKIES_NOR_CACHE; |
285 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { | 284 if (prefs->GetBoolean(browsing_data::prefs::kDeleteCookies)) { |
286 choice = prefs->GetBoolean(browsing_data::prefs::kDeleteCache) | 285 choice = prefs->GetBoolean(browsing_data::prefs::kDeleteCache) |
287 ? BrowsingDataRemover::BOTH_COOKIES_AND_CACHE | 286 ? content::BrowsingDataRemover::BOTH_COOKIES_AND_CACHE |
288 : BrowsingDataRemover::ONLY_COOKIES; | 287 : content::BrowsingDataRemover::ONLY_COOKIES; |
289 } else if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) { | 288 } else if (prefs->GetBoolean(browsing_data::prefs::kDeleteCache)) { |
290 choice = BrowsingDataRemover::ONLY_CACHE; | 289 choice = content::BrowsingDataRemover::ONLY_CACHE; |
291 } | 290 } |
292 UMA_HISTOGRAM_ENUMERATION( | 291 UMA_HISTOGRAM_ENUMERATION( |
293 "History.ClearBrowsingData.UserDeletedCookieOrCacheFromDialog", | 292 "History.ClearBrowsingData.UserDeletedCookieOrCacheFromDialog", choice, |
294 choice, BrowsingDataRemover::MAX_CHOICE_VALUE); | 293 content::BrowsingDataRemover::MAX_CHOICE_VALUE); |
295 | 294 |
296 // Record the circumstances under which passwords are deleted. | 295 // Record the circumstances under which passwords are deleted. |
297 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) { | 296 if (prefs->GetBoolean(browsing_data::prefs::kDeletePasswords)) { |
298 static const char* other_types[] = { | 297 static const char* other_types[] = { |
299 browsing_data::prefs::kDeleteBrowsingHistory, | 298 browsing_data::prefs::kDeleteBrowsingHistory, |
300 browsing_data::prefs::kDeleteDownloadHistory, | 299 browsing_data::prefs::kDeleteDownloadHistory, |
301 browsing_data::prefs::kDeleteCache, | 300 browsing_data::prefs::kDeleteCache, |
302 browsing_data::prefs::kDeleteCookies, | 301 browsing_data::prefs::kDeleteCookies, |
303 browsing_data::prefs::kDeleteFormData, | 302 browsing_data::prefs::kDeleteFormData, |
304 browsing_data::prefs::kDeleteHostedAppsData, | 303 browsing_data::prefs::kDeleteHostedAppsData, |
305 browsing_data::prefs::kDeleteMediaLicenses, | 304 browsing_data::prefs::kDeleteMediaLicenses, |
306 }; | 305 }; |
307 static size_t num_other_types = arraysize(other_types); | 306 static size_t num_other_types = arraysize(other_types); |
308 int checked_other_types = std::count_if( | 307 int checked_other_types = std::count_if( |
309 other_types, | 308 other_types, |
310 other_types + num_other_types, | 309 other_types + num_other_types, |
311 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 310 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
312 UMA_HISTOGRAM_SPARSE_SLOWLY( | 311 UMA_HISTOGRAM_SPARSE_SLOWLY( |
313 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 312 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
314 checked_other_types); | 313 checked_other_types); |
315 } | 314 } |
316 | 315 |
317 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile); | 316 remover_ = content::BrowserContext::GetBrowsingDataRemover(profile); |
318 remover_->AddObserver(this); | 317 remover_->AddObserver(this); |
319 int period_selected = | 318 int period_selected = |
320 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 319 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
321 browsing_data::TimePeriod time_period = | 320 browsing_data::TimePeriod time_period = |
322 static_cast<browsing_data::TimePeriod>(period_selected); | 321 static_cast<browsing_data::TimePeriod>(period_selected); |
323 browsing_data::RecordDeletionForPeriod(time_period); | 322 browsing_data::RecordDeletionForPeriod(time_period); |
324 remover_->RemoveAndReply( | 323 remover_->RemoveAndReply( |
325 browsing_data::CalculateBeginDeleteTime(time_period), | 324 browsing_data::CalculateBeginDeleteTime(time_period), |
326 browsing_data::CalculateEndDeleteTime(time_period), | 325 browsing_data::CalculateEndDeleteTime(time_period), |
327 remove_mask, origin_mask, this); | 326 remove_mask, origin_mask, this); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 432 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
434 should_show_history_notice_); | 433 should_show_history_notice_); |
435 } | 434 } |
436 | 435 |
437 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { | 436 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { |
438 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). | 437 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). |
439 should_show_history_deletion_dialog_ = show; | 438 should_show_history_deletion_dialog_ = show; |
440 } | 439 } |
441 | 440 |
442 } // namespace options | 441 } // namespace options |
OLD | NEW |