| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 AddCounter(base::WrapUnique(new AutofillCounter())); | 97 AddCounter(base::WrapUnique(new AutofillCounter())); |
| 98 | 98 |
| 99 sync_service_ = | 99 sync_service_ = |
| 100 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 100 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 101 if (sync_service_) | 101 if (sync_service_) |
| 102 sync_service_->AddObserver(this); | 102 sync_service_->AddObserver(this); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 void ClearBrowserDataHandler::InitializePage() { | 106 void ClearBrowserDataHandler::InitializePage() { |
| 107 web_ui()->CallJavascriptFunction( | 107 web_ui()->CallJavascriptFunctionUnsafe( |
| 108 "ClearBrowserDataOverlay.createFooter", | 108 "ClearBrowserDataOverlay.createFooter", |
| 109 base::FundamentalValue(AreCountersEnabled()), | 109 base::FundamentalValue(AreCountersEnabled()), |
| 110 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 110 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
| 111 base::FundamentalValue(should_show_history_notice_)); | 111 base::FundamentalValue(should_show_history_notice_)); |
| 112 RefreshHistoryNotice(); | 112 RefreshHistoryNotice(); |
| 113 UpdateInfoBannerVisibility(); | 113 UpdateInfoBannerVisibility(); |
| 114 OnBrowsingHistoryPrefChanged(); | 114 OnBrowsingHistoryPrefChanged(); |
| 115 bool removal_in_progress = !!remover_; | 115 bool removal_in_progress = !!remover_; |
| 116 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setClearing", | 116 web_ui()->CallJavascriptFunctionUnsafe( |
| 117 base::FundamentalValue(removal_in_progress)); | 117 "ClearBrowserDataOverlay.setClearing", |
| 118 base::FundamentalValue(removal_in_progress)); |
| 118 | 119 |
| 119 web_ui()->CallJavascriptFunction( | 120 web_ui()->CallJavascriptFunctionUnsafe( |
| 120 "ClearBrowserDataOverlay.markInitializationComplete"); | 121 "ClearBrowserDataOverlay.markInitializationComplete"); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void ClearBrowserDataHandler::UpdateInfoBannerVisibility() { | 124 void ClearBrowserDataHandler::UpdateInfoBannerVisibility() { |
| 124 base::string16 text; | 125 base::string16 text; |
| 125 | 126 |
| 126 Profile* profile = Profile::FromWebUI(web_ui()); | 127 Profile* profile = Profile::FromWebUI(web_ui()); |
| 127 auto availability = IncognitoModePrefs::GetAvailability(profile->GetPrefs()); | 128 auto availability = IncognitoModePrefs::GetAvailability(profile->GetPrefs()); |
| 128 if (availability == IncognitoModePrefs::ENABLED) { | 129 if (availability == IncognitoModePrefs::ENABLED) { |
| 129 base::Time last_clear_time = base::Time::FromInternalValue( | 130 base::Time last_clear_time = base::Time::FromInternalValue( |
| 130 profile->GetPrefs()->GetInt64(prefs::kLastClearBrowsingDataTime)); | 131 profile->GetPrefs()->GetInt64(prefs::kLastClearBrowsingDataTime)); |
| 131 | 132 |
| 132 const base::TimeDelta since_clear = base::Time::Now() - last_clear_time; | 133 const base::TimeDelta since_clear = base::Time::Now() - last_clear_time; |
| 133 if (since_clear < base::TimeDelta::FromHours(base::Time::kHoursPerDay)) { | 134 if (since_clear < base::TimeDelta::FromHours(base::Time::kHoursPerDay)) { |
| 134 ui::Accelerator acc = chrome::GetPrimaryChromeAcceleratorForCommandId( | 135 ui::Accelerator acc = chrome::GetPrimaryChromeAcceleratorForCommandId( |
| 135 IDC_NEW_INCOGNITO_WINDOW); | 136 IDC_NEW_INCOGNITO_WINDOW); |
| 136 DCHECK_NE(ui::VKEY_UNKNOWN, acc.key_code()); | 137 DCHECK_NE(ui::VKEY_UNKNOWN, acc.key_code()); |
| 137 text = l10n_util::GetStringFUTF16(IDS_CLEAR_BROWSING_DATA_INFO_BAR_TEXT, | 138 text = l10n_util::GetStringFUTF16(IDS_CLEAR_BROWSING_DATA_INFO_BAR_TEXT, |
| 138 acc.GetShortcutText()); | 139 acc.GetShortcutText()); |
| 139 } | 140 } |
| 140 } | 141 } |
| 141 | 142 |
| 142 web_ui()->CallJavascriptFunction("ClearBrowserDataOverlay.setBannerText", | 143 web_ui()->CallJavascriptFunctionUnsafe( |
| 143 base::StringValue(text)); | 144 "ClearBrowserDataOverlay.setBannerText", base::StringValue(text)); |
| 144 } | 145 } |
| 145 | 146 |
| 146 void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) { | 147 void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) { |
| 147 for (BrowsingDataCounter* counter : counters_) { | 148 for (BrowsingDataCounter* counter : counters_) { |
| 148 DCHECK(AreCountersEnabled()); | 149 DCHECK(AreCountersEnabled()); |
| 149 counter->Restart(); | 150 counter->Restart(); |
| 150 } | 151 } |
| 151 } | 152 } |
| 152 | 153 |
| 153 void ClearBrowserDataHandler::GetLocalizedValues( | 154 void ClearBrowserDataHandler::GetLocalizedValues( |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 348 |
| 348 if (show_notice) { | 349 if (show_notice) { |
| 349 // Increment the preference. | 350 // Increment the preference. |
| 350 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes, | 351 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes, |
| 351 notice_shown_times + 1); | 352 notice_shown_times + 1); |
| 352 } | 353 } |
| 353 | 354 |
| 354 UMA_HISTOGRAM_BOOLEAN( | 355 UMA_HISTOGRAM_BOOLEAN( |
| 355 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); | 356 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); |
| 356 | 357 |
| 357 web_ui()->CallJavascriptFunction( | 358 web_ui()->CallJavascriptFunctionUnsafe("ClearBrowserDataOverlay.doneClearing", |
| 358 "ClearBrowserDataOverlay.doneClearing", | 359 base::FundamentalValue(show_notice)); |
| 359 base::FundamentalValue(show_notice)); | |
| 360 } | 360 } |
| 361 | 361 |
| 362 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { | 362 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { |
| 363 web_ui()->CallJavascriptFunction( | 363 web_ui()->CallJavascriptFunctionUnsafe( |
| 364 "ClearBrowserDataOverlay.setAllowDeletingHistory", | 364 "ClearBrowserDataOverlay.setAllowDeletingHistory", |
| 365 base::FundamentalValue(*allow_deleting_browser_history_)); | 365 base::FundamentalValue(*allow_deleting_browser_history_)); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void ClearBrowserDataHandler::AddCounter( | 368 void ClearBrowserDataHandler::AddCounter( |
| 369 std::unique_ptr<BrowsingDataCounter> counter) { | 369 std::unique_ptr<BrowsingDataCounter> counter) { |
| 370 DCHECK(AreCountersEnabled()); | 370 DCHECK(AreCountersEnabled()); |
| 371 | 371 |
| 372 counter->Init( | 372 counter->Init( |
| 373 Profile::FromWebUI(web_ui()), | 373 Profile::FromWebUI(web_ui()), |
| 374 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, | 374 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, |
| 375 base::Unretained(this))); | 375 base::Unretained(this))); |
| 376 counters_.push_back(std::move(counter)); | 376 counters_.push_back(std::move(counter)); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void ClearBrowserDataHandler::UpdateCounterText( | 379 void ClearBrowserDataHandler::UpdateCounterText( |
| 380 std::unique_ptr<BrowsingDataCounter::Result> result) { | 380 std::unique_ptr<BrowsingDataCounter::Result> result) { |
| 381 DCHECK(AreCountersEnabled()); | 381 DCHECK(AreCountersEnabled()); |
| 382 web_ui()->CallJavascriptFunction( | 382 web_ui()->CallJavascriptFunctionUnsafe( |
| 383 "ClearBrowserDataOverlay.updateCounter", | 383 "ClearBrowserDataOverlay.updateCounter", |
| 384 base::StringValue(result->source()->GetPrefName()), | 384 base::StringValue(result->source()->GetPrefName()), |
| 385 base::StringValue(GetCounterTextFromResult(result.get()))); | 385 base::StringValue(GetCounterTextFromResult(result.get()))); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void ClearBrowserDataHandler::OnStateChanged() { | 388 void ClearBrowserDataHandler::OnStateChanged() { |
| 389 web_ui()->CallJavascriptFunction( | 389 web_ui()->CallJavascriptFunctionUnsafe( |
| 390 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", | 390 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", |
| 391 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 391 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
| 392 base::FundamentalValue(should_show_history_notice_)); | 392 base::FundamentalValue(should_show_history_notice_)); |
| 393 } | 393 } |
| 394 | 394 |
| 395 void ClearBrowserDataHandler::RefreshHistoryNotice() { | 395 void ClearBrowserDataHandler::RefreshHistoryNotice() { |
| 396 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 396 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
| 397 sync_service_, | 397 sync_service_, |
| 398 WebHistoryServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())), | 398 WebHistoryServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())), |
| 399 base::Bind(&ClearBrowserDataHandler::UpdateHistoryNotice, | 399 base::Bind(&ClearBrowserDataHandler::UpdateHistoryNotice, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 423 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 423 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
| 424 should_show_history_notice_); | 424 should_show_history_notice_); |
| 425 } | 425 } |
| 426 | 426 |
| 427 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { | 427 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { |
| 428 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). | 428 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). |
| 429 should_show_history_deletion_dialog_ = show; | 429 should_show_history_deletion_dialog_ = show; |
| 430 } | 430 } |
| 431 | 431 |
| 432 } // namespace options | 432 } // namespace options |
| OLD | NEW |