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

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: format 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>;
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 // Given an input id, generate and return a ConsumerID.
53 ConsumerID* GenerateConsumerID(const std::string& id);
Fady Samuel 2015/01/07 19:19:40 Return scoped_ptr<ConsumerID> to avoid accidentall
Xi Han 2015/01/07 20:28:42 Good point, but I realize this function hasn't bee
54
55 // Create a DeclarativeUserScriptMaster object.
56 DeclarativeUserScriptMaster* CreateDeclarativeUserScriptMaster(
57 const ConsumerID& consumer_id);
58
59 // A map of ConsumerIDs for the given rules registry ids.
60 // Different types of input ids will define their own maps to store the
61 // mappings from ids to ConsumerIDs.
62 RulesRegistryKeyToIDMap rules_registry_key_to_id_map_;
63
64 // A map of DeclarativeUserScriptMasters for ConsumerIDs;
65 // each master is lazily initialized.
35 UserScriptMasterMap declarative_user_script_masters_; 66 UserScriptMasterMap declarative_user_script_masters_;
36 67
37 Profile* profile_; 68 Profile* profile_;
38 69
70 int current_instance_id_;
71
39 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager); 72 DISALLOW_COPY_AND_ASSIGN(DeclarativeUserScriptManager);
40 }; 73 };
41 74
42 } // extensions 75 } // namespace extensions
43 76
44 #endif // CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_ 77 #endif // CHROME_BROWSER_EXTENSIONS_DECLARATIVE_USER_SCRIPT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698