Commit 2e3363b6 authored by treib@chromium.org's avatar treib@chromium.org

Before deleting a profile, cancel all in-progress downloads to prevent a "Do...

Before deleting a profile, cancel all in-progress downloads to prevent a "Do you really want to exit Chrome" popup, which (1) is confusing because the message is not accurate, and (2) prevents a window corresponding to the deleted profile from closing, leaving it in an inconsistent state.

A UI update (warning the user that downloads will be canceled) will follow in a separate CL.

Note: I'm aware that this doesn't address crbug.com/289390 which is another way to trigger the same underlying bug. Working on it...

BUG=336725

Review URL: https://codereview.chromium.org/214523003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262970 0039d316-1c4b-4281-b951-d872f2087c98
parent 93c0393e
......@@ -95,6 +95,22 @@ int DownloadService::NonMaliciousDownloadCount() const {
NonMaliciousInProgressCount();
}
void DownloadService::CancelDownloads() {
if (!download_manager_created_)
return;
DownloadManager* download_manager =
BrowserContext::GetDownloadManager(profile_);
DownloadManager::DownloadVector downloads;
download_manager->GetAllDownloads(&downloads);
for (DownloadManager::DownloadVector::iterator it = downloads.begin();
it != downloads.end();
++it) {
if ((*it)->GetState() == content::DownloadItem::IN_PROGRESS)
(*it)->Cancel(false);
}
}
// static
int DownloadService::NonMaliciousDownloadCountAllProfiles() {
std::vector<Profile*> profiles(
......@@ -120,17 +136,9 @@ void DownloadService::CancelAllDownloads() {
for (std::vector<Profile*>::iterator it = profiles.begin();
it < profiles.end();
++it) {
content::DownloadManager* download_manager =
content::BrowserContext::GetDownloadManager(*it);
content::DownloadManager::DownloadVector downloads;
download_manager->GetAllDownloads(&downloads);
for (content::DownloadManager::DownloadVector::iterator it =
downloads.begin();
it != downloads.end();
++it) {
if ((*it)->GetState() == content::DownloadItem::IN_PROGRESS)
(*it)->Cancel(false);
}
DownloadService* service =
DownloadServiceFactory::GetForBrowserContext(*it);
service->CancelDownloads();
}
}
......
......@@ -47,10 +47,13 @@ class DownloadService : public KeyedService {
// service.
int NonMaliciousDownloadCount() const;
// Cancels all in-progress downloads for this profile.
void CancelDownloads();
// Number of non-malicious downloads associated with all profiles.
static int NonMaliciousDownloadCountAllProfiles();
// Cancels all in-progress downloads.
// Cancels all in-progress downloads for all profiles.
static void CancelAllDownloads();
// Sets the DownloadManagerDelegate associated with this object and
......
......@@ -24,6 +24,8 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/download/download_service.h"
#include "chrome/browser/download/download_service_factory.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
......@@ -633,6 +635,17 @@ void ProfileManager::ScheduleProfileForDeletion(
const base::FilePath& profile_dir,
const CreateCallback& callback) {
DCHECK(profiles::IsMultipleProfilesEnabled());
// Cancel all in-progress downloads before deleting the profile to prevent a
// "Do you want to exit Google Chrome and cancel the downloads?" prompt
// (crbug.com/336725).
Profile* profile = GetProfileByPath(profile_dir);
if (profile) {
DownloadService* service =
DownloadServiceFactory::GetForBrowserContext(profile);
service->CancelDownloads();
}
PrefService* local_state = g_browser_process->local_state();
ProfileInfoCache& cache = GetProfileInfoCache();
......@@ -1072,6 +1085,10 @@ void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) {
Profile* profile = GetProfileByPath(profile_dir);
if (profile) {
// By this point, all in-progress downloads for the profile being deleted
// must have been canceled (crbug.com/336725).
DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)->
NonMaliciousDownloadCount() == 0);
BrowserList::CloseAllBrowsersWithProfile(profile);
// Disable sync for doomed profile.
......
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