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

Side by Side Diff: chrome/browser/extensions/declarative_user_script_manager.h

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fady's comments. Created 5 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_
6 #define CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/linked_ptr.h" 11 #include "base/memory/linked_ptr.h"
12 #include "extensions/common/consumer.h"
12 13
13 class Profile; 14 class Profile;
14 15
15 namespace extensions { 16 namespace extensions {
16 class DeclarativeUserScriptMaster; 17 class DeclarativeUserScriptMaster;
17 18
18 // Manages a set of DeclarativeUserScriptMaster objects for script injections. 19 // Manages a set of DeclarativeUserScriptMaster objects for script injections.
19 class DeclarativeUserScriptManager { 20 class DeclarativeUserScriptManager {
20 public: 21 public:
21 explicit DeclarativeUserScriptManager(Profile* profile); 22 explicit DeclarativeUserScriptManager(Profile* profile);
22 ~DeclarativeUserScriptManager(); 23 ~DeclarativeUserScriptManager();
23 24
24 // Get the user script master for declarative scripts; if one does not exist, 25 // Get the user script master for declarative scripts by the given id;
25 // a new object will be created. 26 // if one does not exist, a new object will be created.
26 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID( 27 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID(
27 const std::string& id); 28 const std::string& id);
28 29
29 private: 30 private:
31 // TODO(hanxi): add RulesRegistryID to the RulesRegistryKey.
32 struct RulesRegistryKey {
33 explicit RulesRegistryKey(const std::string& host_id) : host_id(host_id) {}
34 bool operator<(const RulesRegistryKey& key) const {
35 return host_id.compare(key.host_id) < 0;
36 }
37
38 std::string host_id;
39 };
40
41 using RulesRegistryKeyToIDMap = std::map<RulesRegistryKey, ConsumerID>;
Fady Samuel 2015/01/08 16:12:59 Make this std::map<RulesRegistry, linked_ptr<Consu
Xi Han 2015/01/08 20:54:11 Done. Also move the keys conversion part to Consum
30 using UserScriptMasterMap = 42 using UserScriptMasterMap =
31 std::map<std::string, linked_ptr<DeclarativeUserScriptMaster>>; 43 std::map<ConsumerID, linked_ptr<DeclarativeUserScriptMaster>>;
32 44
33 // A map of DeclarativeUserScriptMasters for ids; each master is lazily 45 // Get next available instance ID.
34 // initialized. 46 int GetNextID();
47
48 // Get the user script master for declarative scripts by the given ConsumerID.
49 DeclarativeUserScriptMaster* GetDeclarativeUserScriptMasterByID(
50 const ConsumerID& id);
51
52 // Create a DeclarativeUserScriptMaster object.
53 DeclarativeUserScriptMaster* CreateDeclarativeUserScriptMaster(
54 const ConsumerID& consumer_id);
55
56 // A map of ConsumerIDs for the given rules registry ids.
57 // Different types of input ids will define their own maps to store the
58 // mappings from ids to ConsumerIDs.
59 RulesRegistryKeyToIDMap rules_registry_key_to_id_map_;
60
61 // A map of DeclarativeUserScriptMasters for ConsumerIDs;
62 // each master is lazily initialized.
35 UserScriptMasterMap declarative_user_script_masters_; 63 UserScriptMasterMap declarative_user_script_masters_;
36 64
37 Profile* profile_; 65 Profile* profile_;
38 66
67 int current_instance_id_;
68
39 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager); 69 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager);
40 }; 70 };
41 71
42 } // extensions 72 } // namespace extensions
43 73
44 #endif // CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ 74 #endif // CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698