Commit 2ab1d14e authored by Min Qin's avatar Min Qin Committed by Commit Bot

Move InProgressDownloadManager creation logic into DownloadManagerUtils

Currently InProgressDownloadManager is created in DownloadManagerImpl.
However, for content layer, we don't need to create the in-progress DB.
As a result, This CL move InProgressDownloadManager creation to Chrome layer,
it also allows us to construct the SimpleFactoryKey from the profile,
which can later be used to create the SimpleDownloadManagerCoordinator.

BUG=942770

Change-Id: I8f020f2685dd0d6972c56ab1225b440c3c73051b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1555010Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648745}
parent 625c29d9
...@@ -426,6 +426,8 @@ jumbo_split_static_library("browser") { ...@@ -426,6 +426,8 @@ jumbo_split_static_library("browser") {
"download/download_item_model.h", "download/download_item_model.h",
"download/download_location_dialog_result.h", "download/download_location_dialog_result.h",
"download/download_location_dialog_type.h", "download/download_location_dialog_type.h",
"download/download_manager_utils.cc",
"download/download_manager_utils.h",
"download/download_offline_content_provider.cc", "download/download_offline_content_provider.cc",
"download/download_offline_content_provider.h", "download/download_offline_content_provider.h",
"download/download_permission_request.cc", "download/download_permission_request.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/download/download_manager_utils.h"
#include "base/bind.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "components/download/public/common/in_progress_download_manager.h"
#include "content/public/browser/download_request_utils.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/download/download_manager_service.h"
#endif
// Ignores origin security check. DownloadManagerImpl will provide its own
// implementation when InProgressDownloadManager object is passed to it.
bool IgnoreOriginSecurityCheck(const GURL& url) {
return true;
}
download::InProgressDownloadManager*
DownloadManagerUtils::RetrieveInProgressDownloadManager(Profile* profile) {
// TODO(qinmin): use the profile to retrieve SimpleFactoryKey and
// create SimpleDownloadManagerCoordinator.
#if defined(OS_ANDROID)
download::InProgressDownloadManager* manager =
DownloadManagerService::GetInstance()->RetriveInProgressDownloadManager(
profile);
if (manager)
return manager;
#endif
return new download::InProgressDownloadManager(
nullptr,
profile->IsOffTheRecord() ? base::FilePath() : profile->GetPath(),
base::BindRepeating(&IgnoreOriginSecurityCheck),
base::BindRepeating(&content::DownloadRequestUtils::IsURLSafe));
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_UTILS_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_UTILS_H_
#include "base/macros.h"
class Profile;
namespace download {
class InProgressDownloadManager;
}
class DownloadManagerUtils {
public:
// Creates an InProgressDownloadManager from a profile.
static download::InProgressDownloadManager* RetrieveInProgressDownloadManager(
Profile* profile);
private:
DISALLOW_COPY_AND_ASSIGN(DownloadManagerUtils);
};
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_UTILS_H_
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service.h" #include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h" #include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_manager_utils.h"
#include "chrome/browser/gcm/gcm_profile_service_factory.h" #include "chrome/browser/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/media/media_device_id_salt.h" #include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/net/system_network_context_manager.h" #include "chrome/browser/net/system_network_context_manager.h"
...@@ -190,9 +191,7 @@ ...@@ -190,9 +191,7 @@
#endif #endif
#if defined(OS_ANDROID) #if !defined(OS_ANDROID)
#include "chrome/browser/android/download/download_manager_service.h"
#else
#include "chrome/services/app_service/app_service.h" #include "chrome/services/app_service/app_service.h"
#include "chrome/services/app_service/public/mojom/constants.mojom.h" #include "chrome/services/app_service/public/mojom/constants.mojom.h"
#include "components/zoom/zoom_event_manager.h" #include "components/zoom/zoom_event_manager.h"
...@@ -1330,12 +1329,7 @@ std::string ProfileImpl::GetMediaDeviceIDSalt() { ...@@ -1330,12 +1329,7 @@ std::string ProfileImpl::GetMediaDeviceIDSalt() {
download::InProgressDownloadManager* download::InProgressDownloadManager*
ProfileImpl::RetriveInProgressDownloadManager() { ProfileImpl::RetriveInProgressDownloadManager() {
#if defined(OS_ANDROID) return DownloadManagerUtils::RetrieveInProgressDownloadManager(this);
return DownloadManagerService::GetInstance()
->RetriveInProgressDownloadManager(this);
#else
return nullptr;
#endif
} }
bool ProfileImpl::IsSameProfile(Profile* profile) { bool ProfileImpl::IsSameProfile(Profile* profile) {
......
...@@ -338,9 +338,7 @@ DownloadManagerImpl::DownloadManagerImpl(BrowserContext* browser_context) ...@@ -338,9 +338,7 @@ DownloadManagerImpl::DownloadManagerImpl(BrowserContext* browser_context)
if (!in_progress_manager_) { if (!in_progress_manager_) {
in_progress_manager_ = in_progress_manager_ =
std::make_unique<download::InProgressDownloadManager>( std::make_unique<download::InProgressDownloadManager>(
this, this, base::FilePath(), base::BindRepeating(&IsOriginSecure),
IsOffTheRecord() ? base::FilePath() : browser_context_->GetPath(),
base::BindRepeating(&IsOriginSecure),
base::BindRepeating(&DownloadRequestUtils::IsURLSafe)); base::BindRepeating(&DownloadRequestUtils::IsURLSafe));
} else { } else {
in_progress_manager_->set_delegate(this); in_progress_manager_->set_delegate(this);
......
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