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

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

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