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

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

Issue 2162983002: [Extensions] Ensure ordering of extension [un]loaded, activated messages (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Istiaque's Created 4 years, 4 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "content/public/browser/render_process_host.h" 66 #include "content/public/browser/render_process_host.h"
67 #include "content/public/browser/storage_partition.h" 67 #include "content/public/browser/storage_partition.h"
68 #include "extensions/browser/app_sorting.h" 68 #include "extensions/browser/app_sorting.h"
69 #include "extensions/browser/event_router.h" 69 #include "extensions/browser/event_router.h"
70 #include "extensions/browser/extension_host.h" 70 #include "extensions/browser/extension_host.h"
71 #include "extensions/browser/extension_registry.h" 71 #include "extensions/browser/extension_registry.h"
72 #include "extensions/browser/extension_system.h" 72 #include "extensions/browser/extension_system.h"
73 #include "extensions/browser/extensions_browser_client.h" 73 #include "extensions/browser/extensions_browser_client.h"
74 #include "extensions/browser/external_install_info.h" 74 #include "extensions/browser/external_install_info.h"
75 #include "extensions/browser/install_flag.h" 75 #include "extensions/browser/install_flag.h"
76 #include "extensions/browser/renderer_startup_helper.h"
76 #include "extensions/browser/runtime_data.h" 77 #include "extensions/browser/runtime_data.h"
77 #include "extensions/browser/uninstall_reason.h" 78 #include "extensions/browser/uninstall_reason.h"
78 #include "extensions/browser/update_observer.h" 79 #include "extensions/browser/update_observer.h"
79 #include "extensions/browser/updater/extension_cache.h" 80 #include "extensions/browser/updater/extension_cache.h"
80 #include "extensions/browser/updater/extension_downloader.h" 81 #include "extensions/browser/updater/extension_downloader.h"
81 #include "extensions/common/extension_messages.h" 82 #include "extensions/common/extension_messages.h"
82 #include "extensions/common/extension_urls.h" 83 #include "extensions/common/extension_urls.h"
83 #include "extensions/common/feature_switch.h" 84 #include "extensions/common/feature_switch.h"
84 #include "extensions/common/features/feature_channel.h" 85 #include "extensions/common/features/feature_channel.h"
85 #include "extensions/common/file_util.h" 86 #include "extensions/common/file_util.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 profile_(profile), 303 profile_(profile),
303 system_(extensions::ExtensionSystem::Get(profile)), 304 system_(extensions::ExtensionSystem::Get(profile)),
304 extension_prefs_(extension_prefs), 305 extension_prefs_(extension_prefs),
305 blacklist_(blacklist), 306 blacklist_(blacklist),
306 registry_(extensions::ExtensionRegistry::Get(profile)), 307 registry_(extensions::ExtensionRegistry::Get(profile)),
307 pending_extension_manager_(profile), 308 pending_extension_manager_(profile),
308 install_directory_(install_directory), 309 install_directory_(install_directory),
309 extensions_enabled_(extensions_enabled), 310 extensions_enabled_(extensions_enabled),
310 ready_(ready), 311 ready_(ready),
311 shared_module_service_(new extensions::SharedModuleService(profile_)), 312 shared_module_service_(new extensions::SharedModuleService(profile_)),
313 renderer_helper_(
314 extensions::RendererStartupHelperFactory::GetForBrowserContext(
315 profile_)),
312 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)) { 316 app_data_migrator_(new extensions::AppDataMigrator(profile_, registry_)) {
313 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 317 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
314 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor"); 318 TRACE_EVENT0("browser,startup", "ExtensionService::ExtensionService::ctor");
315 319
316 // Figure out if extension installation should be enabled. 320 // Figure out if extension installation should be enabled.
317 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled( 321 if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
318 *command_line, profile)) 322 *command_line, profile))
319 extensions_enabled_ = false; 323 extensions_enabled_ = false;
320 324
321 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, 325 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 // was loaded, otherwise a race can arise where a renderer that is created 1027 // was loaded, otherwise a race can arise where a renderer that is created
1024 // for the extension may try to load an extension URL with an extension id 1028 // for the extension may try to load an extension URL with an extension id
1025 // that the request context doesn't yet know about. The profile is responsible 1029 // that the request context doesn't yet know about. The profile is responsible
1026 // for ensuring its URLRequestContexts appropriately discover the loaded 1030 // for ensuring its URLRequestContexts appropriately discover the loaded
1027 // extension. 1031 // extension.
1028 system_->RegisterExtensionWithRequestContexts( 1032 system_->RegisterExtensionWithRequestContexts(
1029 extension, 1033 extension,
1030 base::Bind(&ExtensionService::OnExtensionRegisteredWithRequestContexts, 1034 base::Bind(&ExtensionService::OnExtensionRegisteredWithRequestContexts,
1031 AsWeakPtr(), make_scoped_refptr(extension))); 1035 AsWeakPtr(), make_scoped_refptr(extension)));
1032 1036
1033 // Tell renderers about the new extension, unless it's a theme (renderers 1037 renderer_helper_->OnExtensionLoaded(*extension);
1034 // don't need to know about themes).
1035 if (!extension->is_theme()) {
1036 for (content::RenderProcessHost::iterator i(
1037 content::RenderProcessHost::AllHostsIterator());
1038 !i.IsAtEnd(); i.Advance()) {
1039 content::RenderProcessHost* host = i.GetCurrentValue();
1040 Profile* host_profile =
1041 Profile::FromBrowserContext(host->GetBrowserContext());
1042 if (host_profile->GetOriginalProfile() ==
1043 profile_->GetOriginalProfile()) {
1044 // We don't need to include tab permisisons here, since the extension
1045 // was just loaded.
1046 std::vector<ExtensionMsg_Loaded_Params> loaded_extensions(
1047 1, ExtensionMsg_Loaded_Params(extension,
1048 false /* no tab permissions */));
1049 host->Send(
1050 new ExtensionMsg_Loaded(loaded_extensions));
1051 }
1052 }
1053 }
1054 1038
1055 // Tell subsystems that use the EXTENSION_LOADED notification about the new 1039 // Tell subsystems that use the EXTENSION_LOADED notification about the new
1056 // extension. 1040 // extension.
1057 // 1041 //
1058 // NOTE: It is important that this happen after notifying the renderers about 1042 // NOTE: It is important that this happen after notifying the renderers about
1059 // the new extensions so that if we navigate to an extension URL in 1043 // the new extensions so that if we navigate to an extension URL in
1060 // ExtensionRegistryObserver::OnLoaded or 1044 // ExtensionRegistryObserver::OnLoaded or
1061 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the 1045 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the
1062 // renderer is guaranteed to know about it. 1046 // renderer is guaranteed to know about it.
1063 registry_->TriggerOnLoaded(extension); 1047 registry_->TriggerOnLoaded(extension);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 UnloadedExtensionInfo::Reason reason) { 1099 UnloadedExtensionInfo::Reason reason) {
1116 UnloadedExtensionInfo details(extension, reason); 1100 UnloadedExtensionInfo details(extension, reason);
1117 1101
1118 registry_->TriggerOnUnloaded(extension, reason); 1102 registry_->TriggerOnUnloaded(extension, reason);
1119 1103
1120 content::NotificationService::current()->Notify( 1104 content::NotificationService::current()->Notify(
1121 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, 1105 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
1122 content::Source<Profile>(profile_), 1106 content::Source<Profile>(profile_),
1123 content::Details<UnloadedExtensionInfo>(&details)); 1107 content::Details<UnloadedExtensionInfo>(&details));
1124 1108
1125 for (content::RenderProcessHost::iterator i( 1109 renderer_helper_->OnExtensionUnloaded(extension->id());
1126 content::RenderProcessHost::AllHostsIterator());
1127 !i.IsAtEnd(); i.Advance()) {
1128 content::RenderProcessHost* host = i.GetCurrentValue();
1129 Profile* host_profile =
1130 Profile::FromBrowserContext(host->GetBrowserContext());
1131 if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile())
1132 host->Send(new ExtensionMsg_Unloaded(extension->id()));
1133 }
1134 1110
1135 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason); 1111 system_->UnregisterExtensionWithRequestContexts(extension->id(), reason);
1136 1112
1137 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a 1113 // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a
1138 // BrowserContextKeyedService and use ExtensionRegistryObserver. 1114 // BrowserContextKeyedService and use ExtensionRegistryObserver.
1139 profile_->GetExtensionSpecialStoragePolicy()-> 1115 profile_->GetExtensionSpecialStoragePolicy()->
1140 RevokeRightsForExtension(extension); 1116 RevokeRightsForExtension(extension);
1141 1117
1142 #if defined(OS_CHROMEOS) 1118 #if defined(OS_CHROMEOS)
1143 // Revoke external file access for the extension from its file system context. 1119 // Revoke external file access for the extension from its file system context.
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 } 2443 }
2468 2444
2469 void ExtensionService::OnProfileDestructionStarted() { 2445 void ExtensionService::OnProfileDestructionStarted() {
2470 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2446 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2471 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2447 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2472 it != ids_to_unload.end(); 2448 it != ids_to_unload.end();
2473 ++it) { 2449 ++it) {
2474 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2450 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2475 } 2451 }
2476 } 2452 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.h ('k') | chrome/browser/extensions/renderer_initialization_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698