Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 214523003: Before deleting a profile, cancel all in-progress downloads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/profiles/profile_manager.h" 5 #include "chrome/browser/profiles/profile_manager.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/deferred_sequenced_task_runner.h" 12 #include "base/deferred_sequenced_task_runner.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/files/file_enumerator.h" 14 #include "base/files/file_enumerator.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/prefs/scoped_user_pref_update.h" 18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "chrome/browser/bookmarks/bookmark_model.h" 22 #include "chrome/browser/bookmarks/bookmark_model.h"
23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/content_settings/host_content_settings_map.h" 26 #include "chrome/browser/content_settings/host_content_settings_map.h"
27 #include "chrome/browser/download/download_service.h"
28 #include "chrome/browser/download/download_service_factory.h"
27 #include "chrome/browser/prefs/incognito_mode_prefs.h" 29 #include "chrome/browser/prefs/incognito_mode_prefs.h"
28 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h" 30 #include "chrome/browser/profiles/bookmark_model_loaded_observer.h"
29 #include "chrome/browser/profiles/profile_destroyer.h" 31 #include "chrome/browser/profiles/profile_destroyer.h"
30 #include "chrome/browser/profiles/profile_info_cache.h" 32 #include "chrome/browser/profiles/profile_info_cache.h"
31 #include "chrome/browser/profiles/profile_metrics.h" 33 #include "chrome/browser/profiles/profile_metrics.h"
32 #include "chrome/browser/profiles/profiles_state.h" 34 #include "chrome/browser/profiles/profiles_state.h"
33 #include "chrome/browser/profiles/startup_task_runner_service.h" 35 #include "chrome/browser/profiles/startup_task_runner_service.h"
34 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" 36 #include "chrome/browser/profiles/startup_task_runner_service_factory.h"
35 #include "chrome/browser/signin/account_reconcilor_factory.h" 37 #include "chrome/browser/signin/account_reconcilor_factory.h"
36 #include "chrome/browser/sync/profile_sync_service.h" 38 #include "chrome/browser/sync/profile_sync_service.h"
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 627 }
626 628
627 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() { 629 ProfileShortcutManager* ProfileManager::profile_shortcut_manager() {
628 return profile_shortcut_manager_.get(); 630 return profile_shortcut_manager_.get();
629 } 631 }
630 632
631 void ProfileManager::ScheduleProfileForDeletion( 633 void ProfileManager::ScheduleProfileForDeletion(
632 const base::FilePath& profile_dir, 634 const base::FilePath& profile_dir,
633 const CreateCallback& callback) { 635 const CreateCallback& callback) {
634 DCHECK(profiles::IsMultipleProfilesEnabled()); 636 DCHECK(profiles::IsMultipleProfilesEnabled());
637
638 // Cancel all in-progress downloads before deleting the profile to prevent a
639 // "Do you want to exit Google Chrome and cancel the downloads?" prompt
640 // (crbug.com/336725).
641 Profile* profile = GetProfileByPath(profile_dir);
642 if (profile) {
643 DownloadService* service =
644 DownloadServiceFactory::GetForBrowserContext(profile);
645 service->CancelDownloads();
646 }
647
635 PrefService* local_state = g_browser_process->local_state(); 648 PrefService* local_state = g_browser_process->local_state();
636 ProfileInfoCache& cache = GetProfileInfoCache(); 649 ProfileInfoCache& cache = GetProfileInfoCache();
637 650
638 if (profile_dir.BaseName().MaybeAsASCII() == 651 if (profile_dir.BaseName().MaybeAsASCII() ==
639 local_state->GetString(prefs::kProfileLastUsed)) { 652 local_state->GetString(prefs::kProfileLastUsed)) {
640 // Update the last used profile pref before closing browser windows. This 653 // Update the last used profile pref before closing browser windows. This
641 // way the correct last used profile is set for any notification observers. 654 // way the correct last used profile is set for any notification observers.
642 base::FilePath last_non_managed_profile_path; 655 base::FilePath last_non_managed_profile_path;
643 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) { 656 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) {
644 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i); 657 base::FilePath cur_path = cache.GetPathOfProfileAtIndex(i);
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 return true; 1077 return true;
1065 } 1078 }
1066 1079
1067 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) { 1080 void ProfileManager::FinishDeletingProfile(const base::FilePath& profile_dir) {
1068 ProfileInfoCache& cache = GetProfileInfoCache(); 1081 ProfileInfoCache& cache = GetProfileInfoCache();
1069 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we 1082 // TODO(sail): Due to bug 88586 we don't delete the profile instance. Once we
1070 // start deleting the profile instance we need to close background apps too. 1083 // start deleting the profile instance we need to close background apps too.
1071 Profile* profile = GetProfileByPath(profile_dir); 1084 Profile* profile = GetProfileByPath(profile_dir);
1072 1085
1073 if (profile) { 1086 if (profile) {
1087 // By this point, all in-progress downloads for the profile being deleted
1088 // must have been canceled (crbug.com/336725).
1089 DCHECK(DownloadServiceFactory::GetForBrowserContext(profile)->
1090 NonMaliciousDownloadCount() == 0);
1074 BrowserList::CloseAllBrowsersWithProfile(profile); 1091 BrowserList::CloseAllBrowsersWithProfile(profile);
1075 1092
1076 // Disable sync for doomed profile. 1093 // Disable sync for doomed profile.
1077 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( 1094 if (ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
1078 profile)) { 1095 profile)) {
1079 ProfileSyncServiceFactory::GetInstance()->GetForProfile( 1096 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
1080 profile)->DisableForUser(); 1097 profile)->DisableForUser();
1081 } 1098 }
1082 } 1099 }
1083 1100
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 last_non_managed_profile_path.BaseName().MaybeAsASCII()); 1283 last_non_managed_profile_path.BaseName().MaybeAsASCII());
1267 FinishDeletingProfile(profile_to_delete_path); 1284 FinishDeletingProfile(profile_to_delete_path);
1268 } 1285 }
1269 } 1286 }
1270 } 1287 }
1271 #endif 1288 #endif
1272 1289
1273 ProfileManagerWithoutInit::ProfileManagerWithoutInit( 1290 ProfileManagerWithoutInit::ProfileManagerWithoutInit(
1274 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) { 1291 const base::FilePath& user_data_dir) : ProfileManager(user_data_dir) {
1275 } 1292 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698