summaryrefslogtreecommitdiffstats
path: root/extensions/browser/declarative_user_script_master.h
blob: c7a23c3f6b2ec692759d8753064f80b6df65e257 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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 EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_
#define EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_

#include "base/scoped_observer.h"
#include "extensions/browser/extension_user_script_loader.h"

namespace content {
class BrowserContext;
}

namespace extensions {

class UserScript;

// Manages declarative user scripts for a single extension. Owns a
// UserScriptLoader to which file loading and shared memory management
// operations are delegated, and provides an interface for adding, removing,
// and clearing scripts.
class DeclarativeUserScriptMaster {
 public:
  DeclarativeUserScriptMaster(content::BrowserContext* browser_context,
                              const HostID& host_id);
  ~DeclarativeUserScriptMaster();

  // Adds script to shared memory region. This may not happen right away if a
  // script load is in progress.
  void AddScript(const UserScript& script);

  // Removes script from shared memory region. This may not happen right away if
  // a script load is in progress.
  void RemoveScript(const UserScript& script);

  // Removes all scripts from shared memory region. This may not happen right
  // away if a script load is in progress.
  void ClearScripts();

  const HostID& host_id() const { return host_id_; }

 private:
  // ID of host that owns scripts that this component manages.
  HostID host_id_;

  // Script loader that handles loading contents of scripts into shared memory
  // and notifying renderers of script updates.
  ExtensionUserScriptLoader loader_;

  DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptMaster);
};

}  // namespace extensions

#endif  // EXTENSIONS_BROWSER_DECLARATIVE_USER_SCRIPT_MASTER_H_