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

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

Powered by Google App Engine
This is Rietveld 408576698