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

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

Issue 899983002: Revert of 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: rebase Created 5 years, 10 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/declarative_user_script_master.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "extensions/browser/extension_registry.h"
10 8
11 namespace extensions { 9 namespace extensions {
12 10
13 DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile) 11 DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile)
14 : profile_(profile), extension_registry_observer_(this) { 12 : profile_(profile) {
15 extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
16 } 13 }
17 14
18 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() { 15 DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
19 } 16 }
20 17
21 DeclarativeUserScriptMaster* 18 DeclarativeUserScriptMaster*
22 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID( 19 DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
23 const HostID& host_id) { 20 const std::string& id) {
24 UserScriptMasterMap::iterator it = 21 UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id);
25 declarative_user_script_masters_.find(host_id);
26 22
27 if (it != declarative_user_script_masters_.end()) 23 if (it != declarative_user_script_masters_.end())
28 return it->second.get(); 24 return it->second.get();
29 25
30 return CreateDeclarativeUserScriptMaster(host_id);
31 }
32
33 DeclarativeUserScriptMaster*
34 DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster(
35 const HostID& host_id) {
36 linked_ptr<DeclarativeUserScriptMaster> master( 26 linked_ptr<DeclarativeUserScriptMaster> master(
37 new DeclarativeUserScriptMaster(profile_, host_id)); 27 new DeclarativeUserScriptMaster(profile_, id));
38 declarative_user_script_masters_[host_id] = master; 28 declarative_user_script_masters_[id] = master;
39 return master.get(); 29 return master.get();
40 } 30 }
41 31
42 void DeclarativeUserScriptManager::OnExtensionUnloaded( 32 } // extensions
43 content::BrowserContext* browser_context,
44 const Extension* extension,
45 UnloadedExtensionInfo::Reason reason) {
46 for (const auto& val : declarative_user_script_masters_) {
47 DeclarativeUserScriptMaster* master = val.second.get();
48 if (master->host_id().id() == extension->id())
49 master->ClearScripts();
50 }
51 }
52
53 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698