Import in-progress downloads when history DB is loaded
The logic in loading the download history is quite complicated today. When DownloadManagerImpl is created, it first loads the download from in-progress manager. And then it starts to load the downloads from History DB. That's causing several issues: 1. Due to the mismatch between history DB and in-progress DB, DownloadManagerImpl need to resolve the conflicts when history DB is loaded. Normally it just takes the information from in-progress DB. However, due to the latency during database commit, history DB might contain fresher information than the in-progress DB if the download is in a terminating state (Cancelled/Completed). And that's causing crbug/898859 as an extra OnDownloadCreated() call is called for those terminating downloads. 2. DownloadHistory used to call CreateDownloadItem() and expect a reentrant OnDownloadCreated() call when loading history downloads. However, this may no longer happen as OnDownloadCreated() may have already been called when loading the in-progress DB. So DownloadHistory have to handle the case that there is no reentrant call, which makes the code hard to understand. 3. DownloadHistory might get a OnDownloadCreated() call even before history is loaded. And some of the downloads might have already existed in the history DB. This will cause a failed sql insert LOG in the console. Although the behavior is expected, it is not quite clean. This CL fixes all above issue by loading the in-progress DB records and the history DB records at the same time. Once CreateDownloadItem() is called, DownloadManagerImpl will find the corresponding in-progress download and return it to DownloadHistory, and calling OnDownloadCreated() at the same time. BUG=898859 Change-Id: I0f1da0ecea99e72e8c5507ea005c56261a46f3cd Reviewed-on: https://chromium-review.googlesource.com/c/1318692Reviewed-by:Xing Liu <xingliu@chromium.org> Commit-Queue: Min Qin <qinmin@chromium.org> Cr-Commit-Position: refs/heads/master@{#605900}
Showing
Please register or sign in to comment