| 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 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "chrome/browser/browsing_data/autofill_counter.h" | 13 #include "chrome/browser/browsing_data/autofill_counter.h" |
| 14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | 14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
| 15 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 17 #include "chrome/browser/browsing_data/cache_counter.h" | 17 #include "chrome/browser/browsing_data/cache_counter.h" |
| 18 #include "chrome/browser/browsing_data/downloads_counter.h" | 18 #include "chrome/browser/browsing_data/downloads_counter.h" |
| 19 #include "chrome/browser/browsing_data/history_counter.h" | 19 #include "chrome/browser/browsing_data/history_counter.h" |
| 20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | 20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" |
| 21 #include "chrome/browser/browsing_data/media_licenses_counter.h" | 21 #include "chrome/browser/browsing_data/media_licenses_counter.h" |
| 22 #include "chrome/browser/browsing_data/passwords_counter.h" | 22 #include "chrome/browser/browsing_data/passwords_counter.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/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "components/browsing_data/pref_names.h" |
| 27 #include "components/browsing_data_ui/history_notice_utils.h" | 28 #include "components/browsing_data_ui/history_notice_utils.h" |
| 28 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" |
| 29 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 | 33 |
| 33 const int kMaxTimesHistoryNoticeShown = 1; | 34 const int kMaxTimesHistoryNoticeShown = 1; |
| 34 | 35 |
| 35 } | 36 } |
| 36 | 37 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 }; | 154 }; |
| 154 static size_t num_other_types = arraysize(other_types); | 155 static size_t num_other_types = arraysize(other_types); |
| 155 int checked_other_types = std::count_if( | 156 int checked_other_types = std::count_if( |
| 156 other_types, other_types + num_other_types, | 157 other_types, other_types + num_other_types, |
| 157 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 158 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
| 158 UMA_HISTOGRAM_SPARSE_SLOWLY( | 159 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 159 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 160 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
| 160 checked_other_types); | 161 checked_other_types); |
| 161 } | 162 } |
| 162 | 163 |
| 163 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); | 164 int period_selected = |
| 165 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
| 164 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); | 166 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); |
| 165 remover_->AddObserver(this); | 167 remover_->AddObserver(this); |
| 166 remover_->Remove( | 168 remover_->Remove(BrowsingDataRemover::Period( |
| 167 BrowsingDataRemover::Period( | 169 static_cast<browsing_data::TimePeriod>(period_selected)), |
| 168 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)), | 170 remove_mask, origin_mask); |
| 169 remove_mask, origin_mask); | |
| 170 } | 171 } |
| 171 | 172 |
| 172 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { | 173 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { |
| 173 remover_->RemoveObserver(this); | 174 remover_->RemoveObserver(this); |
| 174 remover_ = nullptr; | 175 remover_ = nullptr; |
| 175 | 176 |
| 176 PrefService* prefs = profile_->GetPrefs(); | 177 PrefService* prefs = profile_->GetPrefs(); |
| 177 int notice_shown_times = | 178 int notice_shown_times = |
| 178 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); | 179 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); |
| 179 | 180 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 208 base::StringValue("browsing-history-pref-changed"), | 209 base::StringValue("browsing-history-pref-changed"), |
| 209 base::FundamentalValue( | 210 base::FundamentalValue( |
| 210 profile_->GetPrefs()->GetBoolean( | 211 profile_->GetPrefs()->GetBoolean( |
| 211 prefs::kAllowDeletingBrowserHistory))); | 212 prefs::kAllowDeletingBrowserHistory))); |
| 212 } | 213 } |
| 213 | 214 |
| 214 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 215 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
| 215 AllowJavascript(); | 216 AllowJavascript(); |
| 216 | 217 |
| 217 // TODO(msramek): Simplify this using a factory. | 218 // TODO(msramek): Simplify this using a factory. |
| 218 AddCounter(base::WrapUnique(new AutofillCounter())); | 219 AddCounter(base::WrapUnique(new AutofillCounter(profile_))); |
| 219 AddCounter(base::WrapUnique(new CacheCounter())); | 220 AddCounter(base::WrapUnique(new CacheCounter(profile_))); |
| 220 AddCounter(base::WrapUnique(new DownloadsCounter())); | 221 AddCounter(base::WrapUnique(new DownloadsCounter(profile_))); |
| 221 AddCounter(base::WrapUnique(new HistoryCounter())); | 222 AddCounter(base::WrapUnique(new HistoryCounter(profile_))); |
| 222 AddCounter(base::WrapUnique(new HostedAppsCounter())); | 223 AddCounter(base::WrapUnique(new HostedAppsCounter(profile_))); |
| 223 AddCounter(base::WrapUnique(new PasswordsCounter())); | 224 AddCounter(base::WrapUnique(new PasswordsCounter(profile_))); |
| 224 AddCounter(base::WrapUnique(new MediaLicensesCounter())); | 225 AddCounter(base::WrapUnique(new MediaLicensesCounter(profile_))); |
| 225 | 226 |
| 226 OnStateChanged(); | 227 OnStateChanged(); |
| 227 RefreshHistoryNotice(); | 228 RefreshHistoryNotice(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 void ClearBrowsingDataHandler::OnStateChanged() { | 231 void ClearBrowsingDataHandler::OnStateChanged() { |
| 231 CallJavascriptFunction( | 232 CallJavascriptFunction( |
| 232 "cr.webUIListenerCallback", | 233 "cr.webUIListenerCallback", |
| 233 base::StringValue("update-footer"), | 234 base::StringValue("update-footer"), |
| 234 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 235 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 267 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
| 267 show_history_footer_); | 268 show_history_footer_); |
| 268 } | 269 } |
| 269 | 270 |
| 270 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { | 271 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { |
| 271 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). | 272 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). |
| 272 show_history_deletion_dialog_ = show; | 273 show_history_deletion_dialog_ = show; |
| 273 } | 274 } |
| 274 | 275 |
| 275 void ClearBrowsingDataHandler::AddCounter( | 276 void ClearBrowsingDataHandler::AddCounter( |
| 276 std::unique_ptr<BrowsingDataCounter> counter) { | 277 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { |
| 277 counter->Init( | 278 counter->Init(profile_->GetPrefs(), |
| 278 profile_, | 279 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, |
| 279 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, | 280 base::Unretained(this))); |
| 280 base::Unretained(this))); | |
| 281 counter->Restart(); | 281 counter->Restart(); |
| 282 counters_.push_back(std::move(counter)); | 282 counters_.push_back(std::move(counter)); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void ClearBrowsingDataHandler::UpdateCounterText( | 285 void ClearBrowsingDataHandler::UpdateCounterText( |
| 286 std::unique_ptr<BrowsingDataCounter::Result> result) { | 286 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 287 CallJavascriptFunction( | 287 CallJavascriptFunction( |
| 288 "cr.webUIListenerCallback", | 288 "cr.webUIListenerCallback", |
| 289 base::StringValue("update-counter-text"), | 289 base::StringValue("update-counter-text"), |
| 290 base::StringValue(result->source()->GetPrefName()), | 290 base::StringValue(result->source()->GetPrefName()), |
| 291 base::StringValue(GetCounterTextFromResult(result.get()))); | 291 base::StringValue(GetCounterTextFromResult(result.get()))); |
| 292 } | 292 } |
| 293 | 293 |
| 294 } // namespace settings | 294 } // namespace settings |
| OLD | NEW |