| 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 } | 13 } |
| 14 | 14 |
| 15 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() { | 15 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() { |
| 16 } | 16 } |
| 17 | 17 |
| 18 DeclarativeUserScriptMaster* | 18 linked_ptr<DeclarativeUserScriptMaster> |
| 19 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( | 19 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( |
| 20 const std::string& id) { | 20 const ConsumerID& consumer_id) { |
| 21 UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id); | 21 UserScriptMasterMap::iterator it = |
| 22 declarative_user_script_masters_.find(consumer_id); |
| 22 | 23 |
| 23 if (it != declarative_user_script_masters_.end()) | 24 if (it != declarative_user_script_masters_.end()) |
| 24 return it->second.get(); | 25 return it->second; |
| 25 | 26 |
| 26 linked_ptr<DeclarativeUserScriptMaster> master( | 27 return CreateDeclarativeUserScriptMaster(consumer_id); |
| 27 new DeclarativeUserScriptMaster(profile_, id)); | |
| 28 declarative_user_script_masters_[id] = master; | |
| 29 return master.get(); | |
| 30 } | 28 } |
| 31 | 29 |
| 32 } // extensions | 30 linked_ptr<DeclarativeUserScriptMaster> |
| 31 DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster( |
| 32 const ConsumerID& consumer_id) { |
| 33 linked_ptr<DeclarativeUserScriptMaster> master; |
| 34 switch (consumer_id.host_type()) { |
| 35 case ConsumerID::EXTENSIONS: |
| 36 master.reset( |
| 37 new ExtensionDeclarativeUserScriptMaster(profile_, consumer_id)); |
| 38 break; |
| 39 default: |
| 40 master.reset(new DeclarativeUserScriptMaster(profile_, consumer_id)); |
| 41 } |
| 42 declarative_user_script_masters_[consumer_id] = master; |
| 43 return master; |
| 44 } |
| 45 |
| 46 } // namespace extensions |
| OLD | NEW |