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

Side by Side Diff: chrome/browser/ui/webui/options/clear_browser_data_handler.cc

Issue 2084903002: Moved BrowsingDataCounter and part of BrowsingDataCounterUtils to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed deps Created 4 years, 6 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 (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/autofill_counter.h" 24 #include "chrome/browser/browsing_data/autofill_counter.h"
25 #include "chrome/browser/browsing_data/browsing_data_counter.h"
26 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" 25 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h"
27 #include "chrome/browser/browsing_data/browsing_data_helper.h" 26 #include "chrome/browser/browsing_data/browsing_data_helper.h"
28 #include "chrome/browser/browsing_data/browsing_data_remover.h" 27 #include "chrome/browser/browsing_data/browsing_data_remover.h"
29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 28 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
30 #include "chrome/browser/browsing_data/cache_counter.h" 29 #include "chrome/browser/browsing_data/cache_counter.h"
31 #include "chrome/browser/browsing_data/history_counter.h" 30 #include "chrome/browser/browsing_data/history_counter.h"
32 #include "chrome/browser/browsing_data/passwords_counter.h" 31 #include "chrome/browser/browsing_data/passwords_counter.h"
33 #include "chrome/browser/history/web_history_service_factory.h" 32 #include "chrome/browser/history/web_history_service_factory.h"
34 #include "chrome/browser/prefs/incognito_mode_prefs.h" 33 #include "chrome/browser/prefs/incognito_mode_prefs.h"
35 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
36 #include "chrome/browser/sync/profile_sync_service_factory.h" 35 #include "chrome/browser/sync/profile_sync_service_factory.h"
37 #include "chrome/browser/ui/accelerator_utils.h" 36 #include "chrome/browser/ui/accelerator_utils.h"
38 #include "chrome/common/channel_info.h" 37 #include "chrome/common/channel_info.h"
39 #include "chrome/common/pref_names.h" 38 #include "chrome/common/pref_names.h"
40 #include "chrome/grit/generated_resources.h" 39 #include "chrome/grit/generated_resources.h"
41 #include "chrome/grit/locale_settings.h" 40 #include "chrome/grit/locale_settings.h"
41 #include "components/browsing_data/counters/browsing_data_counter.h"
42 #include "components/browsing_data_ui/history_notice_utils.h" 42 #include "components/browsing_data_ui/history_notice_utils.h"
43 #include "components/google/core/browser/google_util.h" 43 #include "components/google/core/browser/google_util.h"
44 #include "components/prefs/pref_service.h" 44 #include "components/prefs/pref_service.h"
45 #include "content/public/browser/notification_details.h" 45 #include "content/public/browser/notification_details.h"
46 #include "content/public/browser/web_ui.h" 46 #include "content/public/browser/web_ui.h"
47 #include "ui/base/accelerators/accelerator.h" 47 #include "ui/base/accelerators/accelerator.h"
48 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
49 #include "ui/events/keycodes/keyboard_codes.h" 49 #include "ui/events/keycodes/keyboard_codes.h"
50 50
51 namespace { 51 namespace {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs); 85 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs);
86 pepper_flash_settings_enabled_.Init(prefs::kPepperFlashSettingsEnabled, 86 pepper_flash_settings_enabled_.Init(prefs::kPepperFlashSettingsEnabled,
87 prefs); 87 prefs);
88 allow_deleting_browser_history_.Init( 88 allow_deleting_browser_history_.Init(
89 prefs::kAllowDeletingBrowserHistory, 89 prefs::kAllowDeletingBrowserHistory,
90 prefs, 90 prefs,
91 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged, 91 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged,
92 base::Unretained(this))); 92 base::Unretained(this)));
93 93
94 if (AreCountersEnabled()) { 94 if (AreCountersEnabled()) {
95 AddCounter(base::WrapUnique(new PasswordsCounter())); 95 Profile* profile = Profile::FromWebUI(web_ui());
96 AddCounter(base::WrapUnique(new HistoryCounter())); 96 AddCounter(base::WrapUnique(new PasswordsCounter(profile)));
97 AddCounter(base::WrapUnique(new CacheCounter())); 97 AddCounter(base::WrapUnique(new HistoryCounter(profile)));
98 AddCounter(base::WrapUnique(new AutofillCounter())); 98 AddCounter(base::WrapUnique(new CacheCounter(profile)));
99 AddCounter(base::WrapUnique(new AutofillCounter(profile)));
99 100
100 sync_service_ = 101 sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile);
101 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
102 if (sync_service_) 102 if (sync_service_)
103 sync_service_->AddObserver(this); 103 sync_service_->AddObserver(this);
104 } 104 }
105 } 105 }
106 106
107 void ClearBrowserDataHandler::InitializePage() { 107 void ClearBrowserDataHandler::InitializePage() {
108 web_ui()->CallJavascriptFunctionUnsafe( 108 web_ui()->CallJavascriptFunctionUnsafe(
109 "ClearBrowserDataOverlay.createFooter", 109 "ClearBrowserDataOverlay.createFooter",
110 base::FundamentalValue(AreCountersEnabled()), 110 base::FundamentalValue(AreCountersEnabled()),
111 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), 111 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()),
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 other_types + num_other_types, 310 other_types + num_other_types,
311 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); 311 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); });
312 UMA_HISTOGRAM_SPARSE_SLOWLY( 312 UMA_HISTOGRAM_SPARSE_SLOWLY(
313 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", 313 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount",
314 checked_other_types); 314 checked_other_types);
315 } 315 }
316 316
317 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile); 317 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile);
318 remover_->AddObserver(this); 318 remover_->AddObserver(this);
319 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); 319 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod);
320 remover_->Remove( 320 remover_->Remove(Period(static_cast<TimePeriod>(period_selected)),
321 BrowsingDataRemover::Period( 321 remove_mask, origin_mask);
322 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)),
323 remove_mask, origin_mask);
324 322
325 // Store the clear browsing data time. Next time the clear browsing data 323 // Store the clear browsing data time. Next time the clear browsing data
326 // dialog is open, this time is used to decide whether to display an info 324 // dialog is open, this time is used to decide whether to display an info
327 // banner or not. 325 // banner or not.
328 prefs->SetInt64(prefs::kLastClearBrowsingDataTime, 326 prefs->SetInt64(prefs::kLastClearBrowsingDataTime,
329 base::Time::Now().ToInternalValue()); 327 base::Time::Now().ToInternalValue());
330 } 328 }
331 329
332 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { 330 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() {
333 remover_->RemoveObserver(this); 331 remover_->RemoveObserver(this);
(...skipping 29 matching lines...) Expand all
363 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { 361 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() {
364 web_ui()->CallJavascriptFunctionUnsafe( 362 web_ui()->CallJavascriptFunctionUnsafe(
365 "ClearBrowserDataOverlay.setAllowDeletingHistory", 363 "ClearBrowserDataOverlay.setAllowDeletingHistory",
366 base::FundamentalValue(*allow_deleting_browser_history_)); 364 base::FundamentalValue(*allow_deleting_browser_history_));
367 } 365 }
368 366
369 void ClearBrowserDataHandler::AddCounter( 367 void ClearBrowserDataHandler::AddCounter(
370 std::unique_ptr<BrowsingDataCounter> counter) { 368 std::unique_ptr<BrowsingDataCounter> counter) {
371 DCHECK(AreCountersEnabled()); 369 DCHECK(AreCountersEnabled());
372 370
373 counter->Init( 371 counter->Init(Profile::FromWebUI(web_ui())->GetPrefs(),
374 Profile::FromWebUI(web_ui()), 372 prefs::kDeleteTimePeriod,
375 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, 373 base::Bind(&ClearBrowserDataHandler::UpdateCounterText,
376 base::Unretained(this))); 374 base::Unretained(this)));
377 counters_.push_back(std::move(counter)); 375 counters_.push_back(std::move(counter));
378 } 376 }
379 377
380 void ClearBrowserDataHandler::UpdateCounterText( 378 void ClearBrowserDataHandler::UpdateCounterText(
381 std::unique_ptr<BrowsingDataCounter::Result> result) { 379 std::unique_ptr<BrowsingDataCounter::Result> result) {
382 DCHECK(AreCountersEnabled()); 380 DCHECK(AreCountersEnabled());
383 web_ui()->CallJavascriptFunctionUnsafe( 381 web_ui()->CallJavascriptFunctionUnsafe(
384 "ClearBrowserDataOverlay.updateCounter", 382 "ClearBrowserDataOverlay.updateCounter",
385 base::StringValue(result->source()->GetPrefName()), 383 base::StringValue(result->source()->GetPrefName()),
386 base::StringValue(GetCounterTextFromResult(result.get()))); 384 base::StringValue(GetCounterTextFromResult(result.get())));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", 422 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated",
425 should_show_history_notice_); 423 should_show_history_notice_);
426 } 424 }
427 425
428 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { 426 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) {
429 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). 427 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes).
430 should_show_history_deletion_dialog_ = show; 428 should_show_history_deletion_dialog_ = show;
431 } 429 }
432 430
433 } // namespace options 431 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698