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

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

Powered by Google App Engine
This is Rietveld 408576698