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

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

Issue 1093153003: Handle malformed built-in PluginFinder data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 5 years, 8 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 (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/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram_macros.h"
10 #include "base/prefs/pref_registry_simple.h" 11 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/plugins/plugin_metadata.h" 18 #include "chrome/browser/plugins/plugin_metadata.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 DCHECK(success); 122 DCHECK(success);
122 plugin->AddVersion(Version(version), status); 123 plugin->AddVersion(Version(version), status);
123 } 124 }
124 } 125 }
125 126
126 LoadMimeTypes(false, plugin_dict, plugin); 127 LoadMimeTypes(false, plugin_dict, plugin);
127 LoadMimeTypes(true, plugin_dict, plugin); 128 LoadMimeTypes(true, plugin_dict, plugin);
128 return plugin; 129 return plugin;
129 } 130 }
130 131
132 void RecordBuiltInPluginListError(int error_code) {
133 // JSONReader::JSON_PARSE_ERROR_COUNT is used for the case where the JSON
134 // value has the wrong type.
135 UMA_HISTOGRAM_ENUMERATION("PluginFinder.BuiltInPluginList.ErrorCode",
136 error_code,
137 base::JSONReader::JSON_PARSE_ERROR_COUNT + 1);
Alexei Svitkine (slow) 2015/04/20 17:15:10 You don't need +1 here. Also, please update that
Bernhard Bauer 2015/04/21 16:34:11 I'm (ab)using JSONReader::JSON_PARSE_ERROR_COUNT a
Alexei Svitkine (slow) 2015/04/21 16:50:36 I see. I don't think we should do this. Otherwise,
138 }
139
131 } // namespace 140 } // namespace
132 141
133 // static 142 // static
134 void PluginFinder::RegisterPrefs(PrefRegistrySimple* registry) { 143 void PluginFinder::RegisterPrefs(PrefRegistrySimple* registry) {
135 registry->RegisterBooleanPref(prefs::kDisablePluginFinder, false); 144 registry->RegisterBooleanPref(prefs::kDisablePluginFinder, false);
136 } 145 }
137 146
138 // static 147 // static
139 PluginFinder* PluginFinder::GetInstance() { 148 PluginFinder* PluginFinder::GetInstance() {
140 // PluginFinder::GetInstance() is the only method that's allowed to call 149 // PluginFinder::GetInstance() is the only method that's allowed to call
141 // Singleton<PluginFinder>::get(). 150 // Singleton<PluginFinder>::get().
142 return Singleton<PluginFinder>::get(); 151 return Singleton<PluginFinder>::get();
143 } 152 }
144 153
145 PluginFinder::PluginFinder() : version_(-1) { 154 PluginFinder::PluginFinder() : version_(-1) {
146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
147 } 156 }
148 157
149 void PluginFinder::Init() { 158 void PluginFinder::Init() {
150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
151 // Load the built-in plugin list first. If we have a newer version stored 160 // Load the built-in plugin list first. If we have a newer version stored
152 // locally or download one, we will replace this one with it. 161 // locally or download one, we will replace this one with it.
153 scoped_ptr<base::DictionaryValue> plugin_list(LoadBuiltInPluginList()); 162 scoped_ptr<base::DictionaryValue> plugin_list(LoadBuiltInPluginList());
154 DCHECK(plugin_list); 163
164 // Gracefully handle the case where we couldn't parse the built-in plugin list
165 // for some reason (https://crbug.com/388560). TODO(bauerb): Change back to a
166 // DCHECK once we have gathered more data about the underlying problem.
167 if (!plugin_list)
168 return;
169
155 ReinitializePlugins(plugin_list.get()); 170 ReinitializePlugins(plugin_list.get());
156 } 171 }
157 172
158 // static 173 // static
159 base::DictionaryValue* PluginFinder::LoadBuiltInPluginList() { 174 base::DictionaryValue* PluginFinder::LoadBuiltInPluginList() {
160 base::StringPiece json_resource( 175 base::StringPiece json_resource(
161 ResourceBundle::GetSharedInstance().GetRawDataResource( 176 ResourceBundle::GetSharedInstance().GetRawDataResource(
162 IDR_PLUGIN_DB_JSON)); 177 IDR_PLUGIN_DB_JSON));
163 std::string error_str; 178 std::string error_str;
179 int error_code = base::JSONReader::JSON_NO_ERROR;
164 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError( 180 scoped_ptr<base::Value> value(base::JSONReader::ReadAndReturnError(
165 json_resource, 181 json_resource, base::JSON_PARSE_RFC, &error_code, &error_str));
166 base::JSON_PARSE_RFC, 182 if (!value) {
167 NULL,
168 &error_str));
169 if (!value.get()) {
170 DLOG(ERROR) << error_str; 183 DLOG(ERROR) << error_str;
171 return NULL; 184 RecordBuiltInPluginListError(error_code);
185 return nullptr;
172 } 186 }
173 if (value->GetType() != base::Value::TYPE_DICTIONARY) 187
174 return NULL; 188 if (value->GetType() != base::Value::TYPE_DICTIONARY) {
189 // JSONReader::JSON_PARSE_ERROR_COUNT is used for the case where the JSON
190 // value has the wrong type.
191 RecordBuiltInPluginListError(base::JSONReader::JSON_PARSE_ERROR_COUNT);
192 return nullptr;
193 }
194
195 DCHECK_EQ(base::JSONReader::JSON_NO_ERROR, error_code);
196 RecordBuiltInPluginListError(error_code);
175 return static_cast<base::DictionaryValue*>(value.release()); 197 return static_cast<base::DictionaryValue*>(value.release());
176 } 198 }
177 199
178 PluginFinder::~PluginFinder() { 200 PluginFinder::~PluginFinder() {
179 #if defined(ENABLE_PLUGIN_INSTALLATION) 201 #if defined(ENABLE_PLUGIN_INSTALLATION)
180 STLDeleteValues(&installers_); 202 STLDeleteValues(&installers_);
181 #endif 203 #endif
182 STLDeleteValues(&identifier_plugin_); 204 STLDeleteValues(&identifier_plugin_);
183 } 205 }
184 206
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type); 316 metadata->AddMatchingMimeType(plugin.mime_types[i].mime_type);
295 317
296 DCHECK(metadata->MatchesPlugin(plugin)); 318 DCHECK(metadata->MatchesPlugin(plugin));
297 if (identifier_plugin_.find(identifier) != identifier_plugin_.end()) 319 if (identifier_plugin_.find(identifier) != identifier_plugin_.end())
298 identifier = GetLongIdentifier(plugin); 320 identifier = GetLongIdentifier(plugin);
299 321
300 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end()); 322 DCHECK(identifier_plugin_.find(identifier) == identifier_plugin_.end());
301 identifier_plugin_[identifier] = metadata; 323 identifier_plugin_[identifier] = metadata;
302 return metadata->Clone(); 324 return metadata->Clone();
303 } 325 }
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698