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

Unified Diff: chrome/browser/extensions/user_script_loader.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 UserScriptMaster into UserScriptLoader, managed by SharedUserScriptMaster and DeclarativeU… 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/user_script_loader.h
diff --git a/chrome/browser/extensions/user_script_master.h b/chrome/browser/extensions/user_script_loader.h
similarity index 54%
rename from chrome/browser/extensions/user_script_master.h
rename to chrome/browser/extensions/user_script_loader.h
index 3252a8417fc1a998064890b729fedc9db2b538b2..525b5c4905bb5ef7b0562aa580c3f062cadee080 100644
--- a/chrome/browser/extensions/user_script_master.h
+++ b/chrome/browser/extensions/user_script_loader.h
@@ -1,22 +1,18 @@
-// 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_set.h"
#include "extensions/common/user_script.h"
@@ -35,13 +31,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.
Devlin 2014/08/04 18:33:26 Update this comment to document the purpose of thi
Mark Dittmer 2014/08/05 20:33:19 Done.
-class UserScriptMaster : public content::NotificationObserver,
- public ExtensionRegistryObserver {
+class UserScriptLoader : public content::NotificationObserver {
public:
// Parses the includes out of |script| and returns them in |includes|.
static bool ParseMetadataHeader(const base::StringPiece& script_text,
@@ -49,48 +44,57 @@ class UserScriptMaster : public content::NotificationObserver,
// A wrapper around the method to load user scripts, which is normally run on
// the file thread. Exposed only for tests.
- static void LoadScriptsForTest(UserScriptList* user_scripts);
+ static void LoadScriptsForTest(std::set<UserScript>* user_scripts);
- explicit UserScriptMaster(Profile* profile);
- 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();
+ explicit UserScriptLoader(Profile* profile,
Devlin 2014/08/04 18:33:25 This no longer needs explicit :)
Mark Dittmer 2014/08/05 20:33:19 Done.
+ ExtensionId owner_extension_id,
Devlin 2014/08/04 18:33:26 const ExtensionId&
Mark Dittmer 2014/08/05 20:33:20 Done.
+ bool listen_for_extension_system_loaded);
+ virtual ~UserScriptLoader();
// Gets the segment of shared memory for the scripts.
- base::SharedMemory* GetSharedMemory() const {
- return shared_memory_.get();
- }
+ base::SharedMemory* GetSharedMemory() const { return shared_memory_.get(); }
// Return true if we have any scripts ready.
bool ScriptsReady() const { return shared_memory_.get() != NULL; }
Devlin 2014/08/04 18:33:26 Since all the callers of this are being updated an
Mark Dittmer 2014/08/05 20:33:19 Done.
+ void AddScripts(const std::set<UserScript>& scripts);
Devlin 2014/08/04 18:33:25 comments
Mark Dittmer 2014/08/05 20:33:20 Done.
+ void RemoveScripts(const std::set<UserScript>& scripts);
+ void ClearScripts();
+
+ // Initiates procedure to start loading scripts on the file thread.
+ void StartLoad();
+
private:
+ // Initiates script load when we have been waiting for the extension system
+ // to be ready.
+ void OnExtensionSystemReady();
+
// 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;
+ // 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,
+ void OnScriptsLoaded(scoped_ptr<std::set<UserScript> > user_scripts,
scoped_ptr<base::SharedMemory> shared_memory);
-
// 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);
+ const std::set<ExtensionId>& changed_extensions);
+
+ // Update |changed_extensions_| to be the extensions referred to in
+ // |added_scripts_| and |removed_scripts_|.
+ void ComputeChangedExtensions();
+
+ // 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.
@@ -103,24 +107,28 @@ class UserScriptMaster : public content::NotificationObserver,
// 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_;
+ // Set of scripts from currently-installed extensions we should load.
+ scoped_ptr<std::set<UserScript> > user_scripts_;
// 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_;
+
+ // Boolean that indicates whether the the collection of scripts should be
Devlin 2014/08/04 18:33:25 Since this has type bool, I think we can just say
Mark Dittmer 2014/08/05 20:33:19 Done.
+ // cleared before additions+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.
+ std::set<ExtensionId> 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
@@ -133,15 +141,15 @@ class UserScriptMaster : public content::NotificationObserver,
// The profile for which the scripts managed here are installed.
Profile* profile_;
- // Listen to extension load, unloaded notifications.
- ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
- extension_registry_observer_;
+ // 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<UserScriptMaster> weak_factory_;
+ base::WeakPtrFactory<UserScriptLoader> 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_

Powered by Google App Engine
This is Rietveld 408576698