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

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

Issue 10541126: Cleaning Up Extensions When Local Content Removed (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master merge Created 8 years, 6 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
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/extensions/extension_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 #include "webkit/database/database_tracker.h" 112 #include "webkit/database/database_tracker.h"
113 #include "webkit/database/database_util.h" 113 #include "webkit/database/database_util.h"
114 114
115 #if defined(OS_CHROMEOS) 115 #if defined(OS_CHROMEOS)
116 #include "chrome/browser/chromeos/cros/cros_library.h" 116 #include "chrome/browser/chromeos/cros/cros_library.h"
117 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" 117 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
118 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" 118 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
119 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 119 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
120 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" 120 #include "chrome/browser/chromeos/extensions/media_player_event_router.h"
121 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 121 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
122 #include "chrome/browser/extensions/extension_input_ime_api.h"
123 #include "webkit/fileapi/file_system_context.h" 122 #include "webkit/fileapi/file_system_context.h"
124 #include "webkit/fileapi/file_system_mount_point_provider.h" 123 #include "webkit/fileapi/file_system_mount_point_provider.h"
125 #endif 124 #endif
126 125
127 using base::Time; 126 using base::Time;
128 using content::BrowserContext; 127 using content::BrowserContext;
129 using content::BrowserThread; 128 using content::BrowserThread;
130 using content::DevToolsAgentHost; 129 using content::DevToolsAgentHost;
131 using content::DevToolsAgentHostRegistry; 130 using content::DevToolsAgentHostRegistry;
132 using content::PluginService; 131 using content::PluginService;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 317
319 ExtensionService::ExtensionService(Profile* profile, 318 ExtensionService::ExtensionService(Profile* profile,
320 const CommandLine* command_line, 319 const CommandLine* command_line,
321 const FilePath& install_directory, 320 const FilePath& install_directory,
322 ExtensionPrefs* extension_prefs, 321 ExtensionPrefs* extension_prefs,
323 bool autoupdate_enabled, 322 bool autoupdate_enabled,
324 bool extensions_enabled) 323 bool extensions_enabled)
325 : profile_(profile), 324 : profile_(profile),
326 system_(ExtensionSystem::Get(profile)), 325 system_(ExtensionSystem::Get(profile)),
327 extension_prefs_(extension_prefs), 326 extension_prefs_(extension_prefs),
327 extension_garbage_collector_(
328 new extensions::ExtensionGarbageCollector(this)),
328 settings_frontend_(extensions::SettingsFrontend::Create(profile)), 329 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
329 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), 330 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
330 install_directory_(install_directory), 331 install_directory_(install_directory),
331 extensions_enabled_(extensions_enabled), 332 extensions_enabled_(extensions_enabled),
332 show_extensions_prompts_(true), 333 show_extensions_prompts_(true),
333 ready_(false), 334 ready_(false),
334 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 335 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
335 menu_manager_(profile), 336 menu_manager_(profile),
336 app_notification_manager_(new AppNotificationManager(profile)), 337 app_notification_manager_(new AppNotificationManager(profile)),
337 apps_promo_(profile->GetPrefs()), 338 apps_promo_(profile->GetPrefs()),
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1796 // Keep information about the extension so that we can reload it later 1797 // Keep information about the extension so that we can reload it later
1797 // even if it's not permanently installed. 1798 // even if it's not permanently installed.
1798 unloaded_extension_paths_[extension->id()] = extension->path(); 1799 unloaded_extension_paths_[extension->id()] = extension->path();
1799 1800
1800 // Clean up if the extension is meant to be enabled after a reload. 1801 // Clean up if the extension is meant to be enabled after a reload.
1801 disabled_extension_paths_.erase(extension->id()); 1802 disabled_extension_paths_.erase(extension->id());
1802 1803
1803 // Clean up runtime data. 1804 // Clean up runtime data.
1804 extension_runtime_data_.erase(extension_id); 1805 extension_runtime_data_.erase(extension_id);
1805 1806
1806 if (disabled_extensions_.Contains(extension->id())) { 1807 if (disabled_extensions_.Contains(extension->id())) {
1807 UnloadedExtensionInfo details(extension, reason); 1808 UnloadedExtensionInfo details(extension, reason);
1808 details.already_disabled = true; 1809 details.already_disabled = true;
1809 disabled_extensions_.Remove(extension->id()); 1810 disabled_extensions_.Remove(extension->id());
1810 content::NotificationService::current()->Notify( 1811 content::NotificationService::current()->Notify(
1811 chrome::NOTIFICATION_EXTENSION_UNLOADED, 1812 chrome::NOTIFICATION_EXTENSION_UNLOADED,
1812 content::Source<Profile>(profile_), 1813 content::Source<Profile>(profile_),
1813 content::Details<UnloadedExtensionInfo>(&details)); 1814 content::Details<UnloadedExtensionInfo>(&details));
1814 // Make sure the profile cleans up its RequestContexts when an already 1815 // Make sure the profile cleans up its RequestContexts when an already
1815 // disabled extension is unloaded (since they are also tracking the disabled 1816 // disabled extension is unloaded (since they are also tracking the disabled
1816 // extensions). 1817 // extensions).
(...skipping 21 matching lines...) Expand all
1838 // or uninstalled, and UnloadAll is just part of shutdown. 1839 // or uninstalled, and UnloadAll is just part of shutdown.
1839 } 1840 }
1840 1841
1841 void ExtensionService::ReloadExtensions() { 1842 void ExtensionService::ReloadExtensions() {
1842 UnloadAllExtensions(); 1843 UnloadAllExtensions();
1843 component_loader_->LoadAll(); 1844 component_loader_->LoadAll();
1844 extensions::InstalledLoader(this).LoadAllExtensions(); 1845 extensions::InstalledLoader(this).LoadAllExtensions();
1845 } 1846 }
1846 1847
1847 void ExtensionService::GarbageCollectExtensions() { 1848 void ExtensionService::GarbageCollectExtensions() {
1848 if (extension_prefs_->pref_service()->ReadOnly()) 1849 extension_garbage_collector_->GarbageCollectExtensions();
1849 return;
1850
1851 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(
1852 extension_prefs_->GetInstalledExtensionsInfo());
1853
1854 std::map<std::string, FilePath> extension_paths;
1855 for (size_t i = 0; i < info->size(); ++i)
1856 extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path;
1857
1858 if (!BrowserThread::PostTask(
1859 BrowserThread::FILE, FROM_HERE,
1860 base::Bind(
1861 &extension_file_util::GarbageCollectExtensions,
1862 install_directory_,
1863 extension_paths)))
1864 NOTREACHED();
1865 1850
1866 // Also garbage-collect themes. We check |profile_| to be 1851 // Also garbage-collect themes. We check |profile_| to be
1867 // defensive; in the future, we may call GarbageCollectExtensions() 1852 // defensive; in the future, we may call GarbageCollectExtensions()
1868 // from somewhere other than Init() (e.g., in a timer). 1853 // from somewhere other than Init() (e.g., in a timer).
1869 if (profile_) { 1854 if (profile_) {
1870 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes(); 1855 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
1871 } 1856 }
1872 } 1857 }
1873 1858
1874 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { 1859 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2020 // to a version that requires additional privileges. 2005 // to a version that requires additional privileges.
2021 is_privilege_increase = 2006 is_privilege_increase =
2022 granted_permissions->HasLessPrivilegesThan( 2007 granted_permissions->HasLessPrivilegesThan(
2023 extension->GetActivePermissions()); 2008 extension->GetActivePermissions());
2024 } 2009 }
2025 2010
2026 if (is_extension_upgrade) { 2011 if (is_extension_upgrade) {
2027 // Other than for unpacked extensions, CrxInstaller should have guaranteed 2012 // Other than for unpacked extensions, CrxInstaller should have guaranteed
2028 // that we aren't downgrading. 2013 // that we aren't downgrading.
2029 if (extension->location() != Extension::LOAD) 2014 if (extension->location() != Extension::LOAD)
2030 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); 2015 CHECK_GE(extension->version()->CompareTo(*(old->version())), 0);
2031 2016
2032 // Extensions get upgraded if the privileges are allowed to increase or 2017 // Extensions get upgraded if the privileges are allowed to increase or
2033 // the privileges haven't increased. 2018 // the privileges haven't increased.
2034 if (!is_privilege_increase) { 2019 if (!is_privilege_increase) {
2035 SetBeingUpgraded(old, true); 2020 SetBeingUpgraded(old, true);
2036 SetBeingUpgraded(extension, true); 2021 SetBeingUpgraded(extension, true);
2037 } 2022 }
2038 2023
2039 // If the extension was already disabled, suppress any alerts for becoming 2024 // If the extension was already disabled, suppress any alerts for becoming
2040 // disabled on permissions increase. 2025 // disabled on permissions increase.
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 2535
2551 // To coexist with certain unit tests that don't have a work-thread message 2536 // To coexist with certain unit tests that don't have a work-thread message
2552 // loop available at ExtensionService shutdown, we lazy-initialize this 2537 // loop available at ExtensionService shutdown, we lazy-initialize this
2553 // object so that those cases neither create nor destroy an 2538 // object so that those cases neither create nor destroy an
2554 // APIResourceController. 2539 // APIResourceController.
2555 if (!api_resource_controller_.get()) { 2540 if (!api_resource_controller_.get()) {
2556 api_resource_controller_.reset(new extensions::APIResourceController()); 2541 api_resource_controller_.reset(new extensions::APIResourceController());
2557 } 2542 }
2558 return api_resource_controller_.get(); 2543 return api_resource_controller_.get();
2559 } 2544 }
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