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

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

Issue 906493004: Refactoring: de-couple Extensions from "script injection System" [render side]:2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@decouple_brower_isolated_world_1
Patch Set: Rebase and remove ConsumerInstanceInfo(id). Created 5 years, 10 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 | « no previous file | extensions/common/user_script.h » ('j') | extensions/common/user_script.h » ('J')
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 "chrome/browser/extensions/user_script_loader.h" 5 #include "chrome/browser/extensions/user_script_loader.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 // though it removes the possibility that freeing the shared memory block 434 // though it removes the possibility that freeing the shared memory block
435 // would open up enough FDs for long enough for a retry to succeed. 435 // would open up enough FDs for long enough for a retry to succeed.
436 436
437 // Pretend the extension change didn't happen. 437 // Pretend the extension change didn't happen.
438 return; 438 return;
439 } 439 }
440 440
441 // We've got scripts ready to go. 441 // We've got scripts ready to go.
442 shared_memory_.reset(shared_memory.release()); 442 shared_memory_.reset(shared_memory.release());
443 443
444 // If user scripts are comming from a <webview>, will only notify the
445 // RenderProcessHost of that <webview>; otherwise will notify all of the
446 // RenderProcessHosts.
447 bool is_web_view = false;
448 int render_process_id = -1;
449 const UserScriptList* scripts = user_scripts.get();
Devlin 2015/02/23 20:15:00 Why cache this, isntead of just using user_scripts
Xi Han 2015/02/24 16:19:54 Each of them is fine to me. Update.
450 if (scripts && !scripts->empty() &&
451 (*scripts)[0].consumer_instance_type() ==
452 UserScript::ConsumerInstanceType::WEBVIEW) {
453 DCHECK(scripts->size() == 1);
Devlin 2015/02/23 20:15:00 nit: DCHECK_EQ(1u, scripts->size());
Xi Han 2015/02/24 16:19:54 Done.
454 is_web_view = true;
455 render_process_id = (*scripts)[0].routing_info().render_process_id;
456 }
457
444 for (content::RenderProcessHost::iterator i( 458 for (content::RenderProcessHost::iterator i(
Devlin 2015/02/23 20:15:00 I think this is clearer as: if (is_web_view) { R
Fady Samuel 2015/02/23 20:16:57 Does this mean that there is one UserScriptLoader
Xi Han 2015/02/24 16:19:54 Great idea, the logic is much clear now.
Xi Han 2015/02/24 16:19:54 We still have UserScriptLoader per hostID, user sc
445 content::RenderProcessHost::AllHostsIterator()); 459 content::RenderProcessHost::AllHostsIterator());
446 !i.IsAtEnd(); 460 !i.IsAtEnd();
447 i.Advance()) { 461 i.Advance()) {
462 if (is_web_view && i.GetCurrentValue()->GetID() != render_process_id) {
463 continue;
464 }
448 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_); 465 SendUpdate(i.GetCurrentValue(), shared_memory_.get(), changed_hosts_);
466 if (is_web_view)
467 break;
449 } 468 }
450 changed_hosts_.clear(); 469 changed_hosts_.clear();
451 470
452 content::NotificationService::current()->Notify( 471 content::NotificationService::current()->Notify(
453 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, 472 extensions::NOTIFICATION_USER_SCRIPTS_UPDATED,
454 content::Source<Profile>(profile_), 473 content::Source<Profile>(profile_),
455 content::Details<base::SharedMemory>(shared_memory_.get())); 474 content::Details<base::SharedMemory>(shared_memory_.get()));
456 } 475 }
457 476
458 void UserScriptLoader::SendUpdate(content::RenderProcessHost* process, 477 void UserScriptLoader::SendUpdate(content::RenderProcessHost* process,
(...skipping 24 matching lines...) Expand all
483 for (const HostID& id : changed_hosts) 502 for (const HostID& id : changed_hosts)
484 changed_ids_set.insert(id.id()); 503 changed_ids_set.insert(id.id());
485 504
486 if (base::SharedMemory::IsHandleValid(handle_for_process)) { 505 if (base::SharedMemory::IsHandleValid(handle_for_process)) {
487 process->Send(new ExtensionMsg_UpdateUserScripts( 506 process->Send(new ExtensionMsg_UpdateUserScripts(
488 handle_for_process, host_id().id(), changed_ids_set)); 507 handle_for_process, host_id().id(), changed_ids_set));
489 } 508 }
490 } 509 }
491 510
492 } // namespace extensions 511 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/common/user_script.h » ('j') | extensions/common/user_script.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698