Add ICU message format support
[chromium-blink-merge.git] / extensions / browser / declarative_user_script_manager.cc
blob9c10ab3f2f220ac99806608383a43d3e47ddf11a
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
3 // found in the LICENSE file.
5 #include "extensions/browser/declarative_user_script_manager.h"
7 #include "content/public/browser/browser_context.h"
8 #include "extensions/browser/declarative_user_script_manager_factory.h"
9 #include "extensions/browser/declarative_user_script_master.h"
10 #include "extensions/browser/extension_registry.h"
12 namespace extensions {
14 DeclarativeUserScriptManager::DeclarativeUserScriptManager(
15 content::BrowserContext* browser_context)
16 : browser_context_(browser_context), extension_registry_observer_(this) {
17 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context));
20 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
23 // static
24 DeclarativeUserScriptManager* DeclarativeUserScriptManager::Get(
25 content::BrowserContext* browser_context) {
26 return DeclarativeUserScriptManagerFactory::GetForBrowserContext(
27 browser_context);
30 DeclarativeUserScriptMaster*
31 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
32 const HostID& host_id) {
33 UserScriptMasterMap::iterator it =
34 declarative_user_script_masters_.find(host_id);
36 if (it != declarative_user_script_masters_.end())
37 return it->second.get();
39 return CreateDeclarativeUserScriptMaster(host_id);
42 DeclarativeUserScriptMaster*
43 DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster(
44 const HostID& host_id) {
45 linked_ptr<DeclarativeUserScriptMaster> master(
46 new DeclarativeUserScriptMaster(browser_context_, host_id));
47 declarative_user_script_masters_[host_id] = master;
48 return master.get();
51 void DeclarativeUserScriptManager::OnExtensionUnloaded(
52 content::BrowserContext* browser_context,
53 const Extension* extension,
54 UnloadedExtensionInfo::Reason reason) {
55 for (const auto& val : declarative_user_script_masters_) {
56 DeclarativeUserScriptMaster* master = val.second.get();
57 if (master->host_id().id() == extension->id())
58 master->ClearScripts();
62 } // namespace extensions