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

Side by Side Diff: chrome/browser/plugins/plugin_finder.cc

Issue 11348046: Add versioning to PluginFinder metadata. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: chromeos Created 7 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 | Annotate | Revision Log
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 #include "chrome/browser/plugins/plugin_finder.h" 5 #include "chrome/browser/plugins/plugin_finder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 registry->RegisterBooleanPref(prefs::kDisablePluginFinder, false); 141 registry->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
142 } 142 }
143 143
144 // static 144 // static
145 PluginFinder* PluginFinder::GetInstance() { 145 PluginFinder* PluginFinder::GetInstance() {
146 // PluginFinder::GetInstance() is the only method that's allowed to call 146 // PluginFinder::GetInstance() is the only method that's allowed to call
147 // Singleton<PluginFinder>::get(). 147 // Singleton<PluginFinder>::get().
148 return Singleton<PluginFinder>::get(); 148 return Singleton<PluginFinder>::get();
149 } 149 }
150 150
151 PluginFinder::PluginFinder() { 151 PluginFinder::PluginFinder() : version_(-1) {
152 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 152 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
153 } 153 }
154 154
155 void PluginFinder::Init() { 155 void PluginFinder::Init() {
156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
157 plugin_list_.reset(ComputePluginList()); 157 // Load the built-in plug-in list first. If we have a newer version stored
158 DCHECK(plugin_list_.get()); 158 // locally or download one, we will replace this one with it.
159 159 scoped_ptr<DictionaryValue> plugin_list(LoadBuiltInPluginList());
160 InitInternal(); 160 DCHECK(plugin_list);
161 ReinitializePlugins(plugin_list.get());
161 } 162 }
162 163
163 // static 164 // static
164 DictionaryValue* PluginFinder::ComputePluginList() { 165 DictionaryValue* PluginFinder::LoadBuiltInPluginList() {
165 #if defined(ENABLE_PLUGIN_INSTALLATION)
166 const base::DictionaryValue* metadata =
167 g_browser_process->local_state()->GetDictionary(prefs::kPluginsMetadata);
168 if (!metadata->empty())
169 return metadata->DeepCopy();
170 #endif
171 base::DictionaryValue* result = LoadPluginList();
172 if (result)
173 return result;
174 return new base::DictionaryValue();
175 }
176
177 // static
178 DictionaryValue* PluginFinder::LoadPluginList() {
179 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
180 base::StringPiece json_resource( 166 base::StringPiece json_resource(
181 ResourceBundle::GetSharedInstance().GetRawDataResource( 167 ResourceBundle::GetSharedInstance().GetRawDataResource(
182 IDR_PLUGIN_DB_JSON)); 168 IDR_PLUGIN_DB_JSON));
183 std::string error_str; 169 std::string error_str;
184 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( 170 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError(
185 json_resource, 171 json_resource,
186 base::JSON_PARSE_RFC, 172 base::JSON_PARSE_RFC,
187 NULL, 173 NULL,
188 &error_str)); 174 &error_str));
189 if (!value.get()) { 175 if (!value.get()) {
190 DLOG(ERROR) << error_str; 176 DLOG(ERROR) << error_str;
191 return NULL; 177 return NULL;
192 } 178 }
193 if (value->GetType() != base::Value::TYPE_DICTIONARY) 179 if (value->GetType() != base::Value::TYPE_DICTIONARY)
194 return NULL; 180 return NULL;
195 return static_cast<base::DictionaryValue*>(value.release()); 181 return static_cast<base::DictionaryValue*>(value.release());
196 #else
197 return new DictionaryValue();
198 #endif
199 } 182 }
200 183
201 PluginFinder::~PluginFinder() { 184 PluginFinder::~PluginFinder() {
202 #if defined(ENABLE_PLUGIN_INSTALLATION) 185 #if defined(ENABLE_PLUGIN_INSTALLATION)
203 STLDeleteValues(&installers_); 186 STLDeleteValues(&installers_);
204 #endif 187 #endif
205 STLDeleteValues(&identifier_plugin_); 188 STLDeleteValues(&identifier_plugin_);
206 } 189 }
207 190
208 #if defined(ENABLE_PLUGIN_INSTALLATION) 191 #if defined(ENABLE_PLUGIN_INSTALLATION)
209 bool PluginFinder::FindPlugin( 192 bool PluginFinder::FindPlugin(
210 const std::string& mime_type, 193 const std::string& mime_type,
211 const std::string& language, 194 const std::string& language,
212 PluginInstaller** installer, 195 PluginInstaller** installer,
213 scoped_ptr<PluginMetadata>* plugin_metadata) { 196 scoped_ptr<PluginMetadata>* plugin_metadata) {
214 base::AutoLock lock(mutex_);
215 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder)) 197 if (g_browser_process->local_state()->GetBoolean(prefs::kDisablePluginFinder))
216 return false; 198 return false;
217 199
200 base::AutoLock lock(mutex_);
218 PluginMap::const_iterator metadata_it = identifier_plugin_.begin(); 201 PluginMap::const_iterator metadata_it = identifier_plugin_.begin();
219 for (; metadata_it != identifier_plugin_.end(); ++metadata_it) { 202 for (; metadata_it != identifier_plugin_.end(); ++metadata_it) {
220 if (language == metadata_it->second->language() && 203 if (language == metadata_it->second->language() &&
221 metadata_it->second->HasMimeType(mime_type)) { 204 metadata_it->second->HasMimeType(mime_type)) {
222 *plugin_metadata = metadata_it->second->Clone(); 205 *plugin_metadata = metadata_it->second->Clone();
223 206
224 std::map<std::string, PluginInstaller*>::const_iterator installer_it = 207 std::map<std::string, PluginInstaller*>::const_iterator installer_it =
225 installers_.find(metadata_it->second->identifier()); 208 installers_.find(metadata_it->second->identifier());
226 DCHECK(installer_it != installers_.end()); 209 DCHECK(installer_it != installers_.end());
227 *installer = installer_it->second; 210 *installer = installer_it->second;
(...skipping 15 matching lines...) Expand all
243 226
244 if (installer) { 227 if (installer) {
245 std::map<std::string, PluginInstaller*>::const_iterator installer_it = 228 std::map<std::string, PluginInstaller*>::const_iterator installer_it =
246 installers_.find(identifier); 229 installers_.find(identifier);
247 if (installer_it == installers_.end()) 230 if (installer_it == installers_.end())
248 return false; 231 return false;
249 *installer = installer_it->second; 232 *installer = installer_it->second;
250 } 233 }
251 return true; 234 return true;
252 } 235 }
236 #endif
253 237
254 void PluginFinder::ReinitializePlugins( 238 void PluginFinder::ReinitializePlugins(
255 const base::DictionaryValue& json_metadata) { 239 const base::DictionaryValue* plugin_list) {
256 base::AutoLock lock(mutex_); 240 base::AutoLock lock(mutex_);
241 int version = 0; // If no version is defined, we default to 0.
242 const char kVersionKey[] = "x-version";
243 plugin_list->GetInteger(kVersionKey, &version);
244 if (version <= version_)
245 return;
246
247 version_ = version;
248
257 STLDeleteValues(&identifier_plugin_); 249 STLDeleteValues(&identifier_plugin_);
258 identifier_plugin_.clear(); 250 identifier_plugin_.clear();
259 251
260 plugin_list_.reset(json_metadata.DeepCopy()); 252 for (DictionaryValue::Iterator plugin_it(*plugin_list);
261 InitInternal(); 253 plugin_it.HasNext(); plugin_it.Advance()) {
254 const DictionaryValue* plugin = NULL;
255 const std::string& identifier = plugin_it.key();
256 if (plugin_list->GetDictionaryWithoutPathExpansion(identifier, &plugin)) {
257 DCHECK(!identifier_plugin_[identifier]);
258 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin);
259
260 #if defined(ENABLE_PLUGIN_INSTALLATION)
261 if (installers_.find(identifier) == installers_.end())
262 installers_[identifier] = new PluginInstaller();
263 #endif
264 }
265 }
262 } 266 }
263 #endif
264 267
265 string16 PluginFinder::FindPluginNameWithIdentifier( 268 string16 PluginFinder::FindPluginNameWithIdentifier(
266 const std::string& identifier) { 269 const std::string& identifier) {
267 base::AutoLock lock(mutex_); 270 base::AutoLock lock(mutex_);
268 PluginMap::const_iterator it = identifier_plugin_.find(identifier); 271 PluginMap::const_iterator it = identifier_plugin_.find(identifier);
269 string16 name; 272 string16 name;
270 if (it != identifier_plugin_.end()) 273 if (it != identifier_plugin_.end())
271 name = it->second->name(); 274 name = it->second->name();
272 275
273 return name.empty() ? UTF8ToUTF16(identifier) : name; 276 return name.empty() ? UTF8ToUTF16(identifier) : name;
(...skipping 22 matching lines...) Expand all
296 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); 299 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type);
297 300
298 DCHECK(metadata->MatchesPlugin(plugin)); 301 DCHECK(metadata->MatchesPlugin(plugin));
299 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) 302 if (identifier_plugin_.find(identifier) != identifier_plugin_.end())
300 identifier = GetLongIdentifier(plugin); 303 identifier = GetLongIdentifier(plugin);
301 304
302 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); 305 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end());
303 identifier_plugin_[identifier] = metadata; 306 identifier_plugin_[identifier] = metadata;
304 return metadata->Clone(); 307 return metadata->Clone();
305 } 308 }
306
307 void PluginFinder::InitInternal() {
308 for (DictionaryValue::Iterator plugin_it(*plugin_list_);
309 plugin_it.HasNext(); plugin_it.Advance()) {
310 DictionaryValue* plugin = NULL;
311 const std::string& identifier = plugin_it.key();
312 if (plugin_list_->GetDictionaryWithoutPathExpansion(identifier, &plugin)) {
313 DCHECK(!identifier_plugin_[identifier]);
314 identifier_plugin_[identifier] = CreatePluginMetadata(identifier, plugin);
315
316 #if defined(ENABLE_PLUGIN_INSTALLATION)
317 if (installers_.find(identifier) == installers_.end())
318 installers_[identifier] = new PluginInstaller();
319 #endif
320 }
321 }
322 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_finder.h ('k') | chrome/browser/plugins/plugin_finder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698