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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 266343002: Unload all apps / extensions when deleting a profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Do not send NULL extension pointer in notifications. Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extensions/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 10
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 extensions_enabled_ = false; 294 extensions_enabled_ = false;
295 295
296 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, 296 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
297 content::NotificationService::AllBrowserContextsAndSources()); 297 content::NotificationService::AllBrowserContextsAndSources());
298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 298 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
299 content::NotificationService::AllBrowserContextsAndSources()); 299 content::NotificationService::AllBrowserContextsAndSources());
300 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 300 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
301 content::NotificationService::AllBrowserContextsAndSources()); 301 content::NotificationService::AllBrowserContextsAndSources());
302 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, 302 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
303 content::NotificationService::AllBrowserContextsAndSources()); 303 content::NotificationService::AllBrowserContextsAndSources());
304 registrar_.Add(this,
305 chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
306 content::Source<Profile>(profile_));
304 pref_change_registrar_.Init(profile->GetPrefs()); 307 pref_change_registrar_.Init(profile->GetPrefs());
305 base::Closure callback = 308 base::Closure callback =
306 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged, 309 base::Bind(&ExtensionService::OnExtensionInstallPrefChanged,
307 base::Unretained(this)); 310 base::Unretained(this));
308 pref_change_registrar_.Add(extensions::pref_names::kInstallAllowList, 311 pref_change_registrar_.Add(extensions::pref_names::kInstallAllowList,
309 callback); 312 callback);
310 pref_change_registrar_.Add(extensions::pref_names::kInstallDenyList, 313 pref_change_registrar_.Add(extensions::pref_names::kInstallDenyList,
311 callback); 314 callback);
312 pref_change_registrar_.Add(extensions::pref_names::kAllowedTypes, callback); 315 pref_change_registrar_.Add(extensions::pref_names::kAllowedTypes, callback);
313 316
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 chrome::NOTIFICATION_EXTENSION_REMOVED, 1394 chrome::NOTIFICATION_EXTENSION_REMOVED,
1392 content::Source<Profile>(profile_), 1395 content::Source<Profile>(profile_),
1393 content::Details<const Extension>(extension.get())); 1396 content::Details<const Extension>(extension.get()));
1394 } 1397 }
1395 1398
1396 void ExtensionService::RemoveComponentExtension( 1399 void ExtensionService::RemoveComponentExtension(
1397 const std::string& extension_id) { 1400 const std::string& extension_id) {
1398 scoped_refptr<const Extension> extension( 1401 scoped_refptr<const Extension> extension(
1399 GetExtensionById(extension_id, false)); 1402 GetExtensionById(extension_id, false));
1400 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL); 1403 UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL);
1401 content::NotificationService::current()->Notify( 1404 if (extension.get()) {
1402 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 1405 content::NotificationService::current()->Notify(
1403 content::Source<Profile>(profile_), 1406 chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
1404 content::Details<const Extension>(extension.get())); 1407 content::Source<Profile>(profile_),
1408 content::Details<const Extension>(extension.get()));
1409 }
1405 } 1410 }
1406 1411
1407 void ExtensionService::UnloadAllExtensionsForTest() { 1412 void ExtensionService::UnloadAllExtensionsForTest() {
1408 UnloadAllExtensionsInternal(); 1413 UnloadAllExtensionsInternal();
1409 } 1414 }
1410 1415
1411 void ExtensionService::ReloadExtensionsForTest() { 1416 void ExtensionService::ReloadExtensionsForTest() {
1412 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit 1417 // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit
1413 // warning about calling test code in production. 1418 // warning about calling test code in production.
1414 UnloadAllExtensionsInternal(); 1419 UnloadAllExtensionsInternal();
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 system_->info_map(), 2163 system_->info_map(),
2159 process->GetID())); 2164 process->GetID()));
2160 break; 2165 break;
2161 } 2166 }
2162 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { 2167 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
2163 // Notify observers that chrome update is available. 2168 // Notify observers that chrome update is available.
2164 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, 2169 FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_,
2165 OnChromeUpdateAvailable()); 2170 OnChromeUpdateAvailable());
2166 break; 2171 break;
2167 } 2172 }
2173 case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: {
2174 OnProfileDestructionStarted();
2175 break;
2176 }
2168 2177
2169 default: 2178 default:
2170 NOTREACHED() << "Unexpected notification type."; 2179 NOTREACHED() << "Unexpected notification type.";
2171 } 2180 }
2172 } 2181 }
2173 2182
2174 void ExtensionService::OnExtensionInstallPrefChanged() { 2183 void ExtensionService::OnExtensionInstallPrefChanged() {
2175 error_controller_->ShowErrorIfNeeded(); 2184 error_controller_->ShowErrorIfNeeded();
2176 CheckManagementPolicy(); 2185 CheckManagementPolicy();
2177 } 2186 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 void ExtensionService::UnloadAllExtensionsInternal() { 2430 void ExtensionService::UnloadAllExtensionsInternal() {
2422 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2431 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2423 2432
2424 registry_->ClearAll(); 2433 registry_->ClearAll();
2425 system_->runtime_data()->ClearAll(); 2434 system_->runtime_data()->ClearAll();
2426 2435
2427 // TODO(erikkay) should there be a notification for this? We can't use 2436 // TODO(erikkay) should there be a notification for this? We can't use
2428 // EXTENSION_UNLOADED since that implies that the extension has been disabled 2437 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2429 // or uninstalled. 2438 // or uninstalled.
2430 } 2439 }
2440
2441 void ExtensionService::OnProfileDestructionStarted() {
2442 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2443 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2444 it != ids_to_unload.end();
2445 ++it) {
2446 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2447 }
2448 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698