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

Side by Side Diff: extensions/browser/user_script_loader.cc

Issue 2424593002: Reduce FOR_EACH_OBSERVER usage in extensions (Closed)
Patch Set: script_observers_ Created 4 years, 2 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
« no previous file with comments | « extensions/browser/script_executor.cc ('k') | extensions/browser/warning_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser/user_script_loader.h" 5 #include "extensions/browser/user_script_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 pending_load_(false), 163 pending_load_(false),
164 browser_context_(browser_context), 164 browser_context_(browser_context),
165 host_id_(host_id), 165 host_id_(host_id),
166 weak_factory_(this) { 166 weak_factory_(this) {
167 registrar_.Add(this, 167 registrar_.Add(this,
168 content::NOTIFICATION_RENDERER_PROCESS_CREATED, 168 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
169 content::NotificationService::AllBrowserContextsAndSources()); 169 content::NotificationService::AllBrowserContextsAndSources());
170 } 170 }
171 171
172 UserScriptLoader::~UserScriptLoader() { 172 UserScriptLoader::~UserScriptLoader() {
173 FOR_EACH_OBSERVER(Observer, observers_, OnUserScriptLoaderDestroyed(this)); 173 for (auto& observer : observers_)
174 observer.OnUserScriptLoaderDestroyed(this);
174 } 175 }
175 176
176 void UserScriptLoader::AddScripts(std::unique_ptr<UserScriptList> scripts) { 177 void UserScriptLoader::AddScripts(std::unique_ptr<UserScriptList> scripts) {
177 #if DCHECK_IS_ON() 178 #if DCHECK_IS_ON()
178 // |scripts| with non-unique IDs will work, but that would indicate we are 179 // |scripts| with non-unique IDs will work, but that would indicate we are
179 // doing something wrong somewhere, so DCHECK that. 180 // doing something wrong somewhere, so DCHECK that.
180 DCHECK(AreScriptsUnique(*scripts)) 181 DCHECK(AreScriptsUnique(*scripts))
181 << "AddScripts() expects scripts with unique IDs."; 182 << "AddScripts() expects scripts with unique IDs.";
182 #endif // DCHECK_IS_ON() 183 #endif // DCHECK_IS_ON()
183 for (std::unique_ptr<UserScript>& user_script : *scripts) { 184 for (std::unique_ptr<UserScript>& user_script : *scripts) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 !i.IsAtEnd(); i.Advance()) { 388 !i.IsAtEnd(); i.Advance()) {
388 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_); 389 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_);
389 } 390 }
390 changed_hosts_.clear(); 391 changed_hosts_.clear();
391 392
392 // TODO(hanxi): Remove the NOTIFICATION_USER_SCRIPTS_UPDATED. 393 // TODO(hanxi): Remove the NOTIFICATION_USER_SCRIPTS_UPDATED.
393 content::NotificationService::current()->Notify( 394 content::NotificationService::current()->Notify(
394 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, 395 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
395 content::Source<BrowserContext>(browser_context_), 396 content::Source<BrowserContext>(browser_context_),
396 content::Details<base::SharedMemory>(shared_memory_.get())); 397 content::Details<base::SharedMemory>(shared_memory_.get()));
397 FOR_EACH_OBSERVER(Observer, observers_, OnScriptsLoaded(this)); 398 for (auto& observer : observers_)
399 observer.OnScriptsLoaded(this);
398 } 400 }
399 401
400 void UserScriptLoader::SendUpdate(content::RenderProcessHost* process, 402 void UserScriptLoader::SendUpdate(content::RenderProcessHost* process,
401 base::SharedMemory* shared_memory, 403 base::SharedMemory* shared_memory,
402 const std::set<HostID>& changed_hosts) { 404 const std::set<HostID>& changed_hosts) {
403 // Don't allow injection of non-whitelisted extensions' content scripts 405 // Don't allow injection of non-whitelisted extensions' content scripts
404 // into <webview>. 406 // into <webview>.
405 bool whitelisted_only = process->IsForGuestsOnly() && host_id().id().empty(); 407 bool whitelisted_only = process->IsForGuestsOnly() && host_id().id().empty();
406 408
407 // Make sure we only send user scripts to processes in our browser_context. 409 // Make sure we only send user scripts to processes in our browser_context.
(...skipping 11 matching lines...) Expand all
419 if (!shared_memory->ShareToProcess(handle, &handle_for_process)) 421 if (!shared_memory->ShareToProcess(handle, &handle_for_process))
420 return; // This can legitimately fail if the renderer asserts at startup. 422 return; // This can legitimately fail if the renderer asserts at startup.
421 423
422 if (base::SharedMemory::IsHandleValid(handle_for_process)) { 424 if (base::SharedMemory::IsHandleValid(handle_for_process)) {
423 process->Send(new ExtensionMsg_UpdateUserScripts( 425 process->Send(new ExtensionMsg_UpdateUserScripts(
424 handle_for_process, host_id(), changed_hosts, whitelisted_only)); 426 handle_for_process, host_id(), changed_hosts, whitelisted_only));
425 } 427 }
426 } 428 }
427 429
428 } // namespace extensions 430 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/script_executor.cc ('k') | extensions/browser/warning_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698