| Index: chrome/browser/extensions/user_script_loader.h
|
| diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_loader.h
|
| similarity index 52%
|
| rename from chrome/browser/extensions/user_script_master.h
|
| rename to chrome/browser/extensions/user_script_loader.h
|
| index 3ddf292a8e773dc9a4bbca8fb2d4c1e03cc42b77..c9e17eefdb66519cf2c6fea9eb4e8834c575afd4 100644
|
| --- a/chrome/browser/extensions/user_script_master.h
|
| +++ b/chrome/browser/extensions/user_script_loader.h
|
| @@ -1,22 +1,21 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// 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.
|
|
|
| -#ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
|
| -#define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
|
| +#ifndef CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_
|
| +#define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_
|
|
|
| #include <map>
|
| -#include <string>
|
| +#include <set>
|
|
|
| #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.h"
|
| #include "extensions/common/extension_set.h"
|
| #include "extensions/common/user_script.h"
|
|
|
| @@ -25,6 +24,7 @@ class SharedMemory;
|
| }
|
|
|
| namespace content {
|
| +class BrowserContext;
|
| class RenderProcessHost;
|
| }
|
|
|
| @@ -35,12 +35,17 @@ 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,
|
| +// Manages one "logical unit" of user scripts in shared memory by constructing a
|
| +// new shared memory region when the set of scripts changes. Also notifies
|
| +// renderers of new shared memory region when new renderers appear, or when
|
| +// script reloading completes. Script loading lives on the UI thread. Instances
|
| +// of this class are embedded within classes with names ending in
|
| +// UserScriptMaster. These "master" classes implement the strategy for which
|
| +// scripts to load/unload on this logical unit of scripts.
|
| +class UserScriptLoader : public content::NotificationObserver,
|
| public ExtensionRegistryObserver {
|
| public:
|
| // Parses the includes out of |script| and returns them in |includes|.
|
| @@ -51,20 +56,25 @@ class UserScriptMaster : public content::NotificationObserver,
|
| // the file thread. Exposed only for tests.
|
| static void LoadScriptsForTest(UserScriptList* user_scripts);
|
|
|
| - explicit UserScriptMaster(Profile* profile);
|
| - virtual ~UserScriptMaster();
|
| + UserScriptLoader(Profile* profile,
|
| + const ExtensionId& owner_extension_id,
|
| + bool listen_for_extension_system_loaded);
|
| + virtual ~UserScriptLoader();
|
|
|
| - // 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();
|
| + // Add |scripts| to the set of scripts managed by this loader.
|
| + void AddScripts(const std::set<UserScript>& scripts);
|
|
|
| - // Gets the segment of shared memory for the scripts.
|
| - base::SharedMemory* GetSharedMemory() const {
|
| - return shared_memory_.get();
|
| - }
|
| + // Remove |scripts| from the set of scripts managed by this loader.
|
| + void RemoveScripts(const std::set<UserScript>& scripts);
|
| +
|
| + // Clears the set of scripts managed by this loader.
|
| + void ClearScripts();
|
| +
|
| + // Initiates procedure to start loading scripts on the file thread.
|
| + void StartLoad();
|
|
|
| // Return true if we have any scripts ready.
|
| - bool ScriptsReady() const { return shared_memory_.get() != NULL; }
|
| + bool scripts_ready() const { return shared_memory_.get() != NULL; }
|
|
|
| private:
|
| // content::NotificationObserver implementation.
|
| @@ -73,15 +83,22 @@ class UserScriptMaster : public content::NotificationObserver,
|
| 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 when ExtensionSystem is ready.
|
| - void OnExtensionsReady();
|
| + // Initiates script load when we have been waiting for the extension system
|
| + // to be ready.
|
| + void OnExtensionSystemReady();
|
| +
|
| + // Returns whether or not it is possible that calls to AddScripts(),
|
| + // RemoveScripts(), and/or ClearScripts() have caused any real change in the
|
| + // set of scripts to be loaded.
|
| + bool ScriptsMayHaveChanged() const;
|
| +
|
| + // Attempt to initiate a load.
|
| + void AttemptLoad();
|
|
|
| // Called once we have finished loading the scripts on the file thread.
|
| void OnScriptsLoaded(scoped_ptr<UserScriptList> user_scripts,
|
| @@ -93,7 +110,14 @@ class UserScriptMaster : public content::NotificationObserver,
|
| // updated.
|
| void SendUpdate(content::RenderProcessHost* process,
|
| base::SharedMemory* shared_memory,
|
| - const std::set<std::string>& changed_extensions);
|
| + const std::set<ExtensionId>& changed_extensions);
|
| +
|
| + // Add to |changed_extensions_| those extensions referred to by |scripts|.
|
| + void ExpandChangedExtensions(const std::set<UserScript>& scripts);
|
| +
|
| + // Update |extensions_info_| to contain info for each element of
|
| + // |changed_extensions_|.
|
| + void UpdateExtensionsInfo();
|
|
|
| bool is_loading() const {
|
| // Ownership of |user_scripts_| is passed to the file thread when loading.
|
| @@ -112,18 +136,22 @@ class UserScriptMaster : public content::NotificationObserver,
|
| // Maps extension info needed for localization to an extension ID.
|
| ExtensionsInfo extensions_info_;
|
|
|
| - // The IDs of the extensions which have changed since the last update sent to
|
| - // the renderer.
|
| - std::set<std::string> changed_extensions_;
|
| + // The mutually-exclusive sets of scripts that were added or removed since the
|
| + // last script load.
|
| + std::set<UserScript> added_scripts_;
|
| + std::set<UserScript> removed_scripts_;
|
| +
|
| + // Indicates whether the the collection of scripts should be cleared before
|
| + // additions and removals on the next script load.
|
| + bool clear_scripts_;
|
|
|
| - // 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_;
|
| + // The IDs of the extensions which changed in the last update sent to the
|
| + // renderer.
|
| + ExtensionIdSet changed_extensions_;
|
|
|
| // If the extensions service has finished loading its initial set of
|
| // extensions.
|
| - bool extensions_service_ready_;
|
| + bool extension_system_ready_;
|
|
|
| // 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
|
| @@ -136,15 +164,18 @@ class UserScriptMaster : public content::NotificationObserver,
|
| // The profile for which the scripts managed here are installed.
|
| Profile* profile_;
|
|
|
| - // Listen to extension load, unloaded notifications.
|
| + // ID of the extension that owns these scripts, if any. This is only set to a
|
| + // non-empty value for declarative user script shared memory regions.
|
| + ExtensionId owner_extension_id_;
|
| +
|
| + base::WeakPtrFactory<UserScriptLoader> weak_factory_;
|
| +
|
| ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
|
| extension_registry_observer_;
|
|
|
| - base::WeakPtrFactory<UserScriptMaster> weak_factory_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(UserScriptMaster);
|
| + DISALLOW_COPY_AND_ASSIGN(UserScriptLoader);
|
| };
|
|
|
| } // namespace extensions
|
|
|
| -#endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_H_
|
| +#endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_LOADER_H_
|
|
|