OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/user_script_set_manager.h" | 5 #include "extensions/renderer/user_script_set_manager.h" |
6 | 6 |
7 #include "components/crx_file/id_util.h" | 7 #include "components/crx_file/id_util.h" |
8 #include "content/public/renderer/render_thread.h" | 8 #include "content/public/renderer/render_thread.h" |
9 #include "extensions/common/extension_messages.h" | 9 #include "extensions/common/extension_messages.h" |
10 #include "extensions/renderer/dispatcher.h" | 10 #include "extensions/renderer/dispatcher.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 it != programmatic_scripts_.end(); | 84 it != programmatic_scripts_.end(); |
85 ++it) { | 85 ++it) { |
86 it->second->GetActiveExtensionIds(ids); | 86 it->second->GetActiveExtensionIds(ids); |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 UserScriptSet* UserScriptSetManager::GetProgrammaticScriptsByExtension( | 90 UserScriptSet* UserScriptSetManager::GetProgrammaticScriptsByExtension( |
91 const ExtensionId& extension_id) { | 91 const ExtensionId& extension_id) { |
92 UserScriptSetMap::const_iterator it = | 92 UserScriptSetMap::const_iterator it = |
93 programmatic_scripts_.find(extension_id); | 93 programmatic_scripts_.find(extension_id); |
94 return it != programmatic_scripts_.end() ? it->second.get() : NULL; | 94 return it != programmatic_scripts_.end() ? it->second.get() : nullptr; |
95 } | 95 } |
96 | 96 |
97 void UserScriptSetManager::OnUpdateUserScripts( | 97 void UserScriptSetManager::OnUpdateUserScripts( |
98 base::SharedMemoryHandle shared_memory, | 98 base::SharedMemoryHandle shared_memory, |
99 const ExtensionId& extension_id, | 99 const ExtensionId& extension_id, |
100 const std::set<std::string>& changed_extensions) { | 100 const std::set<std::string>& changed_extensions) { |
101 if (!base::SharedMemory::IsHandleValid(shared_memory)) { | 101 if (!base::SharedMemory::IsHandleValid(shared_memory)) { |
102 NOTREACHED() << "Bad scripts handle"; | 102 NOTREACHED() << "Bad scripts handle"; |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 for (std::set<std::string>::const_iterator iter = changed_extensions.begin(); | 106 for (std::set<std::string>::const_iterator iter = changed_extensions.begin(); |
107 iter != changed_extensions.end(); | 107 iter != changed_extensions.end(); |
108 ++iter) { | 108 ++iter) { |
109 if (!crx_file::id_util::IdIsValid(*iter)) { | 109 if (!crx_file::id_util::IdIsValid(*iter)) { |
110 NOTREACHED() << "Invalid extension id: " << *iter; | 110 NOTREACHED() << "Invalid extension id: " << *iter; |
111 return; | 111 return; |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 UserScriptSet* scripts = NULL; | 115 UserScriptSet* scripts = nullptr; |
116 if (!extension_id.empty()) { | 116 if (!extension_id.empty()) { |
117 // The expectation when there is an extension that "owns" this shared | 117 // The expectation when there is an extension that "owns" this shared |
118 // memory region is that the |changed_extensions| is either the empty list | 118 // memory region is that the |changed_extensions| is either the empty list |
119 // or just the owner. | 119 // or just the owner. |
120 CHECK(changed_extensions.size() <= 1); | 120 CHECK(changed_extensions.size() <= 1); |
121 if (programmatic_scripts_.find(extension_id) == | 121 if (programmatic_scripts_.find(extension_id) == |
122 programmatic_scripts_.end()) { | 122 programmatic_scripts_.end()) { |
123 scripts = new UserScriptSet(extensions_); | 123 scripts = new UserScriptSet(extensions_); |
124 programmatic_scripts_[extension_id] = make_linked_ptr(scripts); | 124 programmatic_scripts_[extension_id] = make_linked_ptr(scripts); |
125 } else { | 125 } else { |
(...skipping 23 matching lines...) Expand all Loading... |
149 | 149 |
150 if (scripts->UpdateUserScripts(shared_memory, *effective_extensions)) { | 150 if (scripts->UpdateUserScripts(shared_memory, *effective_extensions)) { |
151 FOR_EACH_OBSERVER( | 151 FOR_EACH_OBSERVER( |
152 Observer, | 152 Observer, |
153 observers_, | 153 observers_, |
154 OnUserScriptsUpdated(*effective_extensions, scripts->scripts())); | 154 OnUserScriptsUpdated(*effective_extensions, scripts->scripts())); |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 } // namespace extensions | 158 } // namespace extensions |
OLD | NEW |