Commit f98607bd authored by Min Qin's avatar Min Qin Committed by Commit Bot

Remove DownloadDBForNewDownloads finch flag

This is defaulted to true for several releases now. Remove
this flag and fixing some tests that still relying on DownloadHistory.

BUG=1001629

Change-Id: Ica9ede823d49b3fa2680342616ca8842d56071a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789924
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695432}
parent 26e2a366
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -52,7 +53,7 @@ ...@@ -52,7 +53,7 @@
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/download/public/common/download_features.h" #include "components/download/public/common/download_task_runner.h"
#include "components/guest_view/browser/guest_view_manager.h" #include "components/guest_view/browser/guest_view_manager.h"
#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "components/guest_view/browser/guest_view_manager_delegate.h"
#include "components/guest_view/browser/guest_view_manager_factory.h" #include "components/guest_view/browser/guest_view_manager_factory.h"
...@@ -2745,57 +2746,34 @@ std::unique_ptr<net::test_server::HttpResponse> HandleDownloadRequestWithCookie( ...@@ -2745,57 +2746,34 @@ std::unique_ptr<net::test_server::HttpResponse> HandleDownloadRequestWithCookie(
return std::move(response); return std::move(response);
} }
class DownloadHistoryWaiter : public DownloadHistory::Observer { // Class for waiting for download manager to be initiailized.
class DownloadManagerWaiter : public content::DownloadManager::Observer {
public: public:
explicit DownloadHistoryWaiter(content::BrowserContext* browser_context) { explicit DownloadManagerWaiter(content::DownloadManager* download_manager)
DownloadCoreService* service = : initialized_(false), download_manager_(download_manager) {
DownloadCoreServiceFactory::GetForBrowserContext(browser_context); download_manager_->AddObserver(this);
download_history_ = service->GetDownloadHistory();
download_history_->AddObserver(this);
} }
~DownloadHistoryWaiter() override { download_history_->RemoveObserver(this); } ~DownloadManagerWaiter() override { download_manager_->RemoveObserver(this); }
void WaitForStored(size_t download_count) { void WaitForInitialized() {
if (stored_downloads_.size() >= download_count) if (initialized_)
return; return;
stored_download_target_ = download_count;
Wait();
}
void WaitForHistoryLoad() {
if (history_query_complete_)
return;
Wait();
}
private:
void Wait() {
base::RunLoop run_loop; base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure(); quit_closure_ = run_loop.QuitClosure();
run_loop.Run(); run_loop.Run();
} }
void OnDownloadStored(download::DownloadItem* item, void OnManagerInitialized() override {
const history::DownloadRow& info) override { initialized_ = true;
stored_downloads_.insert(item); if (quit_closure_)
if (!quit_closure_.is_null() &&
stored_downloads_.size() >= stored_download_target_) {
std::move(quit_closure_).Run(); std::move(quit_closure_).Run();
}
} }
void OnHistoryQueryComplete() override { private:
history_query_complete_ = true;
if (!quit_closure_.is_null())
std::move(quit_closure_).Run();
}
std::unordered_set<download::DownloadItem*> stored_downloads_;
size_t stored_download_target_ = 0;
bool history_query_complete_ = false;
base::Closure quit_closure_; base::Closure quit_closure_;
DownloadHistory* download_history_ = nullptr; bool initialized_;
content::DownloadManager* download_manager_;
}; };
} // namespace } // namespace
...@@ -2894,15 +2872,14 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_DownloadCookieIsolation) { ...@@ -2894,15 +2872,14 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_DownloadCookieIsolation) {
} }
IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) { IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(
download::features::kDownloadDBForNewDownloads);
embedded_test_server()->RegisterRequestHandler( embedded_test_server()->RegisterRequestHandler(
base::BindRepeating(&HandleDownloadRequestWithCookie)); base::BindRepeating(&HandleDownloadRequestWithCookie));
ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
LoadAndLaunchPlatformApp("web_view/download_cookie_isolation", LoadAndLaunchPlatformApp("web_view/download_cookie_isolation",
"created-webviews"); "created-webviews");
scoped_refptr<base::TestMockTimeTaskRunner> task_runner(
new base::TestMockTimeTaskRunner);
download::SetDownloadDBTaskRunnerForTesting(task_runner);
content::WebContents* web_contents = GetFirstAppWindowWebContents(); content::WebContents* web_contents = GetFirstAppWindowWebContents();
ASSERT_TRUE(web_contents); ASSERT_TRUE(web_contents);
...@@ -2910,9 +2887,6 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) { ...@@ -2910,9 +2887,6 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) {
content::DownloadManager* download_manager = content::DownloadManager* download_manager =
content::BrowserContext::GetDownloadManager( content::BrowserContext::GetDownloadManager(
web_contents->GetBrowserContext()); web_contents->GetBrowserContext());
DownloadHistoryWaiter history_waiter(web_contents->GetBrowserContext());
std::unique_ptr<content::DownloadTestObserver> interrupted_observer( std::unique_ptr<content::DownloadTestObserver> interrupted_observer(
new content::DownloadTestObserverInterrupted( new content::DownloadTestObserverInterrupted(
download_manager, 2, download_manager, 2,
...@@ -2945,7 +2919,7 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) { ...@@ -2945,7 +2919,7 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) {
interrupted_observer->WaitForFinished(); interrupted_observer->WaitForFinished();
// Wait for both downloads to be stored. // Wait for both downloads to be stored.
history_waiter.WaitForStored(2); task_runner->FastForwardUntilNoTasksRemain();
content::EnsureCookiesFlushed(profile()); content::EnsureCookiesFlushed(profile());
} }
...@@ -2961,21 +2935,21 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) { ...@@ -2961,21 +2935,21 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, PRE_DownloadCookieIsolation_CrossSession) {
IN_PROC_BROWSER_TEST_F(WebViewTest, IN_PROC_BROWSER_TEST_F(WebViewTest,
MAYBE_DownloadCookieIsolation_CrossSession) { MAYBE_DownloadCookieIsolation_CrossSession) {
base::test::ScopedFeatureList feature_list;
feature_list.InitAndDisableFeature(
download::features::kDownloadDBForNewDownloads);
embedded_test_server()->RegisterRequestHandler( embedded_test_server()->RegisterRequestHandler(
base::BindRepeating(&HandleDownloadRequestWithCookie)); base::BindRepeating(&HandleDownloadRequestWithCookie));
ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
scoped_refptr<base::TestMockTimeTaskRunner> task_runner(
new base::TestMockTimeTaskRunner);
download::SetDownloadDBTaskRunnerForTesting(task_runner);
content::BrowserContext* browser_context = profile(); content::BrowserContext* browser_context = profile();
content::DownloadManager* download_manager = content::DownloadManager* download_manager =
content::BrowserContext::GetDownloadManager(browser_context); content::BrowserContext::GetDownloadManager(browser_context);
DownloadHistoryWaiter history_waiter(browser_context); task_runner->FastForwardUntilNoTasksRemain();
history_waiter.WaitForHistoryLoad(); DownloadManagerWaiter waiter(download_manager);
waiter.WaitForInitialized();
content::DownloadManager::DownloadVector saved_downloads; content::DownloadManager::DownloadVector saved_downloads;
download_manager->GetAllDownloads(&saved_downloads); download_manager->GetAllDownloads(&saved_downloads);
ASSERT_EQ(2u, saved_downloads.size()); ASSERT_EQ(2u, saved_downloads.size());
...@@ -3018,7 +2992,7 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, ...@@ -3018,7 +2992,7 @@ IN_PROC_BROWSER_TEST_F(WebViewTest,
ASSERT_TRUE(download->GetFullPath().empty()); ASSERT_TRUE(download->GetFullPath().empty());
EXPECT_EQ(download::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, EXPECT_EQ(download::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED,
download->GetLastReason()); download->GetLastReason());
download->Resume(false); download->Resume(true);
} }
completion_observer->WaitForFinished(); completion_observer->WaitForFinished();
......
...@@ -558,10 +558,6 @@ bool DownloadHistory::NeedToUpdateDownloadHistory( ...@@ -558,10 +558,6 @@ bool DownloadHistory::NeedToUpdateDownloadHistory(
} }
#endif #endif
if (!base::FeatureList::IsEnabled(
download::features::kDownloadDBForNewDownloads)) {
return true;
}
// When download DB is enabled, only downloads that are in terminal state // When download DB is enabled, only downloads that are in terminal state
// are added to or updated in history DB. Non-transient in-progress and // are added to or updated in history DB. Non-transient in-progress and
// interrupted download will be stored in the in-progress DB. // interrupted download will be stored in the in-progress DB.
......
...@@ -171,18 +171,6 @@ void DownloadDBCache::UpdateDownloadDB() { ...@@ -171,18 +171,6 @@ void DownloadDBCache::UpdateDownloadDB() {
} }
void DownloadDBCache::OnDownloadUpdated(DownloadItem* download) { void DownloadDBCache::OnDownloadUpdated(DownloadItem* download) {
// TODO(crbug.com/778425): Properly handle fail/resume/retry for downloads
// that are in the INTERRUPTED state for a long time.
if (!base::FeatureList::IsEnabled(features::kDownloadDBForNewDownloads)) {
// If history service is still managing in-progress download, we can safely
// remove a download from the in-progress DB whenever it is in the terminal
// state. Otherwise, we need to propagate the completed download to
// history service before we can remove it.
if (download->IsDone()) {
OnDownloadRemoved(download);
return;
}
}
DownloadDBEntry entry = CreateDownloadDBEntryFromItem( DownloadDBEntry entry = CreateDownloadDBEntryFromItem(
*(static_cast<DownloadItemImpl*>(download))); *(static_cast<DownloadItemImpl*>(download)));
AddOrReplaceEntry(entry); AddOrReplaceEntry(entry);
......
...@@ -35,6 +35,9 @@ base::LazySequencedTaskRunner g_download_task_runner = ...@@ -35,6 +35,9 @@ base::LazySequencedTaskRunner g_download_task_runner =
base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner>>:: base::LazyInstance<scoped_refptr<base::SingleThreadTaskRunner>>::
DestructorAtExit g_io_task_runner = LAZY_INSTANCE_INITIALIZER; DestructorAtExit g_io_task_runner = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<scoped_refptr<base::SequencedTaskRunner>>::DestructorAtExit
g_db_task_runner = LAZY_INSTANCE_INITIALIZER;
// Lock to protect |g_io_task_runner| // Lock to protect |g_io_task_runner|
base::Lock& GetIOTaskRunnerLock() { base::Lock& GetIOTaskRunnerLock() {
static base::NoDestructor<base::Lock> instance; static base::NoDestructor<base::Lock> instance;
...@@ -63,4 +66,14 @@ scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() { ...@@ -63,4 +66,14 @@ scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() {
return g_io_task_runner.Get(); return g_io_task_runner.Get();
} }
void SetDownloadDBTaskRunnerForTesting(
const scoped_refptr<base::SequencedTaskRunner>& task_runner) {
DCHECK(task_runner);
g_db_task_runner.Get() = task_runner;
}
scoped_refptr<base::SequencedTaskRunner> GetDownloadDBTaskRunnerForTesting() {
return g_db_task_runner.Get();
}
} // namespace download } // namespace download
...@@ -353,6 +353,10 @@ void InProgressDownloadManager::Initialize( ...@@ -353,6 +353,10 @@ void InProgressDownloadManager::Initialize(
download_db_cache_ = download_db_cache_ =
std::make_unique<DownloadDBCache>(std::move(download_db)); std::make_unique<DownloadDBCache>(std::move(download_db));
if (GetDownloadDBTaskRunnerForTesting()) {
download_db_cache_->SetTimerTaskRunnerForTesting(
GetDownloadDBTaskRunnerForTesting());
}
download_db_cache_->Initialize(base::BindOnce( download_db_cache_->Initialize(base::BindOnce(
&InProgressDownloadManager::OnDBInitialized, weak_factory_.GetWeakPtr())); &InProgressDownloadManager::OnDBInitialized, weak_factory_.GetWeakPtr()));
} }
...@@ -581,36 +585,34 @@ void InProgressDownloadManager::OnDownloadNamesRetrieved( ...@@ -581,36 +585,34 @@ void InProgressDownloadManager::OnDownloadNamesRetrieved(
CreateDownloadEntryFromDownloadDBEntry(entry); CreateDownloadEntryFromDownloadDBEntry(entry);
if (download_entry) if (download_entry)
download_entries_[download_entry->guid] = download_entry.value(); download_entries_[download_entry->guid] = download_entry.value();
if (base::FeatureList::IsEnabled(features::kDownloadDBForNewDownloads)) { auto item = CreateDownloadItemImpl(this, entry);
auto item = CreateDownloadItemImpl(this, entry); if (!item)
if (!item) continue;
continue; uint32_t download_id = item->GetId();
uint32_t download_id = item->GetId(); // Remove entries with duplicate ids.
// Remove entries with duplicate ids. if (download_id != DownloadItem::kInvalidId &&
if (download_id != DownloadItem::kInvalidId && base::Contains(download_ids, download_id)) {
base::Contains(download_ids, download_id)) { RemoveInProgressDownload(item->GetGuid());
num_duplicates++;
continue;
}
#if defined(OS_ANDROID)
const base::FilePath& path = item->GetTargetFilePath();
if (path.IsContentUri()) {
base::FilePath display_name = GetDownloadDisplayName(path);
// If a download doesn't have a display name, remove it.
if (display_name.empty()) {
RemoveInProgressDownload(item->GetGuid()); RemoveInProgressDownload(item->GetGuid());
num_duplicates++;
continue; continue;
} else {
item->SetDisplayName(display_name);
} }
#if defined(OS_ANDROID)
const base::FilePath& path = item->GetTargetFilePath();
if (path.IsContentUri()) {
base::FilePath display_name = GetDownloadDisplayName(path);
// If a download doesn't have a display name, remove it.
if (display_name.empty()) {
RemoveInProgressDownload(item->GetGuid());
continue;
} else {
item->SetDisplayName(display_name);
}
}
#endif
item->AddObserver(download_db_cache_.get());
OnNewDownloadCreated(item.get());
in_progress_downloads_.emplace_back(std::move(item));
download_ids.insert(download_id);
} }
#endif
item->AddObserver(download_db_cache_.get());
OnNewDownloadCreated(item.get());
in_progress_downloads_.emplace_back(std::move(item));
download_ids.insert(download_id);
} }
if (num_duplicates > 0) if (num_duplicates > 0)
RecordDuplicateInProgressDownloadIdCount(num_duplicates); RecordDuplicateInProgressDownloadIdCount(num_duplicates);
......
...@@ -30,9 +30,6 @@ const base::Feature kParallelDownloading { ...@@ -30,9 +30,6 @@ const base::Feature kParallelDownloading {
#endif #endif
}; };
const base::Feature kDownloadDBForNewDownloads{
"DownloadDBForNewDownloads", base::FEATURE_ENABLED_BY_DEFAULT};
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
const base::Feature kRefreshExpirationDate{"RefreshExpirationDate", const base::Feature kRefreshExpirationDate{"RefreshExpirationDate",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
......
...@@ -23,11 +23,6 @@ COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature ...@@ -23,11 +23,6 @@ COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature
// Whether a download can be handled by parallel jobs. // Whether a download can be handled by parallel jobs.
COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature kParallelDownloading; COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature kParallelDownloading;
// Whether metadata for new in-progress downloads will be be stored in download
// DB, rather than history DB.
COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature
kDownloadDBForNewDownloads;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Whether download expiration date will be refreshed on resumption. // Whether download expiration date will be refreshed on resumption.
COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature kRefreshExpirationDate; COMPONENTS_DOWNLOAD_EXPORT extern const base::Feature kRefreshExpirationDate;
......
...@@ -23,6 +23,14 @@ COMPONENTS_DOWNLOAD_EXPORT void SetIOTaskRunner( ...@@ -23,6 +23,14 @@ COMPONENTS_DOWNLOAD_EXPORT void SetIOTaskRunner(
COMPONENTS_DOWNLOAD_EXPORT scoped_refptr<base::SingleThreadTaskRunner> COMPONENTS_DOWNLOAD_EXPORT scoped_refptr<base::SingleThreadTaskRunner>
GetIOTaskRunner(); GetIOTaskRunner();
// Sets the task runner for download DB, must be called on UI thread.
COMPONENTS_DOWNLOAD_EXPORT void SetDownloadDBTaskRunnerForTesting(
const scoped_refptr<base::SequencedTaskRunner>& task_runner);
// Gets the task runner for download DB, must be called on UI thread.
COMPONENTS_DOWNLOAD_EXPORT scoped_refptr<base::SequencedTaskRunner>
GetDownloadDBTaskRunnerForTesting();
} // namespace download } // namespace download
#endif // COMPONENTS_DOWNLOAD_PUBLIC_COMMON_DOWNLOAD_TASK_RUNNER_H_ #endif // COMPONENTS_DOWNLOAD_PUBLIC_COMMON_DOWNLOAD_TASK_RUNNER_H_
...@@ -175,11 +175,9 @@ class DownloadItemFactoryImpl : public download::DownloadItemFactory { ...@@ -175,11 +175,9 @@ class DownloadItemFactoryImpl : public download::DownloadItemFactory {
bool transient, bool transient,
const std::vector<download::DownloadItem::ReceivedSlice>& received_slices) const std::vector<download::DownloadItem::ReceivedSlice>& received_slices)
override { override {
int auto_resume_count = 0; // For history download only as history don't have auto resumption count
if (base::FeatureList::IsEnabled( // saved.
download::features::kDownloadDBForNewDownloads)) { int auto_resume_count = download::DownloadItemImpl::kMaxAutoResumeAttempts;
auto_resume_count = download::DownloadItemImpl::kMaxAutoResumeAttempts;
}
return new download::DownloadItemImpl( return new download::DownloadItemImpl(
delegate, guid, download_id, current_path, target_path, url_chain, delegate, guid, download_id, current_path, target_path, url_chain,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment