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

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

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 #include "chrome/browser/extensions/declarative_user_script_manager.h" 5 #include "chrome/browser/extensions/declarative_user_script_manager.h"
6 6
7 #include "chrome/browser/extensions/declarative_user_script_master.h" 7 #include "chrome/browser/extensions/extension_declarative_user_script_master.h"
8 8
9 namespace extensions { 9 namespace extensions {
10 10
11 DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile) 11 DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile)
12 : profile_(profile) { 12 : profile_(profile), current_instance_id_(ConsumerID::kDefaultInstanceID) {
13 } 13 }
14 14
15 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() { 15 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
16 } 16 }
17 17
18 DeclarativeUserScriptMaster* 18 DeclarativeUserScriptMaster*
19 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( 19 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
Fady Samuel 2015/01/08 16:12:59 You shouldn't need this.
Xi Han 2015/01/08 20:54:11 Removed.
20 const std::string& id) { 20 const std::string& id) {
21 UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id); 21 RulesRegistryKey key(id);
22 RulesRegistryKeyToIDMap::iterator it =
23 rules_registry_key_to_id_map_.find(key);
24 if (it != rules_registry_key_to_id_map_.end())
25 return GetDeclarativeUserScriptMasterByID(it->second);
26
27 ConsumerID consumer_id(ConsumerID::EXTENSIONS, id, ConsumerID::TAB,
28 GetNextID());
29 rules_registry_key_to_id_map_[key] = consumer_id;
30 return CreateDeclarativeUserScriptMaster(consumer_id);
31 }
32
33 DeclarativeUserScriptMaster*
34 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
35 const ConsumerID& consumer_id) {
36 UserScriptMasterMap::iterator it =
37 declarative_user_script_masters_.find(consumer_id);
22 38
23 if (it != declarative_user_script_masters_.end()) 39 if (it != declarative_user_script_masters_.end())
24 return it->second.get(); 40 return it->second.get();
25 41
26 linked_ptr<DeclarativeUserScriptMaster> master( 42 return CreateDeclarativeUserScriptMaster(consumer_id);
27 new DeclarativeUserScriptMaster(profile_, id)); 43 }
28 declarative_user_script_masters_[id] = master; 44
45 DeclarativeUserScriptMaster*
46 DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster(
47 const ConsumerID& consumer_id) {
48 linked_ptr<DeclarativeUserScriptMaster> master;
49 switch (consumer_id.host_type()) {
50 case ConsumerID::EXTENSIONS:
51 master.reset(
52 new ExtensionDeclarativeUserScriptMaster(profile_, consumer_id));
53 break;
54 default:
55 master.reset(new DeclarativeUserScriptMaster(profile_, consumer_id));
56 }
57 declarative_user_script_masters_[consumer_id] = master;
29 return master.get(); 58 return master.get();
30 } 59 }
31 60
32 } // extensions 61 int DeclarativeUserScriptManager::GetNextID() {
62 return ++current_instance_id_;
63 }
64
65 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698