Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/shared_user_script_master.h" | |
| 6 | |
| 7 #include <set> | |
|
Devlin
2014/08/04 18:33:24
This is already included in the .h
Mark Dittmer
2014/08/05 20:33:18
Got it. I thought that "it's okay to depend on [sa
| |
| 8 | |
| 9 #include "chrome/browser/extensions/extension_util.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h" | |
| 12 | |
| 13 namespace extensions { | |
| 14 | |
| 15 SharedUserScriptMaster::SharedUserScriptMaster(Profile* profile) | |
| 16 : loader_(profile, | |
| 17 "" /* owner_extension_id */, | |
| 18 true /* listen_for_extension_system_loaded */), | |
| 19 profile_(profile), | |
| 20 extension_registry_observer_(this) { | |
| 21 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | |
| 22 } | |
| 23 | |
| 24 SharedUserScriptMaster::~SharedUserScriptMaster() { | |
| 25 } | |
| 26 | |
| 27 void SharedUserScriptMaster::OnExtensionLoaded( | |
| 28 content::BrowserContext* browser_context, | |
| 29 const Extension* extension) { | |
| 30 loader_.AddScripts(GetScriptsMetadata(extension)); | |
| 31 } | |
| 32 | |
| 33 void SharedUserScriptMaster::OnExtensionUnloaded( | |
| 34 content::BrowserContext* browser_context, | |
| 35 const Extension* extension, | |
| 36 UnloadedExtensionInfo::Reason reason) { | |
| 37 loader_.RemoveScripts(GetScriptsMetadata(extension)); | |
| 38 } | |
| 39 | |
| 40 const std::set<UserScript>& SharedUserScriptMaster::GetScriptsMetadata( | |
| 41 const Extension* extension) { | |
| 42 const ExtensionId& id = extension->id(); | |
| 43 if (scripts_metadata_.find(id) != scripts_metadata_.end()) | |
|
Devlin
2014/08/04 18:33:24
this is a double-lookup. Prefer:
map::const_itera
Mark Dittmer
2014/08/05 20:33:18
Done.
| |
| 44 return scripts_metadata_[id]; | |
| 45 | |
| 46 scripts_metadata_[id] = std::set<UserScript>(); | |
| 47 bool incognito_enabled = util::IsIncognitoEnabled(id, profile_); | |
| 48 const UserScriptList& fetched_scripts = | |
| 49 ContentScriptsInfo::GetContentScripts(extension); | |
| 50 std::set<UserScript>& stored_scripts = scripts_metadata_[id]; | |
|
Devlin
2014/08/04 18:33:24
again, another double lookup here. Let's initiali
Mark Dittmer
2014/08/05 20:33:18
I'm not sure how this is a double-lookup. In order
Devlin
2014/08/05 21:47:26
sorry, phrased that incorrectly. It's only a doub
Mark Dittmer
2014/08/06 15:32:24
Acknowledged.
| |
| 51 for (UserScriptList::const_iterator it = fetched_scripts.begin(); | |
| 52 it != fetched_scripts.end(); | |
| 53 ++it) { | |
| 54 UserScript script = *it; | |
| 55 script.set_incognito_enabled(incognito_enabled); | |
| 56 stored_scripts.insert(script); | |
| 57 } | |
| 58 | |
| 59 return stored_scripts; | |
| 60 } | |
| 61 | |
| 62 } // namespace extensions | |
| OLD | NEW |