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/passwords_counter.h" | 21 #include "chrome/browser/browsing_data/passwords_counter.h" |
22 #include "chrome/browser/history/web_history_service_factory.h" | 22 #include "chrome/browser/history/web_history_service_factory.h" |
23 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "components/browsing_data/pref_names.h" |
25 #include "components/browsing_data_ui/history_notice_utils.h" | 26 #include "components/browsing_data_ui/history_notice_utils.h" |
26 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
27 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
28 | 29 |
29 namespace settings { | 30 namespace settings { |
30 | 31 |
31 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) | 32 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) |
32 : profile_(Profile::FromWebUI(webui)), | 33 : profile_(Profile::FromWebUI(webui)), |
33 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), | 34 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), |
34 sync_service_observer_(this), | 35 sync_service_observer_(this), |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 }; | 148 }; |
148 static size_t num_other_types = arraysize(other_types); | 149 static size_t num_other_types = arraysize(other_types); |
149 int checked_other_types = std::count_if( | 150 int checked_other_types = std::count_if( |
150 other_types, other_types + num_other_types, | 151 other_types, other_types + num_other_types, |
151 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 152 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
152 UMA_HISTOGRAM_SPARSE_SLOWLY( | 153 UMA_HISTOGRAM_SPARSE_SLOWLY( |
153 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 154 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
154 checked_other_types); | 155 checked_other_types); |
155 } | 156 } |
156 | 157 |
157 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); | 158 int period_selected = |
| 159 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
158 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); | 160 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_); |
159 remover_->AddObserver(this); | 161 remover_->AddObserver(this); |
160 remover_->Remove( | 162 remover_->Remove(BrowsingDataRemover::Period( |
161 BrowsingDataRemover::Period( | 163 static_cast<browsing_data::TimePeriod>(period_selected)), |
162 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)), | 164 remove_mask, origin_mask); |
163 remove_mask, origin_mask); | |
164 } | 165 } |
165 | 166 |
166 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { | 167 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { |
167 remover_->RemoveObserver(this); | 168 remover_->RemoveObserver(this); |
168 remover_ = nullptr; | 169 remover_ = nullptr; |
169 ResolveJavascriptCallback( | 170 ResolveJavascriptCallback( |
170 base::StringValue(webui_callback_id_), | 171 base::StringValue(webui_callback_id_), |
171 *base::Value::CreateNullValue()); | 172 *base::Value::CreateNullValue()); |
172 webui_callback_id_.clear(); | 173 webui_callback_id_.clear(); |
173 } | 174 } |
174 | 175 |
175 void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() { | 176 void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() { |
176 CallJavascriptFunction( | 177 CallJavascriptFunction( |
177 "cr.webUIListenerCallback", | 178 "cr.webUIListenerCallback", |
178 base::StringValue("browsing-history-pref-changed"), | 179 base::StringValue("browsing-history-pref-changed"), |
179 base::FundamentalValue( | 180 base::FundamentalValue( |
180 profile_->GetPrefs()->GetBoolean( | 181 profile_->GetPrefs()->GetBoolean( |
181 prefs::kAllowDeletingBrowserHistory))); | 182 prefs::kAllowDeletingBrowserHistory))); |
182 } | 183 } |
183 | 184 |
184 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 185 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
185 AllowJavascript(); | 186 AllowJavascript(); |
186 | 187 |
187 // TODO(msramek): Simplify this using a factory. | 188 // TODO(msramek): Simplify this using a factory. |
188 AddCounter(base::WrapUnique(new AutofillCounter())); | 189 AddCounter(base::WrapUnique(new AutofillCounter(profile_))); |
189 AddCounter(base::WrapUnique(new CacheCounter())); | 190 AddCounter(base::WrapUnique(new CacheCounter(profile_))); |
190 AddCounter(base::WrapUnique(new DownloadsCounter())); | 191 AddCounter(base::WrapUnique(new DownloadsCounter(profile_))); |
191 AddCounter(base::WrapUnique(new HistoryCounter())); | 192 AddCounter(base::WrapUnique(new HistoryCounter(profile_))); |
192 AddCounter(base::WrapUnique(new HostedAppsCounter())); | 193 AddCounter(base::WrapUnique(new HostedAppsCounter(profile_))); |
193 AddCounter(base::WrapUnique(new PasswordsCounter())); | 194 AddCounter(base::WrapUnique(new PasswordsCounter(profile_))); |
194 | 195 |
195 OnStateChanged(); | 196 OnStateChanged(); |
196 RefreshHistoryNotice(); | 197 RefreshHistoryNotice(); |
197 } | 198 } |
198 | 199 |
199 void ClearBrowsingDataHandler::OnStateChanged() { | 200 void ClearBrowsingDataHandler::OnStateChanged() { |
200 CallJavascriptFunction( | 201 CallJavascriptFunction( |
201 "cr.webUIListenerCallback", | 202 "cr.webUIListenerCallback", |
202 base::StringValue("update-footer"), | 203 base::StringValue("update-footer"), |
203 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 204 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
(...skipping 11 matching lines...) Expand all Loading... |
215 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { | 216 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { |
216 should_show_history_footer_ = show; | 217 should_show_history_footer_ = show; |
217 OnStateChanged(); | 218 OnStateChanged(); |
218 | 219 |
219 UMA_HISTOGRAM_BOOLEAN( | 220 UMA_HISTOGRAM_BOOLEAN( |
220 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 221 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
221 should_show_history_footer_); | 222 should_show_history_footer_); |
222 } | 223 } |
223 | 224 |
224 void ClearBrowsingDataHandler::AddCounter( | 225 void ClearBrowsingDataHandler::AddCounter( |
225 std::unique_ptr<BrowsingDataCounter> counter) { | 226 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { |
226 counter->Init( | 227 counter->Init(profile_->GetPrefs(), |
227 profile_, | 228 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, |
228 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, | 229 base::Unretained(this))); |
229 base::Unretained(this))); | |
230 counter->Restart(); | 230 counter->Restart(); |
231 counters_.push_back(std::move(counter)); | 231 counters_.push_back(std::move(counter)); |
232 } | 232 } |
233 | 233 |
234 void ClearBrowsingDataHandler::UpdateCounterText( | 234 void ClearBrowsingDataHandler::UpdateCounterText( |
235 std::unique_ptr<BrowsingDataCounter::Result> result) { | 235 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
236 CallJavascriptFunction( | 236 CallJavascriptFunction( |
237 "cr.webUIListenerCallback", | 237 "cr.webUIListenerCallback", |
238 base::StringValue("update-counter-text"), | 238 base::StringValue("update-counter-text"), |
239 base::StringValue(result->source()->GetPrefName()), | 239 base::StringValue(result->source()->GetPrefName()), |
240 base::StringValue(GetCounterTextFromResult(result.get()))); | 240 base::StringValue(GetCounterTextFromResult(result.get()))); |
241 } | 241 } |
242 | 242 |
243 } // namespace settings | 243 } // namespace settings |
OLD | NEW |