Add DCHECKs to warn of problems during use of HistoryBackend.
The point of these checks is to help developers learn of problems in their use of the History[Service,Backend] in tests and is inspired by the useful warning in base/task/post_task.cc:52. This was created because of questions I got while trying to land unittest fixes in https://crrev.com/c/1865627 separately. Test creators rightfully wanted to know how they could have been aware of the necessary fixes when sometimes they are not even aware of HistoryBackend. Originally I wanted to enforce preconditions in calling code like ~TestingProfile(). This would have been cleaner. This kind of change proved impractical however because adding any kind of flushing in widely used classes like TestingProfile introduced many failures of tests. These tests were either too brittle to survive a flush or used PostDelayedTask which complicates flushing the ThreadPool. On top of that it was not possible to cleanly represent the state of the execution environment we see in production in those preconditions. To fully replicate them we would have needed a way to make sure that: 1) We are past the closing of the main loop. Or at the very least is not possible to post there. 2) That no tasks bound to &HistoryBackend::* are pending execution but that other tasks are left undisturbed on the ThreadPool. Finally in production the failure modes identified here are pretty much guaranteed not to happen. The deletion of profile directories linked to already deleted profiles happen after the ThreadPool destruction there. On top of that profile directories have distinct names between profiles and we do not restart KeyedServices until after the main thread is joined. Bug: 661143 Change-Id: I5eb412b54b1fc1e0c8c830440aa386368269458e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898109Reviewed-by:Scott Violet <sky@chromium.org> Commit-Queue: Oliver Li <olivierli@chromium.org> Auto-Submit: Oliver Li <olivierli@chromium.org> Cr-Commit-Position: refs/heads/master@{#716982}
Showing
Please register or sign in to comment