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

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

Issue 9369013: Take extensions out of Profile into a profile-keyed service, ExtensionSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rerebase Created 8 years, 9 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) 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "chrome/browser/extensions/extension_global_error.h" 45 #include "chrome/browser/extensions/extension_global_error.h"
46 #include "chrome/browser/extensions/extension_host.h" 46 #include "chrome/browser/extensions/extension_host.h"
47 #include "chrome/browser/extensions/extension_input_ime_api.h" 47 #include "chrome/browser/extensions/extension_input_ime_api.h"
48 #include "chrome/browser/extensions/extension_management_api.h" 48 #include "chrome/browser/extensions/extension_management_api.h"
49 #include "chrome/browser/extensions/extension_preference_api.h" 49 #include "chrome/browser/extensions/extension_preference_api.h"
50 #include "chrome/browser/extensions/extension_process_manager.h" 50 #include "chrome/browser/extensions/extension_process_manager.h"
51 #include "chrome/browser/extensions/extension_processes_api.h" 51 #include "chrome/browser/extensions/extension_processes_api.h"
52 #include "chrome/browser/extensions/extension_sorting.h" 52 #include "chrome/browser/extensions/extension_sorting.h"
53 #include "chrome/browser/extensions/extension_special_storage_policy.h" 53 #include "chrome/browser/extensions/extension_special_storage_policy.h"
54 #include "chrome/browser/extensions/extension_sync_data.h" 54 #include "chrome/browser/extensions/extension_sync_data.h"
55 #include "chrome/browser/extensions/extension_system.h"
56 #include "chrome/browser/extensions/extension_system_factory.h"
55 #include "chrome/browser/extensions/extension_updater.h" 57 #include "chrome/browser/extensions/extension_updater.h"
56 #include "chrome/browser/extensions/extension_web_ui.h" 58 #include "chrome/browser/extensions/extension_web_ui.h"
57 #include "chrome/browser/extensions/extension_webnavigation_api.h" 59 #include "chrome/browser/extensions/extension_webnavigation_api.h"
58 #include "chrome/browser/extensions/external_extension_provider_impl.h" 60 #include "chrome/browser/extensions/external_extension_provider_impl.h"
59 #include "chrome/browser/extensions/external_extension_provider_interface.h" 61 #include "chrome/browser/extensions/external_extension_provider_interface.h"
60 #include "chrome/browser/extensions/installed_loader.h" 62 #include "chrome/browser/extensions/installed_loader.h"
61 #include "chrome/browser/extensions/pending_extension_manager.h" 63 #include "chrome/browser/extensions/pending_extension_manager.h"
62 #include "chrome/browser/extensions/permissions_updater.h" 64 #include "chrome/browser/extensions/permissions_updater.h"
63 #include "chrome/browser/extensions/settings/settings_frontend.h" 65 #include "chrome/browser/extensions/settings/settings_frontend.h"
64 #include "chrome/browser/extensions/unpacked_installer.h" 66 #include "chrome/browser/extensions/unpacked_installer.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 return true; 370 return true;
369 } 371 }
370 372
371 ExtensionService::ExtensionService(Profile* profile, 373 ExtensionService::ExtensionService(Profile* profile,
372 const CommandLine* command_line, 374 const CommandLine* command_line,
373 const FilePath& install_directory, 375 const FilePath& install_directory,
374 ExtensionPrefs* extension_prefs, 376 ExtensionPrefs* extension_prefs,
375 bool autoupdate_enabled, 377 bool autoupdate_enabled,
376 bool extensions_enabled) 378 bool extensions_enabled)
377 : profile_(profile), 379 : profile_(profile),
380 system_(ExtensionSystemFactory::GetForProfile(profile)),
378 extension_prefs_(extension_prefs), 381 extension_prefs_(extension_prefs),
379 settings_frontend_(extensions::SettingsFrontend::Create(profile)), 382 settings_frontend_(extensions::SettingsFrontend::Create(profile)),
380 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), 383 pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)),
381 install_directory_(install_directory), 384 install_directory_(install_directory),
382 extensions_enabled_(extensions_enabled), 385 extensions_enabled_(extensions_enabled),
383 show_extensions_prompts_(true), 386 show_extensions_prompts_(true),
384 ready_(false), 387 ready_(false),
385 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 388 toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
386 menu_manager_(profile), 389 menu_manager_(profile),
387 app_notification_manager_(new AppNotificationManager(profile)), 390 app_notification_manager_(new AppNotificationManager(profile)),
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 void ExtensionService::ReloadExtension(const std::string& extension_id) { 688 void ExtensionService::ReloadExtension(const std::string& extension_id) {
686 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 689 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
687 FilePath path; 690 FilePath path;
688 const Extension* current_extension = GetExtensionById(extension_id, false); 691 const Extension* current_extension = GetExtensionById(extension_id, false);
689 692
690 // Disable the extension if it's loaded. It might not be loaded if it crashed. 693 // Disable the extension if it's loaded. It might not be loaded if it crashed.
691 if (current_extension) { 694 if (current_extension) {
692 // If the extension has an inspector open for its background page, detach 695 // If the extension has an inspector open for its background page, detach
693 // the inspector and hang onto a cookie for it, so that we can reattach 696 // the inspector and hang onto a cookie for it, so that we can reattach
694 // later. 697 // later.
695 ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); 698 // TODO(yoz): this is not incognito-safe!
699 ExtensionProcessManager* manager = system_->process_manager();
696 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id); 700 ExtensionHost* host = manager->GetBackgroundHostForExtension(extension_id);
697 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost( 701 if (host && DevToolsAgentHostRegistry::HasDevToolsAgentHost(
698 host->render_view_host())) { 702 host->render_view_host())) {
699 // Look for an open inspector for the background page. 703 // Look for an open inspector for the background page.
700 DevToolsAgentHost* agent = 704 DevToolsAgentHost* agent =
701 DevToolsAgentHostRegistry::GetDevToolsAgentHost( 705 DevToolsAgentHostRegistry::GetDevToolsAgentHost(
702 host->render_view_host()); 706 host->render_view_host());
703 int devtools_cookie = 707 int devtools_cookie =
704 content::DevToolsManager::GetInstance()->DetachClientHost(agent); 708 content::DevToolsManager::GetInstance()->DetachClientHost(agent);
705 if (devtools_cookie >= 0) 709 if (devtools_cookie >= 0)
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 } 978 }
975 } 979 }
976 980
977 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { 981 void ExtensionService::NotifyExtensionLoaded(const Extension* extension) {
978 // The ChromeURLRequestContexts need to be first to know that the extension 982 // The ChromeURLRequestContexts need to be first to know that the extension
979 // was loaded, otherwise a race can arise where a renderer that is created 983 // was loaded, otherwise a race can arise where a renderer that is created
980 // for the extension may try to load an extension URL with an extension id 984 // for the extension may try to load an extension URL with an extension id
981 // that the request context doesn't yet know about. The profile is responsible 985 // that the request context doesn't yet know about. The profile is responsible
982 // for ensuring its URLRequestContexts appropriately discover the loaded 986 // for ensuring its URLRequestContexts appropriately discover the loaded
983 // extension. 987 // extension.
984 profile_->RegisterExtensionWithRequestContexts(extension); 988 system_->RegisterExtensionWithRequestContexts(extension);
985 989
986 // Tell renderers about the new extension, unless it's a theme (renderers 990 // Tell renderers about the new extension, unless it's a theme (renderers
987 // don't need to know about themes). 991 // don't need to know about themes).
988 if (!extension->is_theme()) { 992 if (!extension->is_theme()) {
989 for (content::RenderProcessHost::iterator i( 993 for (content::RenderProcessHost::iterator i(
990 content::RenderProcessHost::AllHostsIterator()); 994 content::RenderProcessHost::AllHostsIterator());
991 !i.IsAtEnd(); i.Advance()) { 995 !i.IsAtEnd(); i.Advance()) {
992 content::RenderProcessHost* host = i.GetCurrentValue(); 996 content::RenderProcessHost* host = i.GetCurrentValue();
993 Profile* host_profile = 997 Profile* host_profile =
994 Profile::FromBrowserContext(host->GetBrowserContext()); 998 Profile::FromBrowserContext(host->GetBrowserContext());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 for (content::RenderProcessHost::iterator i( 1125 for (content::RenderProcessHost::iterator i(
1122 content::RenderProcessHost::AllHostsIterator()); 1126 content::RenderProcessHost::AllHostsIterator());
1123 !i.IsAtEnd(); i.Advance()) { 1127 !i.IsAtEnd(); i.Advance()) {
1124 content::RenderProcessHost* host = i.GetCurrentValue(); 1128 content::RenderProcessHost* host = i.GetCurrentValue();
1125 Profile* host_profile = 1129 Profile* host_profile =
1126 Profile::FromBrowserContext(host->GetBrowserContext()); 1130 Profile::FromBrowserContext(host->GetBrowserContext());
1127 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) 1131 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
1128 host->Send(new ExtensionMsg_Unloaded(extension->id())); 1132 host->Send(new ExtensionMsg_Unloaded(extension->id()));
1129 } 1133 }
1130 1134
1131 profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); 1135 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
1132 profile_->GetExtensionSpecialStoragePolicy()-> 1136 profile_->GetExtensionSpecialStoragePolicy()->
1133 RevokeRightsForExtension(extension); 1137 RevokeRightsForExtension(extension);
1134 1138
1135 ExtensionWebUI::UnregisterChromeURLOverrides( 1139 ExtensionWebUI::UnregisterChromeURLOverrides(
1136 profile_, extension->GetChromeURLOverrides()); 1140 profile_, extension->GetChromeURLOverrides());
1137 1141
1138 #if defined(OS_CHROMEOS) 1142 #if defined(OS_CHROMEOS)
1139 // Revoke external file access to 1143 // Revoke external file access to
1140 if (BrowserContext::GetFileSystemContext(profile_) && 1144 if (BrowserContext::GetFileSystemContext(profile_) &&
1141 BrowserContext::GetFileSystemContext(profile_)->external_provider()) { 1145 BrowserContext::GetFileSystemContext(profile_)->external_provider()) {
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 extension_misc::UnloadedExtensionReason reason) { 1926 extension_misc::UnloadedExtensionReason reason) {
1923 // Make sure the extension gets deleted after we return from this function. 1927 // Make sure the extension gets deleted after we return from this function.
1924 scoped_refptr<const Extension> extension( 1928 scoped_refptr<const Extension> extension(
1925 GetExtensionByIdInternal(extension_id, true, true, false)); 1929 GetExtensionByIdInternal(extension_id, true, true, false));
1926 1930
1927 // This method can be called via PostTask, so the extension may have been 1931 // This method can be called via PostTask, so the extension may have been
1928 // unloaded by the time this runs. 1932 // unloaded by the time this runs.
1929 if (!extension) { 1933 if (!extension) {
1930 // In case the extension may have crashed/uninstalled. Allow the profile to 1934 // In case the extension may have crashed/uninstalled. Allow the profile to
1931 // clean up its RequestContexts. 1935 // clean up its RequestContexts.
1932 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1936 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
1933 return; 1937 return;
1934 } 1938 }
1935 1939
1936 // Keep information about the extension so that we can reload it later 1940 // Keep information about the extension so that we can reload it later
1937 // even if it's not permanently installed. 1941 // even if it's not permanently installed.
1938 unloaded_extension_paths_[extension->id()] = extension->path(); 1942 unloaded_extension_paths_[extension->id()] = extension->path();
1939 1943
1940 // Clean up if the extension is meant to be enabled after a reload. 1944 // Clean up if the extension is meant to be enabled after a reload.
1941 disabled_extension_paths_.erase(extension->id()); 1945 disabled_extension_paths_.erase(extension->id());
1942 1946
1943 // Clean up runtime data. 1947 // Clean up runtime data.
1944 extension_runtime_data_.erase(extension_id); 1948 extension_runtime_data_.erase(extension_id);
1945 1949
1946 if (disabled_extensions_.Contains(extension->id())) { 1950 if (disabled_extensions_.Contains(extension->id())) {
1947 UnloadedExtensionInfo details(extension, reason); 1951 UnloadedExtensionInfo details(extension, reason);
1948 details.already_disabled = true; 1952 details.already_disabled = true;
1949 disabled_extensions_.Remove(extension->id()); 1953 disabled_extensions_.Remove(extension->id());
1950 content::NotificationService::current()->Notify( 1954 content::NotificationService::current()->Notify(
1951 chrome::NOTIFICATION_EXTENSION_UNLOADED, 1955 chrome::NOTIFICATION_EXTENSION_UNLOADED,
1952 content::Source<Profile>(profile_), 1956 content::Source<Profile>(profile_),
1953 content::Details<UnloadedExtensionInfo>(&details)); 1957 content::Details<UnloadedExtensionInfo>(&details));
1954 // Make sure the profile cleans up its RequestContexts when an already 1958 // Make sure the profile cleans up its RequestContexts when an already
1955 // disabled extension is unloaded (since they are also tracking the disabled 1959 // disabled extension is unloaded (since they are also tracking the disabled
1956 // extensions). 1960 // extensions).
1957 profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); 1961 system_->UnregisterExtensionWithRequestContexts(extension_id, reason);
1958 return; 1962 return;
1959 } 1963 }
1960 1964
1961 // Remove the extension from our list. 1965 // Remove the extension from our list.
1962 extensions_.Remove(extension->id()); 1966 extensions_.Remove(extension->id());
1963 1967
1964 NotifyExtensionUnloaded(extension.get(), reason); 1968 NotifyExtensionUnloaded(extension.get(), reason);
1965 } 1969 }
1966 1970
1967 void ExtensionService::UnloadAllExtensions() { 1971 void ExtensionService::UnloadAllExtensions() {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
2494 Profile::FromBrowserContext(process->GetBrowserContext()); 2498 Profile::FromBrowserContext(process->GetBrowserContext());
2495 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) 2499 if (!profile_->IsSameProfile(host_profile->GetOriginalProfile()))
2496 break; 2500 break;
2497 2501
2498 installed_app_hosts_.erase(process->GetID()); 2502 installed_app_hosts_.erase(process->GetID());
2499 2503
2500 process_map_.RemoveAllFromProcess(process->GetID()); 2504 process_map_.RemoveAllFromProcess(process->GetID());
2501 BrowserThread::PostTask( 2505 BrowserThread::PostTask(
2502 BrowserThread::IO, FROM_HERE, 2506 BrowserThread::IO, FROM_HERE,
2503 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, 2507 base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess,
2504 profile_->GetExtensionInfoMap(), 2508 system_->info_map(),
2505 process->GetID())); 2509 process->GetID()));
2506 break; 2510 break;
2507 } 2511 }
2508 case chrome::NOTIFICATION_PREF_CHANGED: { 2512 case chrome::NOTIFICATION_PREF_CHANGED: {
2509 std::string* pref_name = content::Details<std::string>(details).ptr(); 2513 std::string* pref_name = content::Details<std::string>(details).ptr();
2510 if (*pref_name == prefs::kExtensionInstallAllowList || 2514 if (*pref_name == prefs::kExtensionInstallAllowList ||
2511 *pref_name == prefs::kExtensionInstallDenyList) { 2515 *pref_name == prefs::kExtensionInstallDenyList) {
2512 CheckAdminBlacklist(); 2516 CheckAdminBlacklist();
2513 } else { 2517 } else {
2514 NOTREACHED() << "Unexpected preference name."; 2518 NOTREACHED() << "Unexpected preference name.";
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2668 return api_resource_controller_; 2672 return api_resource_controller_;
2669 } 2673 }
2670 2674
2671 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() { 2675 extensions::RulesRegistryService* ExtensionService::GetRulesRegistryService() {
2672 if (!rules_registry_service_.get()) { 2676 if (!rules_registry_service_.get()) {
2673 rules_registry_service_.reset( 2677 rules_registry_service_.reset(
2674 new extensions::RulesRegistryService(profile_)); 2678 new extensions::RulesRegistryService(profile_));
2675 } 2679 }
2676 return rules_registry_service_.get(); 2680 return rules_registry_service_.get();
2677 } 2681 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/extension_service_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698