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

Side by Side Diff: chrome/browser/extensions/component_loader.h

Issue 2504333003: Fix DictionaryValue leak in component_loader.cc (Closed)
Patch Set: address comments + rewrite all loops Created 4 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/extensions/component_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const base::FilePath& root_directory); 59 const base::FilePath& root_directory);
60 60
61 // Convenience method for registering a component extension by resource id. 61 // Convenience method for registering a component extension by resource id.
62 std::string Add(int manifest_resource_id, 62 std::string Add(int manifest_resource_id,
63 const base::FilePath& root_directory); 63 const base::FilePath& root_directory);
64 64
65 // Loads a component extension from file system. Replaces previously added 65 // Loads a component extension from file system. Replaces previously added
66 // extension with the same ID. 66 // extension with the same ID.
67 std::string AddOrReplace(const base::FilePath& path); 67 std::string AddOrReplace(const base::FilePath& path);
68 68
69 // Returns the extension ID of a component extension specified by resource
70 // id of its manifest file.
71 std::string GetExtensionID(int manifest_resource_id,
72 const base::FilePath& root_directory);
73
74 // Returns true if an extension with the specified id has been added. 69 // Returns true if an extension with the specified id has been added.
75 bool Exists(const std::string& id) const; 70 bool Exists(const std::string& id) const;
76 71
77 // Unloads a component extension and removes it from the list of component 72 // Unloads a component extension and removes it from the list of component
78 // extensions to be loaded. 73 // extensions to be loaded.
79 void Remove(const base::FilePath& root_directory); 74 void Remove(const base::FilePath& root_directory);
80 void Remove(const std::string& id); 75 void Remove(const std::string& id);
81 76
82 // Call this during test setup to load component extensions that have 77 // Call this during test setup to load component extensions that have
83 // background pages for testing, which could otherwise interfere with tests. 78 // background pages for testing, which could otherwise interfere with tests.
84 static void EnableBackgroundExtensionsForTesting(); 79 static void EnableBackgroundExtensionsForTesting();
85 80
86 // Adds the default component extensions. If |skip_session_components| 81 // Adds the default component extensions. If |skip_session_components|
87 // the loader will skip loading component extensions that weren't supposed to 82 // the loader will skip loading component extensions that weren't supposed to
88 // be loaded unless we are in signed user session (ChromeOS). For all other 83 // be loaded unless we are in signed user session (ChromeOS). For all other
89 // platforms this |skip_session_components| is expected to be unset. 84 // platforms this |skip_session_components| is expected to be unset.
90 void AddDefaultComponentExtensions(bool skip_session_components); 85 void AddDefaultComponentExtensions(bool skip_session_components);
91 86
92 // Similar to above but adds the default component extensions for kiosk mode. 87 // Similar to above but adds the default component extensions for kiosk mode.
93 void AddDefaultComponentExtensionsForKioskMode(bool skip_session_components); 88 void AddDefaultComponentExtensionsForKioskMode(bool skip_session_components);
94 89
95 // Clear the list of registered extensions.
96 void ClearAllRegistered();
97
98 // Reloads a registered component extension. 90 // Reloads a registered component extension.
99 void Reload(const std::string& extension_id); 91 void Reload(const std::string& extension_id);
100 92
101 #if defined(OS_CHROMEOS) 93 #if defined(OS_CHROMEOS)
102 // Add a component extension from a specific directory. Assumes that the 94 // Add a component extension from a specific directory. Assumes that the
103 // extension uses a different manifest file when this is a guest session 95 // extension uses a different manifest file when this is a guest session
104 // and that the manifest file lives in |root_directory|. Calls |done_cb| 96 // and that the manifest file lives in |root_directory|. Calls |done_cb|
105 // on success, unless the component loader is shut down during loading. 97 // on success, unless the component loader is shut down during loading.
106 void AddComponentFromDir( 98 void AddComponentFromDir(
107 const base::FilePath& root_directory, 99 const base::FilePath& root_directory,
108 const char* extension_id, 100 const char* extension_id,
109 const base::Closure& done_cb); 101 const base::Closure& done_cb);
110 102
111 void AddChromeOsSpeechSynthesisExtension(); 103 void AddChromeOsSpeechSynthesisExtension();
112 #endif 104 #endif
113 105
114 void set_ignore_whitelist_for_testing(bool value) { 106 void set_ignore_whitelist_for_testing(bool value) {
115 ignore_whitelist_for_testing_ = value; 107 ignore_whitelist_for_testing_ = value;
116 } 108 }
117 109
118 private: 110 private:
119 FRIEND_TEST_ALL_PREFIXES(ComponentLoaderTest, ParseManifest); 111 FRIEND_TEST_ALL_PREFIXES(ComponentLoaderTest, ParseManifest);
120 112
121 // Information about a registered component extension. 113 // Information about a registered component extension.
122 struct ComponentExtensionInfo { 114 struct ComponentExtensionInfo {
123 ComponentExtensionInfo(const base::DictionaryValue* manifest, 115 ComponentExtensionInfo(
124 const base::FilePath& root_directory); 116 std::unique_ptr<base::DictionaryValue> manifest_param,
117 const base::FilePath& root_directory);
118 ~ComponentExtensionInfo();
119
120 ComponentExtensionInfo(ComponentExtensionInfo&& other);
121 ComponentExtensionInfo& operator=(ComponentExtensionInfo&& other);
125 122
126 // The parsed contents of the extensions's manifest file. 123 // The parsed contents of the extensions's manifest file.
127 const base::DictionaryValue* manifest; 124 std::unique_ptr<base::DictionaryValue> manifest;
128 125
129 // Directory where the extension is stored. 126 // Directory where the extension is stored.
130 base::FilePath root_directory; 127 base::FilePath root_directory;
131 128
132 // The component extension's ID. 129 // The component extension's ID.
133 std::string extension_id; 130 std::string extension_id;
131
132 private:
133 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionInfo);
134 }; 134 };
135 135
136 // Parses the given JSON manifest. Returns nullptr if it cannot be parsed or 136 // Parses the given JSON manifest. Returns nullptr if it cannot be parsed or
137 // if the result is not a DictionaryValue. 137 // if the result is not a DictionaryValue.
138 base::DictionaryValue* ParseManifest( 138 std::unique_ptr<base::DictionaryValue> ParseManifest(
139 base::StringPiece manifest_contents) const; 139 base::StringPiece manifest_contents) const;
140 140
141 std::string Add(const base::StringPiece& manifest_contents, 141 std::string Add(const base::StringPiece& manifest_contents,
142 const base::FilePath& root_directory, 142 const base::FilePath& root_directory,
143 bool skip_whitelist); 143 bool skip_whitelist);
144 std::string Add(const base::DictionaryValue* parsed_manifest, 144 std::string Add(std::unique_ptr<base::DictionaryValue> parsed_manifest,
145 const base::FilePath& root_directory, 145 const base::FilePath& root_directory,
146 bool skip_whitelist); 146 bool skip_whitelist);
147 147
148 // Loads a registered component extension. 148 // Loads a registered component extension.
149 void Load(const ComponentExtensionInfo& info); 149 void Load(const ComponentExtensionInfo& info);
150 150
151 void AddDefaultComponentExtensionsWithBackgroundPages( 151 void AddDefaultComponentExtensionsWithBackgroundPages(
152 bool skip_session_components); 152 bool skip_session_components);
153 void AddDefaultComponentExtensionsWithBackgroundPagesForKioskMode(); 153 void AddDefaultComponentExtensionsWithBackgroundPagesForKioskMode();
154 void AddFileManagerExtension(); 154 void AddFileManagerExtension();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 base::WeakPtrFactory<ComponentLoader> weak_factory_; 205 base::WeakPtrFactory<ComponentLoader> weak_factory_;
206 206
207 friend class TtsApiTest; 207 friend class TtsApiTest;
208 208
209 DISALLOW_COPY_AND_ASSIGN(ComponentLoader); 209 DISALLOW_COPY_AND_ASSIGN(ComponentLoader);
210 }; 210 };
211 211
212 } // namespace extensions 212 } // namespace extensions
213 213
214 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_ 214 #endif // CHROME_BROWSER_EXTENSIONS_COMPONENT_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/component_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698