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

Unified Diff: chrome/browser/extensions/user_script_master.h

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: Refactor relationship between UserScriptMaster and its subclasses Created 6 years, 5 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/user_script_master.h
diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_master.h
index 3252a8417fc1a998064890b729fedc9db2b538b2..09a349310f81ce926d5024ff872ad64f9d2f9a0b 100644
--- a/chrome/browser/extensions/user_script_master.h
+++ b/chrome/browser/extensions/user_script_master.h
@@ -6,16 +6,13 @@
#define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
#include <map>
-#include <string>
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "base/scoped_observer.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
-#include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension_messages.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/user_script.h"
@@ -35,13 +32,12 @@ namespace extensions {
class ContentVerifier;
class ExtensionRegistry;
-typedef std::map<std::string, ExtensionSet::ExtensionPathAndDefaultLocale>
+typedef std::map<ExtensionId, ExtensionSet::ExtensionPathAndDefaultLocale>
ExtensionsInfo;
// Manages a segment of shared memory that contains the user scripts the user
// has installed. Lives on the UI thread.
-class UserScriptMaster : public content::NotificationObserver,
- public ExtensionRegistryObserver {
+class UserScriptMaster : public content::NotificationObserver {
public:
// Parses the includes out of |script| and returns them in |includes|.
static bool ParseMetadataHeader(const base::StringPiece& script_text,
@@ -51,12 +47,13 @@ class UserScriptMaster : public content::NotificationObserver,
// the file thread. Exposed only for tests.
static void LoadScriptsForTest(UserScriptList* user_scripts);
- explicit UserScriptMaster(Profile* profile);
+ explicit UserScriptMaster(Profile* profile, ExtensionId owner_extension_id);
virtual ~UserScriptMaster();
- // Kicks off a process on the file thread to reload scripts from disk
- // into a new chunk of shared memory and notify renderers.
- virtual void StartLoad();
+ // content::NotificationObserver implementation.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
// Gets the segment of shared memory for the scripts.
base::SharedMemory* GetSharedMemory() const {
@@ -66,79 +63,79 @@ class UserScriptMaster : public content::NotificationObserver,
// Return true if we have any scripts ready.
bool ScriptsReady() const { return shared_memory_.get() != NULL; }
- private:
- // content::NotificationObserver implementation.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
- // ExtensionRegistryObserver implementation.
- virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
- const Extension* extension) OVERRIDE;
- virtual void OnExtensionUnloaded(
- content::BrowserContext* browser_context,
- const Extension* extension,
- UnloadedExtensionInfo::Reason reason) OVERRIDE;
-
// Called once we have finished loading the scripts on the file thread.
void OnScriptsLoaded(scoped_ptr<UserScriptList> user_scripts,
scoped_ptr<base::SharedMemory> shared_memory);
+ // Wrapper around LoadScripts() that that does bookkeeping and invokes
+ // LoadScripts() with the correct parameters.
+ virtual void StartLoad() = 0;
+
+ protected:
+ // Takes ownership of user script list.
+ virtual void AcquireUserScripts(scoped_ptr<UserScriptList> scripts) = 0;
+
+ // Get extension info related to extensions managed by this master.
+ virtual ExtensionsInfo GetExtensionsInfo() = 0;
+
+ // Gets a set of extensions that need to be reloaded on the file thread.
+ virtual std::set<ExtensionId> GetAddedExtensions() = 0;
+
+ // Gets a set of all extensions managed by this master. The empty set
+ // indicates "all extensions in the system".
+ virtual std::set<ExtensionId> GetAllManagedExtensions() = 0;
+
+ // Gets a set of extensions that have changed since the last
+ // ResetChangedExtensions().
+ virtual std::set<ExtensionId> GetChangedExtensions() = 0;
+
+ // Resets any bookkeeping for tracking the set of changed extensions.
+ virtual void ResetChangedExtensions() = 0;
+
+ // Kicks off a process on the file thread to reload scripts from disk
+ // into a new chunk of shared memory and notify renderers.
+ void LoadScripts(scoped_ptr<UserScriptList> scripts,
+ const ExtensionsInfo& extensions_info);
+
// Sends the renderer process a new set of user scripts. If
// |changed_extensions| is not empty, this signals that only the scripts from
// those extensions should be updated. Otherwise, all extensions will be
// updated.
void SendUpdate(content::RenderProcessHost* process,
base::SharedMemory* shared_memory,
- const std::set<std::string>& changed_extensions);
-
- bool is_loading() const {
- // Ownership of |user_scripts_| is passed to the file thread when loading.
- return user_scripts_.get() == NULL;
- }
-
- // Manages our notification registrations.
- content::NotificationRegistrar registrar_;
-
- // Contains the scripts that were found the last time scripts were updated.
- scoped_ptr<base::SharedMemory> shared_memory_;
-
- // List of scripts from currently-installed extensions we should load.
- scoped_ptr<UserScriptList> user_scripts_;
-
- // Maps extension info needed for localization to an extension ID.
- ExtensionsInfo extensions_info_;
+ const std::set<ExtensionId>& changed_extensions);
- // The IDs of the extensions which have changed since the last update sent to
- // the renderer.
- std::set<std::string> changed_extensions_;
+ void SignalPendingLoad() { pending_load_ = true; }
- // The mutually-exclusive sets of extensions that were added or removed since
- // the last script load.
- std::set<std::string> added_extensions_;
- std::set<std::string> removed_extensions_;
+ Profile* profile() { return profile_; }
- // If the extensions service has finished loading its initial set of
- // extensions.
- bool extensions_service_ready_;
+ const ExtensionId& owner_extension_id() const { return owner_extension_id_; }
+ private:
// If list of user scripts is modified while we're loading it, we note
// that we're currently mid-load and then start over again once the load
// finishes. This boolean tracks whether another load is pending.
bool pending_load_;
- // Whether or not we are currently loading.
- bool is_loading_;
-
// The profile for which the scripts managed here are installed.
Profile* profile_;
- // Listen to extension load, unloaded notifications.
- ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
- extension_registry_observer_;
-
base::WeakPtrFactory<UserScriptMaster> weak_factory_;
+ // ID of extension that owns this region, if any. This is the empty string in
+ // the case of the memory region for statically declared content scripts,
+ // which is shared between extensions.
+ ExtensionId owner_extension_id_;
+
+ // Contains the scripts that were found the last time scripts were updated.
+ scoped_ptr<base::SharedMemory> shared_memory_;
+
+ // Whether or not we are currently loading.
+ bool is_loading_;
+
+ // Manages our notification registrations.
+ content::NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(UserScriptMaster);
};

Powered by Google App Engine
This is Rietveld 408576698