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

Unified Diff: chrome/browser/extensions/shared_user_script_master.cc

Issue 420543002: Declarative content scripts: Browser-side: per-extension shared memory regions (lazily loaded) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another round of review comments addressed Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/shared_user_script_master.cc
diff --git a/chrome/browser/extensions/shared_user_script_master.cc b/chrome/browser/extensions/shared_user_script_master.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c5600fe3b29f2dc69774fddd65035fb9b90d8b5b
--- /dev/null
+++ b/chrome/browser/extensions/shared_user_script_master.cc
@@ -0,0 +1,65 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/shared_user_script_master.h"
+
+#include "chrome/browser/extensions/extension_util.h"
+#include "chrome/browser/profiles/profile.h"
Devlin 2014/08/06 15:59:25 Don't need this.
Mark Dittmer 2014/08/06 22:08:18 Do too :-P For profile_.
Devlin 2014/08/07 15:46:31 We never really use profile_, so just knowing that
Mark Dittmer 2014/08/11 14:08:04 Acknowledged.
+#include "chrome/common/extensions/manifest_handlers/content_scripts_handler.h"
+#include "extensions/browser/extension_registry.h"
+
+namespace extensions {
+
+SharedUserScriptMaster::SharedUserScriptMaster(Profile* profile)
+ : loader_(profile,
+ std::string() /* owner_extension_id */,
+ true /* listen_for_extension_system_loaded */),
+ profile_(profile),
+ extension_registry_observer_(this) {
+ extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
+}
+
+SharedUserScriptMaster::~SharedUserScriptMaster() {
+}
+
+void SharedUserScriptMaster::OnExtensionLoaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension) {
+ loader_.AddScripts(GetScriptsMetadata(extension));
+}
+
+void SharedUserScriptMaster::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ loader_.RemoveScripts(GetScriptsMetadata(extension));
+ loader_.ClearExtensionInfo(extension->id());
+ scripts_metadata_.erase(extension->id());
+}
+
+const std::set<UserScript>& SharedUserScriptMaster::GetScriptsMetadata(
+ const Extension* extension) {
+ const ExtensionId& id = extension->id();
+ std::map<ExtensionId, std::set<UserScript> >::const_iterator iter =
+ scripts_metadata_.find(id);
+ if (iter != scripts_metadata_.end())
+ return iter->second;
+
+ scripts_metadata_[id] = std::set<UserScript>();
Devlin 2014/08/06 15:59:25 I'm somewhat dubious of the benefit of storing all
Mark Dittmer 2014/08/06 22:08:18 Got rid of scripts_metadata_, but I am leaving the
Devlin 2014/08/07 15:46:31 Works for me.
Mark Dittmer 2014/08/11 14:08:04 Acknowledged.
+ bool incognito_enabled = util::IsIncognitoEnabled(id, profile_);
+ const UserScriptList& fetched_scripts =
+ ContentScriptsInfo::GetContentScripts(extension);
+ std::set<UserScript>& stored_scripts = scripts_metadata_[id];
+ for (UserScriptList::const_iterator it = fetched_scripts.begin();
+ it != fetched_scripts.end();
+ ++it) {
+ UserScript script = *it;
+ script.set_incognito_enabled(incognito_enabled);
+ stored_scripts.insert(script);
+ }
+
+ return stored_scripts;
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698