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" |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 } | 248 } |
249 | 249 |
250 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 250 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
251 AllowJavascript(); | 251 AllowJavascript(); |
252 const base::Value* callback_id; | 252 const base::Value* callback_id; |
253 CHECK(args->Get(0, &callback_id)); | 253 CHECK(args->Get(0, &callback_id)); |
254 | 254 |
255 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. | 255 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. |
256 task_observer_.reset(); | 256 task_observer_.reset(); |
257 | 257 |
258 OnStateChanged(); | 258 UpdateSyncState(); |
259 RefreshHistoryNotice(); | 259 RefreshHistoryNotice(); |
260 | 260 |
261 // Restart the counters each time the dialog is reopened. | 261 // Restart the counters each time the dialog is reopened. |
262 for (const auto& counter : counters_) | 262 for (const auto& counter : counters_) |
263 counter->Restart(); | 263 counter->Restart(); |
264 | 264 |
265 ResolveJavascriptCallback( | 265 ResolveJavascriptCallback( |
266 *callback_id, | 266 *callback_id, |
267 *base::Value::CreateNullValue() /* Promise<void> */); | 267 *base::Value::CreateNullValue() /* Promise<void> */); |
268 } | 268 } |
269 | 269 |
270 void ClearBrowsingDataHandler::OnStateChanged() { | 270 void ClearBrowsingDataHandler::OnStateChanged(syncer::SyncService* sync) { |
| 271 UpdateSyncState(); |
| 272 } |
| 273 |
| 274 void ClearBrowsingDataHandler::UpdateSyncState() { |
271 CallJavascriptFunction( | 275 CallJavascriptFunction( |
272 "cr.webUIListenerCallback", | 276 "cr.webUIListenerCallback", |
273 base::StringValue("update-footer"), | 277 base::StringValue("update-footer"), |
274 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 278 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
275 base::FundamentalValue(show_history_footer_)); | 279 base::FundamentalValue(show_history_footer_)); |
276 } | 280 } |
277 | 281 |
278 void ClearBrowsingDataHandler::RefreshHistoryNotice() { | 282 void ClearBrowsingDataHandler::RefreshHistoryNotice() { |
279 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 283 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
280 sync_service_, | 284 sync_service_, |
(...skipping 12 matching lines...) Expand all Loading... |
293 sync_service_, | 297 sync_service_, |
294 WebHistoryServiceFactory::GetForProfile(profile_), | 298 WebHistoryServiceFactory::GetForProfile(profile_), |
295 chrome::GetChannel(), | 299 chrome::GetChannel(), |
296 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryDeletionDialog, | 300 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryDeletionDialog, |
297 weak_ptr_factory_.GetWeakPtr())); | 301 weak_ptr_factory_.GetWeakPtr())); |
298 } | 302 } |
299 } | 303 } |
300 | 304 |
301 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { | 305 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { |
302 show_history_footer_ = show; | 306 show_history_footer_ = show; |
303 OnStateChanged(); | 307 UpdateSyncState(); |
304 | 308 |
305 UMA_HISTOGRAM_BOOLEAN( | 309 UMA_HISTOGRAM_BOOLEAN( |
306 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 310 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
307 show_history_footer_); | 311 show_history_footer_); |
308 } | 312 } |
309 | 313 |
310 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { | 314 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { |
311 // This is used by OnClearingTaskFinished (when the deletion finishes). | 315 // This is used by OnClearingTaskFinished (when the deletion finishes). |
312 show_history_deletion_dialog_ = show; | 316 show_history_deletion_dialog_ = show; |
313 } | 317 } |
314 | 318 |
315 void ClearBrowsingDataHandler::AddCounter( | 319 void ClearBrowsingDataHandler::AddCounter( |
316 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { | 320 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { |
317 counter->Init(profile_->GetPrefs(), | 321 counter->Init(profile_->GetPrefs(), |
318 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, | 322 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, |
319 base::Unretained(this))); | 323 base::Unretained(this))); |
320 counters_.push_back(std::move(counter)); | 324 counters_.push_back(std::move(counter)); |
321 } | 325 } |
322 | 326 |
323 void ClearBrowsingDataHandler::UpdateCounterText( | 327 void ClearBrowsingDataHandler::UpdateCounterText( |
324 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 328 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
325 CallJavascriptFunction( | 329 CallJavascriptFunction( |
326 "cr.webUIListenerCallback", | 330 "cr.webUIListenerCallback", |
327 base::StringValue("update-counter-text"), | 331 base::StringValue("update-counter-text"), |
328 base::StringValue(result->source()->GetPrefName()), | 332 base::StringValue(result->source()->GetPrefName()), |
329 base::StringValue(GetChromeCounterTextFromResult(result.get()))); | 333 base::StringValue(GetChromeCounterTextFromResult(result.get()))); |
330 } | 334 } |
331 | 335 |
332 } // namespace settings | 336 } // namespace settings |
OLD | NEW |