Chromium Code Reviews| 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..3a2bc22bacf8dcbc607923744e913445a299750b 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,69 @@ 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 (std::set<HostID>::const_iterator iter = changed_hosts.begin(); |
|
Devlin
2015/03/09 16:00:05
range-based for-loop?
Xi Han
2015/03/09 19:12:36
Done.
|
| + iter != changed_hosts.end(); ++iter) { |
| + if (iter->type() == HostID::EXTENSIONS && |
| + !crx_file::id_util::IdIsValid(iter->id())) { |
| + NOTREACHED() << "Invalid extension id: " << iter->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 an host that "owns" this shared |
|
Devlin
2015/03/09 16:00:05
a host, not an host.
Xi Han
2015/03/09 19:12:36
Done.
|
| + // 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(); |
| + 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()) |
| + all_hosts = extensions_->GetHostIDs(); |
| else |
| - all_extensions.insert(extension_id); |
| - effective_extensions = &all_extensions; |
| + 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())); |
| } |
| } |