Chromium Code Reviews| OLD | NEW |
|---|---|
| 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), |
| 13 current_instance_id_(ConsumerID::kDefaultInstanceID + 1) { | |
|
Fady Samuel
2015/01/06 13:55:11
Why?
Xi Han
2015/01/07 18:57:03
Updated.
| |
| 13 } | 14 } |
| 14 | 15 |
| 15 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() { | 16 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() { |
| 16 } | 17 } |
| 17 | 18 |
| 18 DeclarativeUserScriptMaster* | 19 DeclarativeUserScriptMaster* |
| 19 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( | 20 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( |
| 20 const std::string& id) { | 21 const std::string& id) { |
| 21 UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id); | 22 RulesRegistryKey key(id); |
| 23 RulesRegistryKeyToIDMap::iterator it = | |
| 24 rules_registry_key_to_id_map_.find(key); | |
| 25 if (it != rules_registry_key_to_id_map_.end()) | |
| 26 return GetDeclarativeUserScriptMasterByID(it->second); | |
| 27 | |
| 28 ConsumerID consumer_id(EXTENSIONS, id, TAB, 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 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 |
| 61 int DeclarativeUserScriptManager::GetNextID() { | |
| 62 return ++current_instance_id_; | |
| 63 } | |
| 64 | |
| 32 } // extensions | 65 } // extensions |
| OLD | NEW |