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

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

Issue 9817018: Cleaning Up Extensions When Local Content Removed (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed preexisting race condition Created 8 years, 8 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 #include "webkit/database/database_tracker.h" 107 #include "webkit/database/database_tracker.h"
108 #include "webkit/database/database_util.h" 108 #include "webkit/database/database_util.h"
109 109
110 #if defined(OS_CHROMEOS) 110 #if defined(OS_CHROMEOS)
111 #include "chrome/browser/chromeos/cros/cros_library.h" 111 #include "chrome/browser/chromeos/cros/cros_library.h"
112 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" 112 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
113 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" 113 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h"
114 #include "chrome/browser/chromeos/extensions/input_method_event_router.h" 114 #include "chrome/browser/chromeos/extensions/input_method_event_router.h"
115 #include "chrome/browser/chromeos/extensions/media_player_event_router.h" 115 #include "chrome/browser/chromeos/extensions/media_player_event_router.h"
116 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 116 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
117 #include "chrome/browser/extensions/extension_input_ime_api.h"
118 #include "webkit/fileapi/file_system_context.h" 117 #include "webkit/fileapi/file_system_context.h"
119 #include "webkit/fileapi/file_system_mount_point_provider.h" 118 #include "webkit/fileapi/file_system_mount_point_provider.h"
120 #endif 119 #endif
121 120
122 #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD) 121 #if defined(OS_CHROMEOS) && defined(USE_VIRTUAL_KEYBOARD)
123 #include "chrome/browser/extensions/extension_input_ui_api.h" 122 #include "chrome/browser/extensions/extension_input_ui_api.h"
124 #endif 123 #endif
125 124
126 using base::Time; 125 using base::Time;
127 using content::BrowserContext; 126 using content::BrowserContext;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 373
375 ExtensionService::ExtensionService(Profile* profile, 374 ExtensionService::ExtensionService(Profile* profile,
376 const CommandLine* command_line, 375 const CommandLine* command_line,
377 const FilePath& install_directory, 376 const FilePath& install_directory,
378 ExtensionPrefs* extension_prefs, 377 ExtensionPrefs* extension_prefs,
379 bool autoupdate_enabled, 378 bool autoupdate_enabled,
380 bool extensions_enabled) 379 bool extensions_enabled)
381 : profile_(profile), 380 : profile_(profile),
382 system_(ExtensionSystemFactory::GetForProfile(profile)), 381 system_(ExtensionSystemFactory::GetForProfile(profile)),
383 extension_prefs_(extension_prefs), 382 extension_prefs_(extension_prefs),
383 extension_garbage_collector_(new ExtensionGarbageCollector(this)),
384 settings_frontend_(extensions::SettingsFrontend::Create(profile)), 384 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
385 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), 385 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
386 install_directory_(install_directory), 386 install_directory_(install_directory),
387 extensions_enabled_(extensions_enabled), 387 extensions_enabled_(extensions_enabled),
388 show_extensions_prompts_(true), 388 show_extensions_prompts_(true),
389 ready_(false), 389 ready_(false),
390 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 390 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
391 menu_manager_(profile), 391 menu_manager_(profile),
392 app_notification_manager_(new AppNotificationManager(profile)), 392 app_notification_manager_(new AppNotificationManager(profile)),
393 apps_promo_(profile->GetPrefs()), 393 apps_promo_(profile->GetPrefs()),
(...skipping 1497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 // Keep information about the extension so that we can reload it later 1891 // Keep information about the extension so that we can reload it later
1892 // even if it's not permanently installed. 1892 // even if it's not permanently installed.
1893 unloaded_extension_paths_[extension->id()] = extension->path(); 1893 unloaded_extension_paths_[extension->id()] = extension->path();
1894 1894
1895 // Clean up if the extension is meant to be enabled after a reload. 1895 // Clean up if the extension is meant to be enabled after a reload.
1896 disabled_extension_paths_.erase(extension->id()); 1896 disabled_extension_paths_.erase(extension->id());
1897 1897
1898 // Clean up runtime data. 1898 // Clean up runtime data.
1899 extension_runtime_data_.erase(extension_id); 1899 extension_runtime_data_.erase(extension_id);
1900 1900
1901 if (disabled_extensions_.Contains(extension->id())) { 1901 if (disabled_extensions_.Contains(extension->id())) {
1902 UnloadedExtensionInfo details(extension, reason); 1902 UnloadedExtensionInfo details(extension, reason);
1903 details.already_disabled = true; 1903 details.already_disabled = true;
1904 disabled_extensions_.Remove(extension->id()); 1904 disabled_extensions_.Remove(extension->id());
1905 content::NotificationService::current()->Notify( 1905 content::NotificationService::current()->Notify(
1906 chrome::NOTIFICATION_EXTENSION_UNLOADED, 1906 chrome::NOTIFICATION_EXTENSION_UNLOADED,
1907 content::Source<Profile>(profile_), 1907 content::Source<Profile>(profile_),
1908 content::Details<UnloadedExtensionInfo>(&details)); 1908 content::Details<UnloadedExtensionInfo>(&details));
1909 // Make sure the profile cleans up its RequestContexts when an already 1909 // Make sure the profile cleans up its RequestContexts when an already
1910 // disabled extension is unloaded (since they are also tracking the disabled 1910 // disabled extension is unloaded (since they are also tracking the disabled
1911 // extensions). 1911 // extensions).
(...skipping 21 matching lines...) Expand all
1933 // or uninstalled, and UnloadAll is just part of shutdown. 1933 // or uninstalled, and UnloadAll is just part of shutdown.
1934 } 1934 }
1935 1935
1936 void ExtensionService::ReloadExtensions() { 1936 void ExtensionService::ReloadExtensions() {
1937 UnloadAllExtensions(); 1937 UnloadAllExtensions();
1938 component_loader_->LoadAll(); 1938 component_loader_->LoadAll();
1939 extensions::InstalledLoader(this).LoadAllExtensions(); 1939 extensions::InstalledLoader(this).LoadAllExtensions();
1940 } 1940 }
1941 1941
1942 void ExtensionService::GarbageCollectExtensions() { 1942 void ExtensionService::GarbageCollectExtensions() {
1943 if (extension_prefs_->pref_service()->ReadOnly()) 1943 extension_garbage_collector_->GarbageCollectExtensions();
1944 return;
1945
1946 scoped_ptr<ExtensionPrefs::ExtensionsInfo> info(
1947 extension_prefs_->GetInstalledExtensionsInfo());
1948
1949 std::map<std::string, FilePath> extension_paths;
1950 for (size_t i = 0; i < info->size(); ++i)
1951 extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path;
1952
1953 if (!BrowserThread::PostTask(
1954 BrowserThread::FILE, FROM_HERE,
1955 base::Bind(
1956 &extension_file_util::GarbageCollectExtensions,
1957 install_directory_,
1958 extension_paths)))
1959 NOTREACHED();
1960 1944
1961 // Also garbage-collect themes. We check |profile_| to be 1945 // Also garbage-collect themes. We check |profile_| to be
1962 // defensive; in the future, we may call GarbageCollectExtensions() 1946 // defensive; in the future, we may call GarbageCollectExtensions()
1963 // from somewhere other than Init() (e.g., in a timer). 1947 // from somewhere other than Init() (e.g., in a timer).
1964 if (profile_) { 1948 if (profile_) {
1965 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes(); 1949 ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes();
1966 } 1950 }
1967 } 1951 }
1968 1952
1969 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { 1953 void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 // to a version that requires additional privileges. 2114 // to a version that requires additional privileges.
2131 is_privilege_increase = 2115 is_privilege_increase =
2132 granted_permissions->HasLessPrivilegesThan( 2116 granted_permissions->HasLessPrivilegesThan(
2133 extension->GetActivePermissions()); 2117 extension->GetActivePermissions());
2134 } 2118 }
2135 2119
2136 if (is_extension_upgrade) { 2120 if (is_extension_upgrade) {
2137 // Other than for unpacked extensions, CrxInstaller should have guaranteed 2121 // Other than for unpacked extensions, CrxInstaller should have guaranteed
2138 // that we aren't downgrading. 2122 // that we aren't downgrading.
2139 if (extension->location() != Extension::LOAD) 2123 if (extension->location() != Extension::LOAD)
2140 CHECK(extension->version()->CompareTo(*(old->version())) >= 0); 2124 CHECK_GE(extension->version()->CompareTo(*(old->version())), 0);
2141 2125
2142 // Extensions get upgraded if the privileges are allowed to increase or 2126 // Extensions get upgraded if the privileges are allowed to increase or
2143 // the privileges haven't increased. 2127 // the privileges haven't increased.
2144 if (!is_privilege_increase) { 2128 if (!is_privilege_increase) {
2145 SetBeingUpgraded(old, true); 2129 SetBeingUpgraded(old, true);
2146 SetBeingUpgraded(extension, true); 2130 SetBeingUpgraded(extension, true);
2147 } 2131 }
2148 2132
2149 // To upgrade an extension in place, unload the old one and 2133 // To upgrade an extension in place, unload the old one and
2150 // then load the new one. 2134 // then load the new one.
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 return api_resource_controller_; 2630 return api_resource_controller_;
2647 } 2631 }
2648 2632
2649 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { 2633 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() {
2650 if (!rules_registry_service_.get()) { 2634 if (!rules_registry_service_.get()) {
2651 rules_registry_service_.reset( 2635 rules_registry_service_.reset(
2652 new extensions::RulesRegistryService(profile_)); 2636 new extensions::RulesRegistryService(profile_));
2653 } 2637 }
2654 return rules_registry_service_.get(); 2638 return rules_registry_service_.get();
2655 } 2639 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698