Chromium Code Reviews| Index: chrome/browser/extensions/user_script_master_manager.h |
| diff --git a/chrome/browser/extensions/user_script_master_manager.h b/chrome/browser/extensions/user_script_master_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..343ccfb53f172073f1272dae107b07b6b1d2be7f |
| --- /dev/null |
| +++ b/chrome/browser/extensions/user_script_master_manager.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
|
Devlin
2014/08/04 18:33:26
no (c)
Mark Dittmer
2014/08/05 20:33:20
Done.
|
| +// 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_MANAGER_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_MANAGER_H_ |
| + |
| +#include "base/containers/scoped_ptr_hash_map.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/scoped_observer.h" |
| +#include "chrome/browser/extensions/declarative_user_script_master.h" |
| +#include "chrome/browser/extensions/shared_user_script_master.h" |
| +#include "extensions/browser/extension_registry.h" |
| +#include "extensions/browser/extension_registry_observer.h" |
| +#include "extensions/common/extension.h" |
| +#include "extensions/common/user_script.h" |
| + |
| +namespace content { |
| + |
| +class BrowserContext; |
|
Devlin
2014/08/04 18:33:26
condense
Mark Dittmer
2014/08/05 20:33:20
Done.
|
| + |
| +} // namespace content |
| + |
| +class Profile; |
| + |
| +namespace extensions { |
| + |
| +class UserScriptMasterManager : public ExtensionRegistryObserver { |
|
Devlin
2014/08/04 18:33:26
So...Do we need this class? Or could we just have
Mark Dittmer
2014/08/05 20:33:20
You're right. We can get rid of this class. Done.
|
| + public: |
| + explicit UserScriptMasterManager(Profile* profile); |
| + virtual ~UserScriptMasterManager(); |
| + |
| + SharedUserScriptMaster* shared_master() { return shared_master_.get(); } |
| + |
| + DeclarativeUserScriptMaster* GetDeclarativeMasterByExtension( |
| + const ExtensionId& extension_id) { |
| + if (!declarative_masters_.get(extension_id)) { |
| + declarative_masters_.set(extension_id, |
| + make_scoped_ptr(new DeclarativeUserScriptMaster( |
| + profile_, extension_id))); |
| + } |
| + return declarative_masters_.get(extension_id); |
| + } |
| + |
| + // 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; |
| + |
| + private: |
| + Profile* profile_; |
| + |
| + // Shared memory region manager for scripts statically declared in extension |
| + // manifests. This region is shared between all extensions. |
| + scoped_ptr<SharedUserScriptMaster> shared_master_; |
| + |
| + // Shared memory region manager for programmatically declared scripts, one per |
| + // extension. Managers are instantiated the first time the declarative API is |
| + // used by an extension to request content scripts. |
| + base::ScopedPtrHashMap<ExtensionId, DeclarativeUserScriptMaster> |
| + declarative_masters_; |
| + |
| + // Listen to extension load, unloaded notifications. |
| + ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| + extension_registry_observer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UserScriptMasterManager); |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_USER_SCRIPT_MASTER_MANAGER_H_ |