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

Side by Side Diff: extensions/browser/extension_registry.cc

Issue 131743021: app_shell: Extract extension runtime data from ExtensionService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add ExtensionRegistry observer (runtime_data) Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/browser/extension_registry.h" 5 #include "extensions/browser/extension_registry.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "extensions/browser/extension_registry_factory.h" 8 #include "extensions/browser/extension_registry_factory.h"
9 #include "extensions/browser/extension_registry_observer.h"
9 10
10 namespace extensions { 11 namespace extensions {
11 12
12 ExtensionRegistry::ExtensionRegistry() {} 13 ExtensionRegistry::ExtensionRegistry() {}
13 ExtensionRegistry::~ExtensionRegistry() {} 14 ExtensionRegistry::~ExtensionRegistry() {}
14 15
15 // static 16 // static
16 ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) { 17 ExtensionRegistry* ExtensionRegistry::Get(content::BrowserContext* context) {
17 return ExtensionRegistryFactory::GetForBrowserContext(context); 18 return ExtensionRegistryFactory::GetForBrowserContext(context);
18 } 19 }
19 20
21 void ExtensionRegistry::AddObserver(ExtensionRegistryObserver* observer) {
22 observers_.AddObserver(observer);
23 }
24
25 void ExtensionRegistry::RemoveObserver(ExtensionRegistryObserver* observer) {
26 observers_.RemoveObserver(observer);
27 }
28
20 const Extension* ExtensionRegistry::GetExtensionById(const std::string& id, 29 const Extension* ExtensionRegistry::GetExtensionById(const std::string& id,
21 int include_mask) const { 30 int include_mask) const {
22 std::string lowercase_id = StringToLowerASCII(id); 31 std::string lowercase_id = StringToLowerASCII(id);
23 if (include_mask & ENABLED) { 32 if (include_mask & ENABLED) {
24 const Extension* extension = enabled_extensions_.GetByID(lowercase_id); 33 const Extension* extension = enabled_extensions_.GetByID(lowercase_id);
25 if (extension) 34 if (extension)
26 return extension; 35 return extension;
27 } 36 }
28 if (include_mask & DISABLED) { 37 if (include_mask & DISABLED) {
29 const Extension* extension = disabled_extensions_.GetByID(lowercase_id); 38 const Extension* extension = disabled_extensions_.GetByID(lowercase_id);
30 if (extension) 39 if (extension)
31 return extension; 40 return extension;
32 } 41 }
33 if (include_mask & TERMINATED) { 42 if (include_mask & TERMINATED) {
34 const Extension* extension = terminated_extensions_.GetByID(lowercase_id); 43 const Extension* extension = terminated_extensions_.GetByID(lowercase_id);
35 if (extension) 44 if (extension)
36 return extension; 45 return extension;
37 } 46 }
38 if (include_mask & BLACKLISTED) { 47 if (include_mask & BLACKLISTED) {
39 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id); 48 const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id);
40 if (extension) 49 if (extension)
41 return extension; 50 return extension;
42 } 51 }
43 return NULL; 52 return NULL;
44 } 53 }
45 54
55 void ExtensionRegistry::UnloadExtension(
56 const scoped_refptr<const Extension>& extension) {
57 enabled_extensions_.Remove(extension->id());
58 disabled_extensions_.Remove(extension->id());
59 FOR_EACH_OBSERVER(ExtensionRegistryObserver,
60 observers_,
61 OnExtensionUnloaded(extension.get()));
62 }
63
64 void ExtensionRegistry::EnableExtension(
65 const scoped_refptr<const Extension>& extension) {
66 DCHECK(disabled_extensions_.Contains(extension->id()));
67 enabled_extensions_.Insert(extension);
68 disabled_extensions_.Remove(extension->id());
69 }
70
71 void ExtensionRegistry::DisableExtension(
72 const scoped_refptr<const Extension>& extension) {
73 DCHECK(enabled_extensions_.Contains(extension->id()) ||
74 terminated_extensions_.Contains(extension->id()));
75 disabled_extensions_.Insert(extension);
76 enabled_extensions_.Remove(extension->id());
77 terminated_extensions_.Remove(extension->id());
78 FOR_EACH_OBSERVER(ExtensionRegistryObserver,
79 observers_,
80 OnExtensionDisabled(extension.get()));
81 }
82
46 bool ExtensionRegistry::AddEnabled( 83 bool ExtensionRegistry::AddEnabled(
47 const scoped_refptr<const Extension>& extension) { 84 const scoped_refptr<const Extension>& extension) {
48 return enabled_extensions_.Insert(extension); 85 return enabled_extensions_.Insert(extension);
49 } 86 }
50 87
51 bool ExtensionRegistry::RemoveEnabled(const std::string& id) {
52 return enabled_extensions_.Remove(id);
53 }
54
55 bool ExtensionRegistry::AddDisabled( 88 bool ExtensionRegistry::AddDisabled(
56 const scoped_refptr<const Extension>& extension) { 89 const scoped_refptr<const Extension>& extension) {
57 return disabled_extensions_.Insert(extension); 90 return disabled_extensions_.Insert(extension);
58 } 91 }
59 92
60 bool ExtensionRegistry::RemoveDisabled(const std::string& id) {
61 return disabled_extensions_.Remove(id);
62 }
63
64 bool ExtensionRegistry::AddTerminated( 93 bool ExtensionRegistry::AddTerminated(
65 const scoped_refptr<const Extension>& extension) { 94 const scoped_refptr<const Extension>& extension) {
66 return terminated_extensions_.Insert(extension); 95 return terminated_extensions_.Insert(extension);
67 } 96 }
68 97
69 bool ExtensionRegistry::RemoveTerminated(const std::string& id) { 98 bool ExtensionRegistry::RemoveTerminated(const std::string& id) {
70 return terminated_extensions_.Remove(id); 99 return terminated_extensions_.Remove(id);
71 } 100 }
72 101
73 bool ExtensionRegistry::AddBlacklisted( 102 bool ExtensionRegistry::AddBlacklisted(
(...skipping 16 matching lines...) Expand all
90 const ExtensionSet::ModificationCallback& callback) { 119 const ExtensionSet::ModificationCallback& callback) {
91 disabled_extensions_.set_modification_callback(callback); 120 disabled_extensions_.set_modification_callback(callback);
92 } 121 }
93 122
94 void ExtensionRegistry::Shutdown() { 123 void ExtensionRegistry::Shutdown() {
95 // Release references to all Extension objects in the sets. 124 // Release references to all Extension objects in the sets.
96 ClearAll(); 125 ClearAll();
97 } 126 }
98 127
99 } // namespace extensions 128 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698