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

Unified Diff: chrome/browser/extensions/declarative_user_script_manager.cc

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change ConsumerID to class; remove usages of linked_ptr, and nits. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/declarative_user_script_manager.cc
diff --git a/chrome/browser/extensions/declarative_user_script_manager.cc b/chrome/browser/extensions/declarative_user_script_manager.cc
index e740b5b4f4e25c94889afcea7c8d1f92cecc1eb6..981091303d0f3a96b9c9be11342fbc3231bf5f03 100644
--- a/chrome/browser/extensions/declarative_user_script_manager.cc
+++ b/chrome/browser/extensions/declarative_user_script_manager.cc
@@ -5,11 +5,14 @@
#include "chrome/browser/extensions/declarative_user_script_manager.h"
#include "chrome/browser/extensions/declarative_user_script_master.h"
+#include "chrome/browser/profiles/profile.h"
+#include "extensions/browser/extension_registry.h"
namespace extensions {
DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile)
- : profile_(profile) {
+ : profile_(profile), extension_registry_observer_(this) {
+ extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
}
DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
@@ -17,16 +20,35 @@ DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
DeclarativeUserScriptMaster*
DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
- const std::string& id) {
- UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id);
+ const ConsumerID& consumer_id) {
+ UserScriptMasterMap::iterator it =
+ declarative_user_script_masters_.find(consumer_id);
if (it != declarative_user_script_masters_.end())
return it->second.get();
+ return CreateDeclarativeUserScriptMaster(consumer_id);
+}
+
+DeclarativeUserScriptMaster*
+DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster(
+ const ConsumerID& consumer_id) {
linked_ptr<DeclarativeUserScriptMaster> master(
- new DeclarativeUserScriptMaster(profile_, id));
- declarative_user_script_masters_[id] = master;
+ new DeclarativeUserScriptMaster(profile_, consumer_id));
+ declarative_user_script_masters_[consumer_id] = master;
return master.get();
}
-} // extensions
+void DeclarativeUserScriptManager::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ for (auto it = declarative_user_script_masters_.begin();
Devlin 2015/01/20 17:51:05 nit: shorter: for (const auto& val : declarative_u
Xi Han 2015/01/21 21:30:16 Done.
+ it != declarative_user_script_masters_.end(); ++it) {
+ linked_ptr<DeclarativeUserScriptMaster> master = it->second;
+ if (master->consumer_id().host_id() == extension->id())
+ master->ClearScripts();
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698