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

Unified Diff: extensions/renderer/user_script_set_manager.cc

Issue 988633003: Refactoring: de-couple Extensions from "script injection System" [render side]:4 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Devlin's comments. Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/user_script_set_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/user_script_set_manager.cc
diff --git a/extensions/renderer/user_script_set_manager.cc b/extensions/renderer/user_script_set_manager.cc
index 2a6425fb34e7b019ba131e61245d95a71c3adebc..f20a84d3cf55c9d23d846ebcca0ef56448915fac 100644
--- a/extensions/renderer/user_script_set_manager.cc
+++ b/extensions/renderer/user_script_set_manager.cc
@@ -40,7 +40,7 @@ UserScriptSetManager::GetInjectionForDeclarativeScript(
const GURL& url,
const std::string& extension_id) {
UserScriptSet* user_script_set =
- GetProgrammaticScriptsByExtension(extension_id);
+ GetProgrammaticScriptsByHostID(HostID(HostID::EXTENSIONS, extension_id));
if (!user_script_set)
return scoped_ptr<ScriptInjection>();
@@ -86,71 +86,72 @@ void UserScriptSetManager::GetAllActiveExtensionIds(
}
}
-UserScriptSet* UserScriptSetManager::GetProgrammaticScriptsByExtension(
- const ExtensionId& extension_id) {
- UserScriptSetMap::const_iterator it =
- programmatic_scripts_.find(extension_id);
+UserScriptSet* UserScriptSetManager::GetProgrammaticScriptsByHostID(
+ const HostID& host_id) {
+ UserScriptSetMap::const_iterator it = programmatic_scripts_.find(host_id);
return it != programmatic_scripts_.end() ? it->second.get() : NULL;
}
void UserScriptSetManager::OnUpdateUserScripts(
base::SharedMemoryHandle shared_memory,
- const ExtensionId& extension_id,
- const std::set<std::string>& changed_extensions) {
+ const HostID& host_id,
+ const std::set<HostID>& changed_hosts) {
if (!base::SharedMemory::IsHandleValid(shared_memory)) {
NOTREACHED() << "Bad scripts handle";
return;
}
- for (std::set<std::string>::const_iterator iter = changed_extensions.begin();
- iter != changed_extensions.end();
- ++iter) {
- if (!crx_file::id_util::IdIsValid(*iter)) {
- NOTREACHED() << "Invalid extension id: " << *iter;
+ for (const HostID& host_id : changed_hosts) {
+ if (host_id.type() == HostID::EXTENSIONS &&
+ !crx_file::id_util::IdIsValid(host_id.id())) {
+ NOTREACHED() << "Invalid extension id: " << host_id.id();
return;
}
}
UserScriptSet* scripts = NULL;
- if (!extension_id.empty()) {
- // The expectation when there is an extension that "owns" this shared
- // memory region is that the |changed_extensions| is either the empty list
+ if (!host_id.id().empty()) {
+ // The expectation when there is a host that "owns" this shared
+ // memory region is that the |changed_hosts| is either the empty list
// or just the owner.
- CHECK(changed_extensions.size() <= 1);
- if (programmatic_scripts_.find(extension_id) ==
- programmatic_scripts_.end()) {
+ CHECK(changed_hosts.size() <= 1);
+ if (programmatic_scripts_.find(host_id) == programmatic_scripts_.end()) {
scripts = new UserScriptSet(extensions_);
- programmatic_scripts_[extension_id] = make_linked_ptr(scripts);
+ programmatic_scripts_[host_id] = make_linked_ptr(scripts);
} else {
- scripts = programmatic_scripts_[extension_id].get();
+ scripts = programmatic_scripts_[host_id].get();
}
} else {
scripts = &static_scripts_;
}
DCHECK(scripts);
- // If no extensions are included in the set, that indicates that all
- // extensions were updated. Add them all to the set so that observers and
+ // If no hosts are included in the set, that indicates that all
+ // hosts were updated. Add them all to the set so that observers and
// individual UserScriptSets don't need to know this detail.
- const std::set<std::string>* effective_extensions = &changed_extensions;
- std::set<std::string> all_extensions;
- if (changed_extensions.empty()) {
- // The meaning of "all extensions" varies, depending on whether some
- // extension "owns" this shared memory region.
- // No owner => all known extensions.
- // Owner => just the owner extension.
- if (extension_id.empty())
- all_extensions = extensions_->GetIDs();
- else
- all_extensions.insert(extension_id);
- effective_extensions = &all_extensions;
+ const std::set<HostID>* effective_hosts = &changed_hosts;
+ std::set<HostID> all_hosts;
+ if (changed_hosts.empty()) {
+ // The meaning of "all hosts(extensions)" varies, depending on whether some
+ // host "owns" this shared memory region.
+ // No owner => all known hosts.
+ // Owner => just the owner host.
+ if (host_id.id().empty()) {
+ std::set<std::string> extension_ids = extensions_->GetIDs();
+ for (std::string extension_id : extension_ids)
+ all_hosts.insert(HostID(HostID::EXTENSIONS, extension_id));
+ }
Devlin 2015/03/10 21:44:57 nit: else goes on the same line as the bracket (th
Xi Han 2015/03/10 23:52:09 Thanks for catching it again.
+ else {
+ all_hosts.insert(host_id);
+ }
+ effective_hosts = &all_hosts;
}
- if (scripts->UpdateUserScripts(shared_memory, *effective_extensions)) {
+ if (scripts->UpdateUserScripts(shared_memory, *effective_hosts)) {
FOR_EACH_OBSERVER(
Observer,
observers_,
- OnUserScriptsUpdated(*effective_extensions, scripts->scripts()));
+ OnUserScriptsUpdated(*effective_hosts, scripts->scripts()));
}
}
« no previous file with comments | « extensions/renderer/user_script_set_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698