| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browsing_data/history_counter.h" | 5 #include "chrome/browser/browsing_data/history_counter.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/history/history_service_factory.h" | 8 #include "chrome/browser/history/history_service_factory.h" |
| 9 #include "chrome/browser/history/web_history_service_factory.h" | 9 #include "chrome/browser/history/web_history_service_factory.h" |
| 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // syncing history deletion, and this should restart the counter. | 347 // syncing history deletion, and this should restart the counter. |
| 348 ASSERT_TRUE(SetupSync()); | 348 ASSERT_TRUE(SetupSync()); |
| 349 ASSERT_TRUE(sync_service->IsSyncActive()); | 349 ASSERT_TRUE(sync_service->IsSyncActive()); |
| 350 ASSERT_TRUE(sync_service->GetPreferredDataTypes().Has( | 350 ASSERT_TRUE(sync_service->GetPreferredDataTypes().Has( |
| 351 syncer::HISTORY_DELETE_DIRECTIVES)); | 351 syncer::HISTORY_DELETE_DIRECTIVES)); |
| 352 WaitForCountingOrConfirmFinished(); | 352 WaitForCountingOrConfirmFinished(); |
| 353 | 353 |
| 354 // We stop syncing history deletion in particular. This restarts the counter. | 354 // We stop syncing history deletion in particular. This restarts the counter. |
| 355 syncer::ModelTypeSet everything_except_history = syncer::ModelTypeSet::All(); | 355 syncer::ModelTypeSet everything_except_history = syncer::ModelTypeSet::All(); |
| 356 everything_except_history.Remove(syncer::HISTORY_DELETE_DIRECTIVES); | 356 everything_except_history.Remove(syncer::HISTORY_DELETE_DIRECTIVES); |
| 357 sync_service->SetSetupInProgress(true); | 357 auto setup_handle = sync_service->GetSetupInProgressHandle(); |
| 358 sync_service->ChangePreferredDataTypes(everything_except_history); | 358 sync_service->ChangePreferredDataTypes(everything_except_history); |
| 359 sync_service->SetSetupInProgress(false); | 359 setup_handle.reset(); |
| 360 WaitForCountingOrConfirmFinished(); | 360 WaitForCountingOrConfirmFinished(); |
| 361 | 361 |
| 362 // If the history deletion sync is not affected, the counter is not restarted. | 362 // If the history deletion sync is not affected, the counter is not restarted. |
| 363 syncer::ModelTypeSet only_passwords(syncer::PASSWORDS); | 363 syncer::ModelTypeSet only_passwords(syncer::PASSWORDS); |
| 364 sync_service->ChangePreferredDataTypes(only_passwords); | 364 sync_service->ChangePreferredDataTypes(only_passwords); |
| 365 sync_service->SetSetupInProgress(true); | 365 setup_handle = sync_service->GetSetupInProgressHandle(); |
| 366 sync_service->ChangePreferredDataTypes(only_passwords); | 366 sync_service->ChangePreferredDataTypes(only_passwords); |
| 367 sync_service->SetSetupInProgress(false); | 367 setup_handle.reset(); |
| 368 EXPECT_FALSE(counter.HasTrackedTasks()); | 368 EXPECT_FALSE(counter.HasTrackedTasks()); |
| 369 EXPECT_FALSE(CountingFinishedSinceLastAsked()); | 369 EXPECT_FALSE(CountingFinishedSinceLastAsked()); |
| 370 | 370 |
| 371 // Same in this case. | 371 // Same in this case. |
| 372 syncer::ModelTypeSet autofill_and_passwords( | 372 syncer::ModelTypeSet autofill_and_passwords( |
| 373 syncer::AUTOFILL, syncer::PASSWORDS); | 373 syncer::AUTOFILL, syncer::PASSWORDS); |
| 374 sync_service->SetSetupInProgress(true); | 374 setup_handle = sync_service->GetSetupInProgressHandle(); |
| 375 sync_service->ChangePreferredDataTypes(autofill_and_passwords); | 375 sync_service->ChangePreferredDataTypes(autofill_and_passwords); |
| 376 sync_service->SetSetupInProgress(false); | 376 setup_handle.reset(); |
| 377 EXPECT_FALSE(counter.HasTrackedTasks()); | 377 EXPECT_FALSE(counter.HasTrackedTasks()); |
| 378 EXPECT_FALSE(CountingFinishedSinceLastAsked()); | 378 EXPECT_FALSE(CountingFinishedSinceLastAsked()); |
| 379 | 379 |
| 380 // We start syncing history deletion again. This restarts the counter. | 380 // We start syncing history deletion again. This restarts the counter. |
| 381 sync_service->SetSetupInProgress(true); | 381 setup_handle = sync_service->GetSetupInProgressHandle(); |
| 382 sync_service->ChangePreferredDataTypes(syncer::ModelTypeSet::All()); | 382 sync_service->ChangePreferredDataTypes(syncer::ModelTypeSet::All()); |
| 383 sync_service->SetSetupInProgress(false); | 383 setup_handle.reset(); |
| 384 WaitForCountingOrConfirmFinished(); | 384 WaitForCountingOrConfirmFinished(); |
| 385 | 385 |
| 386 // Changing the syncing datatypes to another set that still includes history | 386 // Changing the syncing datatypes to another set that still includes history |
| 387 // deletion should technically not trigger a restart, because the state of | 387 // deletion should technically not trigger a restart, because the state of |
| 388 // history deletion did not change. However, in reality we can get two | 388 // history deletion did not change. However, in reality we can get two |
| 389 // notifications, one that history sync has stopped and another that it is | 389 // notifications, one that history sync has stopped and another that it is |
| 390 // active again. | 390 // active again. |
| 391 | 391 |
| 392 // Stopping the Sync service triggers a restart. | 392 // Stopping the Sync service triggers a restart. |
| 393 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA); | 393 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA); |
| 394 WaitForCountingOrConfirmFinished(); | 394 WaitForCountingOrConfirmFinished(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace | 397 } // namespace |
| OLD | NEW |