| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 if (show_notice) { | 234 if (show_notice) { |
| 235 // Increment the preference. | 235 // Increment the preference. |
| 236 prefs->SetInteger( | 236 prefs->SetInteger( |
| 237 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, | 237 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, |
| 238 notice_shown_times + 1); | 238 notice_shown_times + 1); |
| 239 } | 239 } |
| 240 | 240 |
| 241 UMA_HISTOGRAM_BOOLEAN( | 241 UMA_HISTOGRAM_BOOLEAN( |
| 242 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); | 242 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); |
| 243 | 243 |
| 244 ResolveJavascriptCallback( | 244 ResolveJavascriptCallback(base::StringValue(webui_callback_id), |
| 245 base::StringValue(webui_callback_id), | 245 base::Value(show_notice)); |
| 246 base::FundamentalValue(show_notice)); | |
| 247 task_observer_.reset(); | 246 task_observer_.reset(); |
| 248 } | 247 } |
| 249 | 248 |
| 250 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 249 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
| 251 AllowJavascript(); | 250 AllowJavascript(); |
| 252 const base::Value* callback_id; | 251 const base::Value* callback_id; |
| 253 CHECK(args->Get(0, &callback_id)); | 252 CHECK(args->Get(0, &callback_id)); |
| 254 | 253 |
| 255 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. | 254 // Needed because WebUI doesn't handle renderer crashes. See crbug.com/610450. |
| 256 task_observer_.reset(); | 255 task_observer_.reset(); |
| 257 | 256 |
| 258 UpdateSyncState(); | 257 UpdateSyncState(); |
| 259 RefreshHistoryNotice(); | 258 RefreshHistoryNotice(); |
| 260 | 259 |
| 261 // Restart the counters each time the dialog is reopened. | 260 // Restart the counters each time the dialog is reopened. |
| 262 for (const auto& counter : counters_) | 261 for (const auto& counter : counters_) |
| 263 counter->Restart(); | 262 counter->Restart(); |
| 264 | 263 |
| 265 ResolveJavascriptCallback( | 264 ResolveJavascriptCallback( |
| 266 *callback_id, | 265 *callback_id, |
| 267 *base::Value::CreateNullValue() /* Promise<void> */); | 266 *base::Value::CreateNullValue() /* Promise<void> */); |
| 268 } | 267 } |
| 269 | 268 |
| 270 void ClearBrowsingDataHandler::OnStateChanged(syncer::SyncService* sync) { | 269 void ClearBrowsingDataHandler::OnStateChanged(syncer::SyncService* sync) { |
| 271 UpdateSyncState(); | 270 UpdateSyncState(); |
| 272 } | 271 } |
| 273 | 272 |
| 274 void ClearBrowsingDataHandler::UpdateSyncState() { | 273 void ClearBrowsingDataHandler::UpdateSyncState() { |
| 275 CallJavascriptFunction( | 274 CallJavascriptFunction( |
| 276 "cr.webUIListenerCallback", | 275 "cr.webUIListenerCallback", base::StringValue("update-footer"), |
| 277 base::StringValue("update-footer"), | 276 base::Value(sync_service_ && sync_service_->IsSyncActive()), |
| 278 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 277 base::Value(show_history_footer_)); |
| 279 base::FundamentalValue(show_history_footer_)); | |
| 280 } | 278 } |
| 281 | 279 |
| 282 void ClearBrowsingDataHandler::RefreshHistoryNotice() { | 280 void ClearBrowsingDataHandler::RefreshHistoryNotice() { |
| 283 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 281 browsing_data::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
| 284 sync_service_, | 282 sync_service_, |
| 285 WebHistoryServiceFactory::GetForProfile(profile_), | 283 WebHistoryServiceFactory::GetForProfile(profile_), |
| 286 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryNotice, | 284 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryNotice, |
| 287 weak_ptr_factory_.GetWeakPtr())); | 285 weak_ptr_factory_.GetWeakPtr())); |
| 288 | 286 |
| 289 // If the dialog with history notice has been shown less than | 287 // If the dialog with history notice has been shown less than |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 void ClearBrowsingDataHandler::UpdateCounterText( | 325 void ClearBrowsingDataHandler::UpdateCounterText( |
| 328 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 326 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 329 CallJavascriptFunction( | 327 CallJavascriptFunction( |
| 330 "cr.webUIListenerCallback", | 328 "cr.webUIListenerCallback", |
| 331 base::StringValue("update-counter-text"), | 329 base::StringValue("update-counter-text"), |
| 332 base::StringValue(result->source()->GetPrefName()), | 330 base::StringValue(result->source()->GetPrefName()), |
| 333 base::StringValue(GetChromeCounterTextFromResult(result.get()))); | 331 base::StringValue(GetChromeCounterTextFromResult(result.get()))); |
| 334 } | 332 } |
| 335 | 333 |
| 336 } // namespace settings | 334 } // namespace settings |
| OLD | NEW |